How to use htmljs-parser - 3 common examples

To help you get started, we’ve selected a few htmljs-parser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marko-js / language-server / server / src / utils / htmljs-parser.ts View on Github external
export function parseUntilOffset(options: {
  offset: number;
  text: string;
  taglib: TagLibLookup;
  includeErrors?: boolean;
}) {
  const { offset, text, taglib, includeErrors } = options;
  let result: ParserEvents.Any | null = null;
  let parentTag: ParserEvents.OpenTagName | ParserEvents.OpenTag | null = null;
  const parser = createParser(
    {
      onError: includeErrors && finish,
      onScriptlet: finish,
      onPlaceholder: finish,
      onOpenTagName(ev: ParserEvents.OpenTagName) {
        if (parentTag) {
          ev.parent = parentTag as ParserEvents.OpenTag;
        }

        // Currently the parser has the wrong end position here with tag params :\
        if (!ev.concise) {
          ev.pos += 1;
        }

        ev.endPos = ev.pos + ev.tagName.length;
        parentTag = ev;
github marko-js / marko / src / compiler / HtmlJsParser.js View on Github external
// Text within XML comment
                handlers.handleComment(event.value);
            },

            onScriptlet(event) {
                // <% (code) %> or $ {}
                handlers.handleScriptlet(event);
            },

            onError(event) {
                handlers.handleError(event);
            }
        };

        var mergedOptions = Object.assign({}, this.defaultOptions, options);
        var parser = (this.parser = htmljs.createParser(listeners, {
            ignorePlaceholders: mergedOptions.ignorePlaceholders,
            isOpenTagOnly: function(tagName) {
                return handlers.isOpenTagOnly(tagName);
            }
        }));
        parser.parse(src, filename);
    }
}
github marko-js / language-server / server / src / util / autocomplete.ts View on Github external
return new Promise(function (resolve: (tag: Scope | boolean) => any) {
        const parser = createParser({
            onError: (error: any, data: any) => {
                resolve({
                    tagName: error.code,
                    scopeType: ScopeType.NO_SCOPE,
                    data,
                });
            },
            onOpenTag: (event: IHtMLJSParserEvent) => {
                const {
                    pos: startPos,
                    endPos,
                    tagName,
                    tagNameEndPos,
                    attributes,
                } = event;

htmljs-parser

An HTML parser recognizes content and string placeholders and allows JavaScript expressions as attribute values

MIT
Latest version published 24 days ago

Package Health Score

81 / 100
Full package analysis

Popular htmljs-parser functions