Giter Site home page Giter Site logo

serkansipahi / handlebars-html-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stevenvachon/handlebars-html-parser

0.0 1.0 0.0 89 KB

Parse Handlebars and HTML (Node.js)

License: MIT License

JavaScript 93.84% Handlebars 5.96% HTML 0.20%

handlebars-html-parser's Introduction

handlebars-html-parser NPM Version Build Status Dependency Status

Parse Handlebars and HTML.

Parse this:

<{{tag}}> value {{{obj.value~}}} </tag>

into this:

[
    { type:"htmlTagStart" },
    { type:"htmlTagNameStart" },
    { type:"hbsTagStart" },
    { type:"hbsExpressionStart" },
    { type:"hbsExpressionPath", value:["tag"] },
    { type:"hbsExpressionEnd" },
    { type:"hbsTagEnd" },
    { type:"htmlTagNameEnd" },
    { type:"htmlTagEnd" },
    
    { type:"text", text:" value " },
    
    { type:"hbsTagStart", notEscaped:true },
    { type:"hbsExpressionStart" },
    { type:"hbsExpressionPath", value:["obj","value"] },
    { type:"hbsExpressionEnd" },
    { type:"hbsTagEnd", stripWhitespace:true, notEscaped:true },
    
    // whitespace stripped
    
    { type:"htmlTagStart", closing:true },
    { type:"htmlTagNameStart" },
    { type:"text", text:"tag" },
    { type:"htmlTagNameEnd" },
    { type:"htmlTagEnd" }
]

…for use in compiling to something like a virtual DOM, such that of handlebars-react.

For more information on the strengths, weaknesses and implementation details of this library, check out the wiki.

Options

options.ignoreHbsComments

Type: Boolean
Default value: false
When true, Handlebars comments will be excluded from output.

options.ignoreHtmlComments

Type: Boolean
Default value: false
When true, HTML comments will be excluded from output.

options.normalizeWhitespace

Type: Boolean
Default value: false
When true, will replace standard whitespace (line breaks, tabs, regular spaces) with a single space. This helps lower compiled template file size and improve runtime performance.

  • Does not affect "special" whitespace chars such as &nbsp;, etc.
  • Does not affect text within <pre>,<script>,<style> tags
  • Does not affect HTML's rendered appearance

FAQ

  1. How is this different from HTMLBars?
    HTMLBars builds a DOM whereas this library allows you to build a DOM and especially a virtual DOM.

  2. Why not use parse5?
    As of v1.5.0, it is not at all "forgiving", in that it will parse <{{tag}}>asdf</{{tag}}> as text instead of HTML.

Roadmap Features

  • add support for sub-expressions
  • add support for {{#if}},{{else}},{{else if}},{{#unless}}
  • add support for {{#with}},{{#each}},{{@index}},{{@key}},{{this}},{{.}},{{undefined}},{{null}},{{true}},{{1}}
  • add support for {{> partial}}
  • options.mustacheOnly that disables helpers, expressions and whitespace control? would have to provide parse errors

Changelog

  • 0.0.1–0.0.9 pre-releases

handlebars-html-parser's People

Contributors

stevenvachon avatar

Watchers

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