Coder Social home page Coder Social logo

htmljs-parser's Introduction


htmljs-parser
Styled with prettier Build status Code Coverage NPM version Downloads

An HTML parser with super powers used by Marko.

Installation

npm install htmljs-parser

Creating A Parser

First we must create a parser instance and pass it some handlers for the various parse events shown below.

Each parse event is called a Range and is an object with start and end properties which are zero-based offsets from the beginning of th parsed code.

Additional meta data and nested ranges are exposed on some events shown below.

You can get the raw string from any range using parser.read(range).

import { createParser, ErrorCode, TagType } from "htmljs-parser";

const parser = createParser({
  /**
   * Called when the parser encounters an error.
   *
   * @example
   * 1╭─ <a><b
   *  ╰─     ╰─ error(code: 19, message: "EOF reached while parsing open tag")
   */
  onError(range) {
    range.code; // An error code id. You can see the list of error codes in ErrorCode imported above.
    range.message; // A human readable (hopefully) error message.
  },

  /**
   * Called when some static text is parsed within some body content.
   *
   * @example
   * 1╭─ <div>Hi</div>
   *  ╰─      ╰─ text "Hi"
   */
  onText(range) {},

  /**
   * Called after parsing a placeholder within body content.
   *
   * @example
   * 1╭─ <div>${hello} $!{world}</div>
   *  │       │ │      │  ╰─ placeholder.value "world"
   *  │       │ │      ╰─ placeholder "$!{world}"
   *  │       │ ╰─ placeholder:escape.value "hello"
   *  ╰─      ╰─ placeholder:escape "${hello}"
   */
  onPlaceholder(range) {
    range.escape; // true for ${} placeholders and false for $!{} placeholders.
    range.value; // Another range that includes only the placeholder value itself without the wrapping braces.
  },

  /**
   * Called when we find a comment at the root of the document or within a tags contents.
   * It will not be fired for comments within expressions, such as attribute values.
   *
   * @example
   * 1╭─ <!-- hi -->
   *  │  │   ╰─ comment.value " hi "
   *  ╰─ ╰─ comment "<!-- hi -->"
   * 2╭─ // hi
   *  │  │ ╰─ comment.value " hi"
   *  ╰─ ╰─ comment "// hi"
   */
  onComment(range) {
    range.value; // Another range that only includes the contents of the comment.
  },

  /**
   * Called after parsing a CDATA section.
   * // https://developer.mozilla.org/en-US/docs/Web/API/CDATASection
   *
   * @example
   * 1╭─ <![CDATA[hi]]>
   *  │  │        ╰─ cdata.value "hi"
   *  ╰─ ╰─ cdata "<![CDATA[hi]]>"
   */
  onCDATA(range) {
    range.value; // Another range that only includes the contents of the CDATA.
  },

  /**
   * Called after parsing a DocType comment.
   * https://developer.mozilla.org/en-US/docs/Web/API/DocumentType
   *
   * @example
   * 1╭─ <!DOCTYPE html>
   *  │  │ ╰─ doctype.value "DOCTYPE html"
   *  ╰─ ╰─ doctype "<!DOCTYPE html>"
   */
  onDoctype(range) {
    range.value; // Another range that only includes the contents of the DocType.
  },

  /**
   * Called after parsing an XML declaration.
   * https://developer.mozilla.org/en-US/docs/Web/XML/XML_introduction#xml_declaration
   *
   * @example
   * 1╭─ <?xml version="1.0" encoding="UTF-8"?>
   *  │  │ ╰─ declaration.value "xml version=\"1.0\" encoding=\"UTF-8\""
   *  ╰─ ╰─ declaration "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
   */
  onDeclaration(range) {
    range.value; // Another range that only includes the contents of the declaration.
  },

  /**
   * Called after parsing a scriptlet (new line followed by a $).
   *
   * @example
   * 1╭─ $ foo();
   *  │   │╰─ scriptlet.value "foo();"
   *  ╰─  ╰─ scriptlet " foo();"
   * 2╭─ $ { bar(); }
   *  │   │ ╰─ scriptlet:block.value " bar(); "
   *  ╰─  ╰─ scriptlet:block " { bar(); }"
   */
  onScriptlet(range) {
    range.block; // true if the scriptlet was contained within braces.
    range.value; // Another range that includes only the value itself without the leading $ or surrounding braces (if applicable).
  },

  /**
   * Called when we're about to begin an HTML open tag (before the tag name).
   * Note: This is only called for HTML mode tags and can be used to track if you are in concise mode.
   *
   * @example
   * 1╭─ <div>Hi</div>
   *  ╰─ ╰─ openTagStart
   */
  onOpenTagStart(range) {},

  /**
   * Called when a tag name, which can include placeholders, has been parsed.
   *
   * @example
   * 1╭─ <div/>
   *  ╰─  ╰─ openTagName "div"
   * 2╭─ <hello-${test}-again/>
   *  │   │     │      ╰─ openTagName.quasis[1] "-again"
   *  │   │     ╰─ openTagName.expressions[0] "${test}"
   *  │   ├─ openTagName.quasis[0] "hello-"
   *  ╰─  ╰─ openTagName "hello-${test}-again"
   */
  onOpenTagName(range) {
    range.quasis; // An array of ranges that indicate the string literal parts of the tag name.
    range.expressions; // A list of placeholder ranges (similar to whats emitted via onPlaceholder).

    // Return a different tag type enum value to enter a different parse mode.
    // Below is approximately what Marko uses:
    switch (parser.read(range)) {
      case "area":
      case "base":
      case "br":
      case "col":
      case "embed":
      case "hr":
      case "img":
      case "input":
      case "link":
      case "meta":
      case "param":
      case "source":
      case "track":
      case "wbr":
        // TagType.void makes this a void element (cannot have children).
        return TagType.void;
      case "html-comment":
      case "script":
      case "style":
      case "textarea":
        // TagType.text makes the child content text only (with placeholders).
        return TagType.text;
      case "class":
      case "export":
      case "import":
      case "static":
        // TagType.statement makes this a statement tag where the content following the tag name will be parsed as script code until we reach a new line, eg for `import x from "y"`).
        return TagType.statement;
    }

    // TagType.html is the default which allows child content as html with placeholders.
    return TagType.html;
  },

  /**
   * Called when a shorthand id, which can include placeholders, has been parsed.
   *
   * @example
   * 1╭─ <div#hello-${test}-again/>
   *  │      ││     │       ╰─ tagShorthandId.quasis[1] "-again"
   *  │      ││     ╰─ tagShorthandId.expressions[0] "${test}"
   *  │      │╰─ tagShorthandId.quasis[0] "hello-"
   *  ╰─     ╰─ tagShorthandId "#hello-${test}-again"
   */
  onTagShorthandId(range) {
    range.quasis; // An array of ranges that indicate the string literal parts of the shorthand id name.
    range.expressions; // A list of placeholder ranges (similar to whats emitted via onPlaceholder).
  },

  /**
   * Called when a shorthand class name, which can include placeholders, has been parsed.
   * Note there can be multiple of these.
   *
   * @example
   * 1╭─ <div.hello-${test}-again/>
   *  │      ││     │       ╰─ tagShorthandClassName.quasis[1] "-again"
   *  │      ││     ╰─ tagShorthandClassName.expressions[0] "${test}"
   *  │      │╰─ tagShorthandClassName.quasis[0] "hello-"
   *  ╰─     ╰─ tagShorthandClassName "#hello-${test}-again"
   */
  onTagShorthandClass(range) {
    range.quasis; // An array of ranges that indicate the string literal parts of the shorthand id name.
    range.expressions; // A list of placeholder ranges (similar to whats emitted via onPlaceholder).
  },

  /**
   * Called after the type arguments for a tag have been parsed.
   *
   * @example
   * 1╭─ <foo<string>>
   *  │      │╰─ tagTypeArgs.value "string"
   *  ╰─     ╰─ tagTypeArgs "<string>"
   */
  onTagTypeArgs(range) {
    range.value; // Another range that includes only the type arguments themselves and not the angle brackets.
  },

  /**
   * Called after a tag variable has been parsed.
   *
   * @example
   * 1╭─ <div/el/>
   *  │      │╰─ tagVar.value "el"
   *  ╰─     ╰─ tagVar "/el"
   */
  onTagVar(range) {
    range.value; // Another range that includes only the tag var itself and not the leading slash.
  },

  /**
   * Called after tag arguments have been parsed.
   *
   * @example
   * 1╭─ <if(x)>
   *  │     │╰─ tagArgs.value "x"
   *  ╰─    ╰─ tagArgs "(x)"
   */
  onTagArgs(range) {
    range.value; // Another range that includes only the args themselves and not the outer parenthesis.
  },

  /**
   * Called after type parameters for the tag parameters have been parsed.
   *
   * @example
   * 1╭─ <tag<T>|input: { name: T }|>
   *  │      │╰─ tagTypeParams.value
   *  ╰─     ╰─ tagTypeParams "<T>"
   */
  onTagTypeParams(range) {
    range.value; // Another range that includes only the type params themselves and not the angle brackets.
  },

  /**
   * Called after tag parameters have been parsed.
   *
   * @example
   * 1╭─ <for|item| of=list>
   *  │      │╰─ tagParams.value "item"
   *  ╰─     ╰─ tagParams "|item|"
   */
  onTagParams(range) {
    range.value; // Another range that includes only the params themselves and not the outer pipes.
  },

  /**
   * Called after an attribute name as been parsed.
   * Note this may be followed by the related AttrArgs, AttrValue or AttrMethod. It can also be directly followed by another AttrName, AttrSpread or the OpenTagEnd if this is a boolean attribute.
   *
   * @example
   * 1╭─ <div class="hi">
   *  ╰─      ╰─ attrName "class"
   */
  onAttrName(range) {},

  /**
   * Called after attr arguments have been parsed.
   *
   * @example
   * 1╭─ <div if(x)>
   *  │         │╰─ attrArgs.value "x"
   *  ╰─        ╰─ attrArgs "(x)"
   */
  onAttrArgs(range) {
    range.value; // Another range that includes only the args themselves and not the outer parenthesis.
  },

  /**
   * Called after an attr value has been parsed.
   *
   * @example
   * 1╭─ <input name="hi" value:=x>
   *  │             ││         │ ╰─ attrValue:bound.value
   *  │             ││         ╰─ attrValue:bound ":=x"
   *  │             │╰─ attrValue.value "\"hi\""
   *  ╰─            ╰─ attrValue "=\"hi\""
   */
  onAttrValue(range) {
    range.bound; // true if the attribute value was preceded by :=.
    range.value; // Another range that includes only the value itself without the leading = or :=.
  },

  /**
   * Called after an attribute method shorthand has been parsed.
   *
   * @example
   * 1╭─ <div onClick(ev) { foo(); }>
   *  │              ││   │╰─ attrMethod.body.value " foo(); "
   *  │              ││   ╰─ attrMethod.body "{ foo(); }"
   *  │              │╰─ attrMethod.params.value "ev"
   *  │              ├─ attrMethod.params "(ev)"
   *  ╰─             ╰─ attrMethod "(ev) { foo(); }"
   */
  onAttrMethod(range) {
    range.typeParams; // Another range which includes the type params for the method.
    range.typeParams.value; // Another range which includes the type params without outer angle brackets.

    range.params; // Another range which includes the params for the method.
    range.params.value; // Another range which includes the method params without outer parenthesis.

    range.body; // Another range which includes the entire body block.
    range.body.value; // Another range which includes the body block without outer braces.
  },

  /**
   * Called after we've parsed a spread attribute.
   *
   * @example
   * 1╭─ <div ...attrs>
   *  │       │  ╰─ attrSpread.value "attrs"
   *  ╰─      ╰─ attrSpread "...attrs"
   */
  onAttrSpread(range) {
    range.value; // Another range that includes only the value itself without the leading ...
  },

  /**
   * Called once we've completed parsing the open tag.
   *
   * @example
   * 1╭─ <div><span/></div>
   *  │      │     ╰─ openTagEnd:selfClosed "/>"
   *  ╰─     ╰─ openTagEnd ">"
   */
  onOpenTagEnd(range) {
    range.selfClosed; // true if this tag was self closed (the onCloseTag* handlers will not be called if so).
  },

  /**
   * Called when we start parsing and html closing tag.
   * Note this is not emitted for concise, selfClosed, void or statement tags.
   *
   * @example
   * 1╭─ <div><span/></div>
   *  ╰─             ╰─ closeTagStart "</"
   */
  onCloseTagStart(range) {},

  /**
   * Called after the content within the brackets of an html closing tag has been parsed.
   * Note this is not emitted for concise, selfClosed, void or statement tags.
   *
   * @example
   * 1╭─ <div><span/></div>
   *  ╰─               ╰─ closeTagName "div"
   */
  onCloseTagName(range) {},

  /**
   * Called once the closing tag has finished parsing, or in concise mode we hit an outdent or eof.
   * Note this is not called for selfClosed, void or statement tags.
   *
   * @example
   * 1╭─ <div><span/></div>
   *  ╰─                  ╰─ closeTagEnd ">"
   */
  onCloseTagEnd(range) {},
});

