Giter Site home page Giter Site logo

posthtml-render-ejs's Introduction

npm node deps tests coverage chat

PostHTML

PostHTML Render

Renders a PostHTML Tree to HTML/XML

Install

npm i -D posthtml-render

โ„น๏ธ This module is also available for bower and as an AMD, CommonJS and IIFE (global) module, uncompressed and compressed

Usage

NodeJS

const render = require('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>

๐ŸŒ Browser

<!DOCTYPE html>
<html>
<head>
  <title>Title</title>
  <script src="./node_modules/posthtml-render/lib/browser.min.js"></script>
  <script >
    const tree = {
      tag: 'h1',
      attrs: {
        style: 'color: red;'
      },
      content: [ 'Title' ]
    }

    window.onload = function () {
      document.body.innerHTML = render(tree)
    }
  </script>
</head>
<body></body>
</html>

Options

Name Type Default Description
singleTags {Array<String|RegExp>} [] Specify custom single tags (self closing)
closingSingleTag {String} > Specify the single tag closing format

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: 'tag' })
<custom />
'default' (Default)
const html = render(tree)
<img></img>

posthtml-render-ejs's People

Contributors

voischev avatar michael-ciniawsky avatar scrum avatar awinogradov avatar hojas avatar guria avatar island205 avatar maciej-ka avatar

Watchers

Syg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.