3.0.0 • Published 3 years ago

posthtml-render v3.0.0

Weekly downloads
522,459
License
MIT
Repository
github
Last release
3 years ago

npm node tests coverage

npm i -D posthtml-render

NodeJS

import { render } from ''posthtml-render;

const tree = [];

const node = {};

node.tag = 'ul';
node.attrs = { class: 'list' };
node.content = [
 'one',
 'two',
 'three'
].map((content) => ({ tag: 'li', content }));

tree.push(node);

const html = render(tree, options);
<ul class="list">
  <li>one</li>
  <li>two</li>
  <li>three</li>
</ul>
NameTypeDefaultDescription
singleTags{Array<String\|RegExp>}[]Specify custom single tags (self closing)
closingSingleTag{String}>Specify the single tag closing format
quoteAllAttributes{Boolean}truePut double quotes around all tags, even when not necessary.
replaceQuote{Boolean}trueReplaces quotes in attribute values with &quote;.
quoteStyle{0 or 1 or 2}2Specify the style of quote arround the attribute values

singleTags

Specify custom single tags (self closing)

{String}

const render = require('posthtml-render')

const tree = [ { tag: 'name' } ]
const options = { singleTags: [ 'name' ] }

const html = render(tree, options)

result.html

<name>

{RegExp}

const render = require('posthtml-render')

const tree = [ { tag: '%=title%' } ]
const options = { singleTags: [ /^%.*%$/ ] }

const html = render(tree, options)

result.html

<%=title%>

closingSingleTag

Specify the single tag closing format

Formats

const render = require('posthtml-render')

const tree = [ { tag: 'img' } ]
'tag'
const html = render(tree, { closingSingleTag: 'tag' })
<custom></custom>
'slash'
const html = render(tree, { closingSingleTag: 'slash' })
<custom />
'default' (Default)
const html = render(tree)
<img>
'closeAs'
const tree = [ {
  tag: 'custom',
  closeAs: 'default' // Available types: `tag` | `slash` | `default`
} ]
const html = render(tree, { closingSingleTag: 'closeAs' })
<custom>

quoteAllAttributes

Specify if all attributes should be quoted.

true (Default)
<i src="index.js"></i>
false
<i src=index.js></i>

replaceQuote

Replaces quotes in attribute values with &quote;.

true (Default)
<img src="<?php echo $foo[&quote;bar&quote;] ?>">
false
<img src="<?php echo $foo["bar"] ?>">

quoteStyle

2 (Default)

Attribute values are wrapped in double quotes:

<img src="https://example.com/example.png" onload="testFunc("test")">
1

Attribute values are wrapped in single quote:

<img src='https://example.com/example.png' onload='testFunc("test")'>
0

Quote style is based on attribute values (an alternative for replaceQuote option):

<img src="https://example.com/example.png" onload='testFunc("test")'>
weex-binding-style-loader@parcel-nightly-unofficial/transformer-html@parcel-nightly-unofficial/transformer-posthtmlproject-name-herezable@ianlucas/parcel-bundler@flame-app/f2-reactget3d-viewerposthtml-markdown@everything-registry/sub-chunk-2463nodeppt-parsereleventy-plugin-code-style-hooksnewxviajes-patch-vuepress-demo-blockmggauhar@edvinas108/parcel-bundlervformlmqchain_diggernative-lazy-loading@lordbeanbag/vite-plugin-svg-icons-monorepo@parcel/transformer-svg@snapview/parcel-bundlerh5-baler@nerdbeere/parcel-bundler@lego-js/tests@mischnic/parcel-bundler@ng-doc/core@parcel/transformer-html@parcel/transformer-posthtmlvuepress-plugin-code-block-nossrvite-plugin-vitepress-code-block@faizanhaider/iconsaxvue-to-dmvuepress-plugin-demo-block-antdxcim-codesandbox@jagi/parcel-bundler@jcblw/parcel-bundler@klipstein/parcel-bundler@mango-js/parcel-transformer-html@pzy915/vite-plugin-vitepress-demohtmltozhhtml-to-react-componentshtml-to-react-components-es6html-i18n-cli@tinajs/mina-sfcparcel-transformer-html-datasrcparcel-transformer-iconifyparcel-plugin-simplephpparcel-bundlerparcel-bundler-forkparcel-bundler-patchparcel-bundler-slparcel-bundler-vueparcel-bundler-without-deasyncparcel-plugin-velocityparcel-plugin-vmpackage-example.jsonwebsite-dependency-graphwebpack-simplywebpack-ysyfe-easy-packgenerator-bootstrap-boilerplate-template@linebyline/editor@jgbjs/plugin-htmlpineglade-bemlinterpineglade-configpineglade-w3cflexscss-parcel-bundlerfront3posthtml-componentposthtml-email-remove-unused-cssposthtml-expressionsposthtml-bem-linterposthtmlposthtml-beautifyposthtml-hintposthtml-typografposthtml-uglifyposthtml-useposthtml-viewposthtml-w3cposthtml-w3c-validatorposthtml-modulesposthtml-nunjucksposthtml-shikiposthtml-spacelessposthtml-svelteposthtml-svg-modeposthtml-tidyposthtml-markdownitposthtml-minifierposthtml-jsxpostsvg@poky85/parcel-bundler@tomzio/parcel-bundlerhulk-markdown-loader@refactorpro/pixi-virtual-joystickinline-css-cli@volkovasystem/parcel-bundler@yanyu-fe/vuepress-plugin-code-block
3.0.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.3.1

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.5

5 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.7

6 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.0

9 years ago