Finally after setting up the parser with it's handlers, it's time to pass in some source code to parse.

parser.parse("<div></div>");

Parser Helpers

The parser instance provides a few helpers to make it easier to work with the parsed content.

// Pass any range object into this method to get the raw string from the source for the range.
parser.read(range);

// Given an zero based offset within the source code, returns a position object that contains line and column properties.
parser.positionAt(offset);

// Given a range object returns a location object with start and end properties which are each position objects as returned from the "positionAt" api.
parser.locationAt(range);

Code of Conduct

This project adheres to the eBay Code of Conduct. By participating in this project you agree to abide by its terms.

htmljs-parser's People

Contributors

austinkelleher avatar dylanpiercey avatar gilbert avatar github-actions[bot] avatar greenkeeper[bot] avatar ismail-codar avatar mlrawlings avatar patrick-steele-idem avatar philidem avatar snyamathi avatar starptech avatar thomasmcdonald avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

htmljs-parser's Issues

Incorrectly throwing missing ending tag

<span></span><div>
</div>

Throws the error: Missing ending "div" tag

All of these work as expected:

<span></span><div></div>
<span></span>
<div>
</div>
--
<span></span><div>
</div>
--

Arguments for HTML tags and attributes should not include parenthesis

Currently, the event for <for(var i=0; i<10; i++)> is the following:

