All Projects → syntax-tree → hast-util-to-html

syntax-tree / hast-util-to-html

Licence: MIT License
utility to serialize hast to HTML

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hast-util-to-html

hast-util-from-dom
utility to transform a DOM tree to hast
Stars: ✭ 20 (-57.45%)
Mutual labels:  syntax-tree, util, unist, hast, hast-util
hast-util-sanitize
utility to sanitize hast nodes
Stars: ✭ 34 (-27.66%)
Mutual labels:  syntax-tree, util, unist, hast, hast-util
mdast-util-to-hast
utility to transform mdast to hast
Stars: ✭ 53 (+12.77%)
Mutual labels:  syntax-tree, unist, hast, hast-util
nlcst-to-string
utility to transform an nlcst tree to a string
Stars: ✭ 16 (-65.96%)
Mutual labels:  syntax-tree, util, stringify, unist
unist-util-visit-parents
utility to recursively walk over unist nodes, with ancestral information
Stars: ✭ 25 (-46.81%)
Mutual labels:  syntax-tree, util, unist
hast-util-reading-time
utility to estimate the reading time
Stars: ✭ 55 (+17.02%)
Mutual labels:  unist, hast, hast-util
hast-util-select
utility to add `querySelector`, `querySelectorAll`, and `matches` support for hast
Stars: ✭ 20 (-57.45%)
Mutual labels:  util, hast, hast-util
unist-util-map
utility to create a new tree by mapping all nodes
Stars: ✭ 30 (-36.17%)
Mutual labels:  syntax-tree, util, unist
mdast-util-to-string
utility to get the plain text content of an mdast node
Stars: ✭ 27 (-42.55%)
Mutual labels:  syntax-tree, util, unist
hast-util-to-mdast
utility to transform hast (HTML) to mdast (markdown)
Stars: ✭ 26 (-44.68%)
Mutual labels:  unist, hast, hast-util
unist-builder
utility to create a new trees with a nice syntax
Stars: ✭ 52 (+10.64%)
Mutual labels:  syntax-tree, util, unist
unist-util-inspect
utility to inspect nodes
Stars: ✭ 16 (-65.96%)
Mutual labels:  syntax-tree, util, unist
xast
Extensible Abstract Syntax Tree
Stars: ✭ 32 (-31.91%)
Mutual labels:  syntax-tree, unist
ntast
Notion Abstract Syntax Tree specification.
Stars: ✭ 101 (+114.89%)
Mutual labels:  syntax-tree, unist
unist-util-select
utility to select unist nodes with CSS-like selectors
Stars: ✭ 41 (-12.77%)
Mutual labels:  util, unist
Unist Util Visit
utility to visit nodes
Stars: ✭ 101 (+114.89%)
Mutual labels:  syntax-tree, util
Unified
☔️ interface for parsing, inspecting, transforming, and serializing content through syntax trees
Stars: ✭ 3,036 (+6359.57%)
Mutual labels:  syntax-tree, unist
sast
Parse CSS, Sass, SCSS, and Less into a unist syntax tree
Stars: ✭ 51 (+8.51%)
Mutual labels:  syntax-tree, unist
MarkdownSyntax
☄️ A Type-safe Markdown parser in Swift.
Stars: ✭ 65 (+38.3%)
Mutual labels:  syntax-tree, unist
MyUtil
早期入门学习中记录和整理一些实用的笔记🎯
Stars: ✭ 27 (-42.55%)
Mutual labels:  util

hast-util-to-html

Build Coverage Downloads Size Sponsors Backers Chat

hast utility to serialize to HTML.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install hast-util-to-html

Use

import {h} from 'hastscript'
import {toHtml} from 'hast-util-to-html'

var tree = h('.alpha', [
  'bravo ',
  h('b', 'charlie'),
  ' delta ',
  h('a.echo', {download: true}, 'foxtrot')
])

console.log(toHtml(tree))

Yields:

<div class="alpha">bravo <b>charlie</b> delta <a class="echo" download>foxtrot</a></div>

API

This package exports the following identifiers: toHtml. There is no default export.

toHtml(tree[, options])

Serialize the given hast tree (or list of nodes).

options.space

Whether the root of the tree is in the 'html' or 'svg' space (enum, 'svg' or 'html', default: 'html').

If an svg element is found in the HTML space, toHtml automatically switches to the SVG space when entering the element, and switches back when exiting.

options.entities

Configuration for stringify-entities (Object, default: {}). Do not use escapeOnly, attribute, or subset (toHtml already passes those, so they won’t work). However, useNamedReferences, useShortestReferences, and omitOptionalSemicolons are all fine.

options.voids

Tag names of elements to serialize without closing tag (Array.<string>, default: html-void-elements).

Not used in the SVG space.

options.upperDoctype

Use a <!DOCTYPE… instead of <!doctype…. Useless except for XHTML (boolean, default: false).

options.quote

Preferred quote to use ('"' or '\'', default: '"').

options.quoteSmart

Use the other quote if that results in less bytes (boolean, default: false).

options.preferUnquoted

Leave attributes unquoted if that results in less bytes (boolean, default: false).

Not used in the SVG space.

options.omitOptionalTags

Omit optional opening and closing tags (boolean, default: false). For example, in <ol><li>one</li><li>two</li></ol>, both </li> closing tags can be omitted. The first because it’s followed by another li, the last because it’s followed by nothing.

Not used in the SVG space.

options.collapseEmptyAttributes

Collapse empty attributes: get class instead of class="" (boolean, default: false). Note: boolean attributes, such as hidden, are always collapsed.

Not used in the SVG space.

options.closeSelfClosing

Close self-closing nodes with an extra slash (/): <img /> instead of <img> (boolean, default: false). See tightSelfClosing to control whether a space is used before the slash.

Not used in the SVG space.

options.closeEmptyElements

Close SVG elements without any content with slash (/) on the opening tag instead of an end tag: <circle /> instead of <circle></circle> (boolean, default: false). See tightSelfClosing to control whether a space is used before the slash.

Not used in the HTML space.

options.tightSelfClosing

Do not use an extra space when closing self-closing elements: <img/> instead of <img /> (boolean, default: false). Note: Only used if closeSelfClosing: true or closeEmptyElements: true.

options.tightCommaSeparatedLists

Join known comma-separated attribute values with just a comma (,), instead of padding them on the right as well (, where · represents a space) (boolean, default: false).

options.tightAttributes

Join attributes together, without whitespace, if possible: get class="a b"title="c d" instead of class="a b" title="c d" to save bytes (boolean, default: false). Note: creates invalid (but working) markup.

Not used in the SVG space.

options.tightDoctype

Drop unneeded spaces in doctypes: <!doctypehtml> instead of <!doctype html> to save bytes (boolean, default: false). Note: creates invalid (but working) markup.

options.bogusComments

Use “bogus comments” instead of comments to save byes: <?charlie> instead of <!--charlie--> (boolean, default: false). Note: creates invalid (but working) markup.

options.allowParseErrors

Do not encode characters which cause parse errors (even though they work), to save bytes (boolean, default: false). Note: creates invalid (but working) markup.

Not used in the SVG space.

options.allowDangerousCharacters

Do not encode some characters which cause XSS vulnerabilities in older browsers (boolean, default: false). Note: Only set this if you completely trust the content.

options.allowDangerousHtml

Allow raw nodes and insert them as raw HTML. When falsey, encodes raw nodes (boolean, default: false). Note: Only set this if you completely trust the content.

Security

Use of hast-util-to-html can open you up to a cross-site scripting (XSS) attack if the hast tree is unsafe. Use hast-util-santize to make the hast tree safe.

Related

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

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].