3.0.0 • Published 4 years ago

posthtml-render v3.0.0

Weekly downloads
522,459
License
MIT
Repository
github
Last release
4 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-2463xcim-codesandboxsticky-scroll-catchsvg-fill-loadersvg-clrz-loadervite-plugin-move-scriptvitepress-plugin-demoblockvite-plugin-vitepress-code-blockviajes-patch-vuepress-demo-block@dkwasniewski/paczkagenerator-bootstrap-boilerplate-templatejgb-plugin-htmlkigokwasniew-parcel-bundlerchain_diggerst-require-packsr-require-pack@ash9g/parcel-bundler@atlaspack/transformer-html@atlaspack/transformer-posthtml@atlaspack/transformer-svg@alexlafroscia/parcel-bundler@beeanco/render-wordpress-post@ayc0/parcel-bundler@bfehub/vuepress-plugin-code-block@bitfirer/vue-qriously@abtnode/cli@achil/parcel-bundler@abidibo/js-word-event@bouygues-telecom/parcel-bundler@devorso/dcountdown@danmarshall/parcel-bundlervuepress-plugin-demo-block-antdvuepress-plugin-code-block-nossrvue-to-dmwebpack-ysywebsite-dependency-graphwebpack-simplyvformlmq@edvinas108/parcel-bundler@funish/bundle@frodzislaw/front3@glas/parcel-bundler@lordbeanbag/vite-plugin-svg-icons-monorepo@lego-js/tests@linebyline/editor@maizzle/framework@mango-js/parcel-transformer-html@ng-doc/core@nerdbeere/parcel-bundler@faizanhaider/iconsax@mischnic/parcel-bundler@jcblw/parcel-bundler@jagi/parcel-bundler@klipstein/parcel-bundler@jgbjs/plugin-html@pzy915/vite-plugin-vitepress-demo@refactorpro/pixi-virtual-joystick@onlook/angular@poky85/parcel-bundler@parcel/transformer-html@parcel/transformer-posthtml@parcel/transformer-svg@snapview/parcel-bundlermggauharnative-lazy-loadingpackage-example.jsonparcel-transformer-html-datasrcparcel-transformer-iconifyparcel-plugin-simplephpparcel-plugin-velocityparcel-plugin-vmparcel-bundlerparcel-bundler-forkparcel-bundler-patchparcel-bundler-slparcel-bundler-vueparcel-bundler-without-deasyncsan-cli-markdown-loaderscegnewxnodeppt-parserpineglade-bemlinterpineglade-configpineglade-w3cposthtml-tidyposthtml-typografposthtml-uglifyposthtml-useposthtml-viewposthtml-w3c
3.0.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.6

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.1

4 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.5

6 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago

0.0.0

10 years ago