{
    type: 'opentag',
    name: 'for',
    arguments: [
        '(var i = 0; i < 10; i++)'
    ],
    attributes: []
}

The following would be better:

{
    type: 'opentag',
    name: 'for',
    arguments: [
        'var i = 0; i < 10; i++'
    ],
    attributes: []
}

CDATA is not parsed correctly

Given:

<html-comment><![CDATA[[if lt IE 9]><div><![endif]]]></html-comment>

This is getting parsed as the following:

[
    {
        "type": "opentag",
        "tagName": "html-comment",
        "attributes": [],
        "pos": 0
    },
    {
        "type": "cdata",
        "text": "[if lt IE 9><div><![endif"
    },
    {
        "type": "closetag",
        "tagName": "html-comment"
    }
]

Add support for concise syntax

#another-div
    <div class="something">
        <!-- Everything inside this tag will be parsed as HTML -->
        <h2>Heading 2</h2>
        Some <b>bold</b> text. Some <em>emphasis</em>.
        <div class="something-else">
            Good thing there are no
            more periods.
        </div>
    </div>
    span.foo - Hello ${data.name}!

Forward slashes from URLs incorrectly parsed as single line comments

My previously working marko template is now failing to compile due to URL forward slashes causing htmljs-parser to think they are single line code comments. I believe the recently merged PR, caused this issue: https://github.com/marko-js/htmljs-parser/pull/69/files

