All Projects → huozhi → html2any

huozhi / html2any

Licence: other
🌀 parse and convert html string to anything

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to html2any

Posthtml
PostHTML is a tool to transform HTML/XML with JS plugins
Stars: ✭ 2,737 (+6265.12%)
Mutual labels:  html-parser, xml-parser
Fuzi
A fast & lightweight XML & HTML parser in Swift with XPath & CSS support
Stars: ✭ 894 (+1979.07%)
Mutual labels:  html-parser, xml-parser
Hquery.php
An extremely fast web scraper that parses megabytes of invalid HTML in a blink of an eye. PHP5.3+, no dependencies.
Stars: ✭ 295 (+586.05%)
Mutual labels:  html-parser, xml-parser
Sax Wasm
The first streamable, fixed memory XML, HTML, and JSX parser for WebAssembly.
Stars: ✭ 89 (+106.98%)
Mutual labels:  html-parser, xml-parser
Didom
Simple and fast HTML and XML parser
Stars: ✭ 1,939 (+4409.3%)
Mutual labels:  html-parser, xml-parser
Wxparse
微信小程序富文本解析
Stars: ✭ 135 (+213.95%)
Mutual labels:  html-parser, rich-text
Oga
Read-only mirror of https://gitlab.com/yorickpeterse/oga
Stars: ✭ 1,147 (+2567.44%)
Mutual labels:  html-parser, xml-parser
Kanna
Kanna(鉋) is an XML/HTML parser for Swift.
Stars: ✭ 2,227 (+5079.07%)
Mutual labels:  html-parser, xml-parser
Webpageparser
A delightful xml and html parsing relish for iOS
Stars: ✭ 236 (+448.84%)
Mutual labels:  html-parser, xml-parser
dsm
Declarative Stream Mapping (DSM) is a stream de/serializer library for XML and JSON. DSM allows you to make custom parsing, filtering, transforming, aggregating, grouping on any JSON or XML document at stream time(read only once).
Stars: ✭ 23 (-46.51%)
Mutual labels:  xml-parser
rich-text
A set of companion packages for GraphCMS's Rich Text Field
Stars: ✭ 62 (+44.19%)
Mutual labels:  rich-text
unicode-formatter
Convert portions of text to fancy text using unicode fonts for use on Twitter and other sites that don't support rich text
Stars: ✭ 31 (-27.91%)
Mutual labels:  rich-text
mobility-actiontext
Translate Rails Action Text rich text with Mobility.
Stars: ✭ 27 (-37.21%)
Mutual labels:  rich-text
Taro-ParserRichText
适用于 Taro 的小程序富文本组件
Stars: ✭ 32 (-25.58%)
Mutual labels:  rich-text
Aris
Aris - A fast and powerful tool to write HTML in JS easily. Includes syntax highlighting, templates, SVG, CSS autofixing, debugger support and more...
Stars: ✭ 61 (+41.86%)
Mutual labels:  html-parser
richvariables
DEPRECATED Allows you to easily use Craft Globals as variables in Rich Text fields
Stars: ✭ 44 (+2.33%)
Mutual labels:  rich-text
eaxy
Eaxy - Enjoy XML. Java library for parsing, building and iterating both simple and huge + complex XML
Stars: ✭ 52 (+20.93%)
Mutual labels:  xml-parser
DocSum
A tool to automatically summarize documents abstractively using the BART or PreSumm Machine Learning Model.
Stars: ✭ 58 (+34.88%)
Mutual labels:  xml-parser
fox
A Fortran XML library
Stars: ✭ 51 (+18.6%)
Mutual labels:  xml-parser
sherpa 41
Simple browser engine.
Stars: ✭ 31 (-27.91%)
Mutual labels:  html-parser

html2any

npm version

A non-dependecy package for coverting html/xml string to your customized format/structures.

While building websites, people may met issues for rendering rich text into different formats. For example, I've got an <video> tag, but I wanna render it with my own React video component. But I also want to render the whole html easily rather than parse it manually.

Now html2any help you to render html string. It not only parses your html but also gives you ability to transform it from origin to the dest.

API

html2any provide following APIs

  • AST(Object) parse(String source)

  • void transform(AST ast, function rule)

  • void html2any(html, function rule)

  • parse

Build the AST from source to AST from source html/xml code

  • transform

Convert the AST to the final form with the specific rule.

  • html2any

Convert the html/xml to the final form directly.

Usage

npm i -S html2any
import html2any, { parse, transform } from 'html2any'

const html = escapeHTMLEntity(`<div>123</div>`)

const ast = parse(html)[0]

function rule(node, children) {
  if (typeof node === 'string') {
    return node
  } else {
    return <div>{node}</div>
  }
}

const vdom = transform(ast, rule)
// JSX vdom form of html
// { type: 'div', props: {...}, children: '...' }

Or you can just call html2any directly

const vdom = html2any(html, rule)

How It Works

Use html2any to construct an AST of html string, then convert each node recursively with rule passed to transform function.

For example, we translate <p> tag into React Native component <Text style={styles.paragraph}> with the prepared styles. Then decode the p tag' s content to avoid html entities mess up.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].