Example code:

let noScriptImgUrl = `https://sb.scorecardresearch.com`;

Marko compile error:

- Failed to compile "src/components/foo.marko". Error: Error: An error occurred while trying to compile template at path "/Users/Dev/app/src/components/foo.marko". Error(s) in template:
1) [src/components/foo.marko:1:1] EOF reached while parsing scriptet

    at handleErrors (/Users/Dev/app/node_modules/marko/src/compiler/Compiler.js:95:21)
    at Compiler.compile (/Users/Dev/app/node_modules/marko/src/compiler/Compiler.js:178:9)
    at _compile (/Users/Dev/app/node_modules/marko/src/compiler/index.js:88:33)
    at /Users/Dev/app/node_modules/marko/src/compiler/index.js:146:13
    at FSReqWrap.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:53:3)

Dependencies:

onattributeplaceholder is only called for outer placeholders

Given:

<div class="$!{foo + 'nested ${bar}'}">
</div>

The onattributeplaceholder event only fires once:

{ escape: false,
  type: 'attributeplaceholder',
  expression: 'foo + (\'nested \'+(bar))',
  pos: 12 }

It is not fired for the inner placeholder.

The automated release is failing 🚨

🚨 The automated release from the next branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the next branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot 📦🚀

Empty string body in class tag

class Foo {
    constructor() {

    }
}
 
var foo = new Foo();

Above code will throw an INVALID_BODY error (for the class tag) due to the space on the new line (after }). Should not do that for empty strings.

Strip JavaScript block comments within open tag

Input:

<div foo="bar" /*this is a comment*/ hello="world" /* this is another comment */>
</div>

Output event for open tag:

{
    tagName: 'div',
    attributes: [
        {
            name: 'foo',
            value: '"bar"',
            literalValue: 'bar'
        },
        {
            name: 'hello',
            value: '"world"',
            literalValue: 'world'
        }
    ]
}

Escaped single quote in strings not parsed correctly

Given the following input:

var decade = '1960\'s'

The following error will be produced currently:

error:"Invalid string (\"1960\\'s\"): SyntaxError: Unexpected token ' in JSON at position 6" (code: "INVALID_STRING")

Fun fact, JSON.parse() will throw an error when passed "1970\'s"

Works: JSON.parse('"1970\\\"s"')
Does not work: JSON.parse('"1970\\\'s"')
Works: eval('"1970\\\'s"')

Change how placeholders at the beginning of a concise line are handled

htmljs-parser supports dynamic tag names:

<div>
  <${foo ? 'span' : 'a'}>Foo</>
</div>

Currently, when parsing in concise mode, a placeholder at the start of the line is parsed as a text placeholder instead of a tag name placeholder. We are changing how ${...} at the start of a concise line such that it will now be parsed as a dynamic tag name. Thus, the following concise template is equivalent to the above HTML template:

div
  ${foo ? 'span' : 'a'} -- Foo

Current mechanism for changing parser state does not work with the validating parser

By time the open tag event is actually emitted to the application code it is too late to change the parser state. The validating parser waits until the entire document has been parsed before emitting the parser events.

Proposed solution:

Expose a function parserStateProvider(event) : String option. The user-provided parserStateProvider function is allowed to return one of the following values:

  • "static-text" (equivalent to enterStaticTextContentState())
  • "parsed-text" (equivalent toenterParsedTextContentState()`)
  • "html" (equivalent to enterHtmlContentState(), the default)
  • null/undefined (use the default state)

Support JavaScript-style comments in concise mode

div
  // This is a single line comment
  - This is the body of the div tag
p
  /*
  This is a
  multiline comment
  */
  - This is the body of the p tag

Output:

<div>
  <!-- This is a single line comment-->
  This is the body of the div tag
</div>
<p>
  <!--
  This is a
  multiline comment
  -->
  This is the body of the p tag
</p>

Allow placeholders in tag name

<${myTagName} class="foo"></${myTagName}>
<${myTagName} class="foo"></>

Placeholders at the beginning should not be allowed in concise mode since the placeholder would be recognized as body placeholder content.

String literals are not properly handled

String expressions are not correctly evaluated/parsed to their literal equivalent. Currently, the parser does handle escape characters that appear in the string.

Deprecate "-" in favor of "--" in concise parsing mode

OLD:

h1 - Hello World!

NEW:

h1 -- Hello World!

Why?

With the change to support spaces in any attribute values in, the usage of a single hyphen (AKA minus sign) is now ambiguous. For example, given the following input:

todos remaining = total  - completed

This could be interpreted as either of the following:

<todos remaining=(total - completed)/>
<todos remaining=total>completed</todos>

To avoid the ambiguity, we are now requiring two hyphens (surrounded by spaces). While two hyphens can be used as a unary operator JavaScript expressions, it would never appear with spaces before and after (" -- ").

Additional details

Concise mode text

- to start an html block will be deprecated in v3. Two (or more) dashes will be required. This is partly to allow var foo = 3 - 2; without any ambiguity and keep consistency throughout the language.

Two (or more) dashes followed by a space and some text indicate one line of an html text block:

div class="foo" -- Hello World
div class="foo" 
    -- Hello World

Two (or more) dashes followed by a line break indicate the beginning of a multiline html text block. The lines that follow must maintain the indentation or they will enter back into concise mode as a sibling tag:

div class="foo" -- 
    Hello World
    What's up?
span -- Meh
div class="foo" 
    -- 
    Hello World
    What's up?
span -- Meh

A multiline html text block can be ended by the same number of dashes that opened it so that additional children can be added to the parent tag:

div class="foo" -- 
    Hello World
    What's up?
    --
    span -- Meh.
div class="foo" 
    -- 
    Hello World
    What's up?
    --
    span -- Meh.

Related Pull Requests:

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Regular text in THAI identified as tag

I have the following string in English
Before performing this bulk merge operation, you must have a recipient group and template in place.<BR>All bulk email communication sent through {1:product name} must meet the requirements defined in the Mass Email Messaging <a href='xxxxx' target='_blank'>Terms of Service</a>.<BR>

and a corresponding THAI translation

ก่อนที่จะดำเนินการในการส่งจดหมายถึงผู้รับหลายคนนี้ คุณต้องมีกลุ่มผู้รับและแม่แบบอยู่แล้ว<BR>การรับส่งอีเมลทั้งหมดในปริมาณมากซึ่งส่งผ่าน {1:product name} ต้องเป็นไปตามข้อกำหนดที่กำหนดไว้ใน<a href='xxxxx' target='_blank'>เงื่อนไขการให้บริการ</a>ด้านการส่งข้อความอีเมลจำนวนมาก<BR>

The parse is OK for the English string, but incorrectly identifies the Thai text as tags. For example:

{
    type: 'openTag',
    tagName: 'ก่อนที่จะดำเนินการในการส่งจดหมายถึงผู้รับหลายคนนี้',
    tagNameExpression: undefined,
    emptyTagName: undefined,
    argument: undefined,
    params: undefined,
    pos: 0,
    endPos: 313,
    tagNameEndPos: 50,
    openTagOnly: false,
    selfClosed: false,
    concise: true,
    attributes: [Array],
    setParseOptions: [Function]
  }

Is there any known specific configuration to be used for Thai language or other unicode, or any workaround I could use to eliminate this false positive?

Thanks

Expressions generated when there are placeholders in strings should be wrapped in parenthesis

Given the following:

<a title=foo+"Hello ${data.name">

The title attribute is being provided with the following expression:

foo+'Hello '+data.name+''

There are two problems with this:

  1. The expression is not wrapped in parenthesis so order of operations is wrong
  2. There is an extra empty string on the end

The code needs to be improved to produce the following expression:

foo+('Hello '+data.name)

How to deal with included tags?

Hi,

I'm trying to parse

<ol>
	<li><h1>my title</h1></li>
	<li>my string</li>
</ol>

and get li tags innert HTML i.e:

[
    "<h1>my title</h1>",
    "my string"
]

What would be the the good approach to get included tags inner HTML?

Thanks!

Tag with expression attribute example output is not correct

<say-something message="Hello "+data.name> example (from README.md) returns as

{type: "error", code: "INVALID_STRING", message: "Invalid string ("Hello "+data.name): SyntaxError: Unexpected token + in JSON at position 8", pos: 22, endPos: 42}

Support vdom output (react or others).

I haven't had a ton of time to dig into this library but it looks like a pretty solid templating language. I was wondering if there are any effort to support virtual DOM Esq output similar to JSX?

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.