How to use the parse5.serialize function in parse5

To help you get started, we’ve selected a few parse5 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 pluralsight-projects / Vue-BookListing / test / unit / mocha / part5 / book-form-contains-form-data.spec.js View on Github external
file = fs.readFileSync(path.join(process.cwd(), 'src/components/BookForm.vue'), 'utf8');
    } catch (e) {
      assert(false, 'The BookForm.vue file does not exist');
    }

    // Parse document
    const doc = parse5.parseFragment(file.replace(/\n/g, ''), { locationInfo: true });
    const nodes = doc.childNodes;

    // Parse for HTML in template
    const template = nodes.filter(node => node.nodeName === 'template');
    if (template.length == 0) {
      assert(false, "The BookForm component does not contain a template tag")
    }

    const content = parse5.serialize(template[0].content);
    const dom = new JSDOM(content, { includeNodeLocations: true, SVG_LCASE: true });
    const document = dom.window.document;

    // Test for for form existance
    const results = document.querySelector('form');
    if (results == null) {
      assert(false, "The BookForm template does not contain a `form` tag.")
    }
    assert(results.length > 0, 'The BookForm template does not contain a `form` tag');
  });
});
github rxweb / rxweb / rxweb.io / node_modules / @angular-devkit / build-angular / src / angular-cli-files / plugins / index-html-webpack-plugin.js View on Github external
// Inject into the html
            const indexSource = new webpack_sources_1.ReplaceSource(new webpack_sources_1.RawSource(inputContent), this._options.input);
            const scriptElements = treeAdapter.createDocumentFragment();
            for (const script of scripts) {
                const attrs = [
                    { name: 'type', value: 'text/javascript' },
                    { name: 'src', value: (this._options.deployUrl || '') + script },
                ];
                if (this._options.sri) {
                    const content = compilation.assets[script].source();
                    attrs.push(...this._generateSriAttributes(content));
                }
                const element = treeAdapter.createElement('script', undefined, attrs);
                treeAdapter.appendChild(scriptElements, element);
            }
            indexSource.insert(scriptInsertionPoint, parse5.serialize(scriptElements, { treeAdapter }));
            // Adjust base href if specified
            if (typeof this._options.baseHref == 'string') {
                let baseElement;
                for (const headChild of headElement.childNodes) {
                    if (headChild.tagName === 'base') {
                        baseElement = headChild;
                    }
                }
                const baseFragment = treeAdapter.createDocumentFragment();
                if (!baseElement) {
                    baseElement = treeAdapter.createElement('base', undefined, [
                        { name: 'href', value: this._options.baseHref },
                    ]);
                    treeAdapter.appendChild(baseFragment, baseElement);
                    indexSource.insert(headElement.__location.startTag.endOffset + 1, parse5.serialize(baseFragment, { treeAdapter }));
                }
github GoogleChromeLabs / squoosh / config / critters-webpack-plugin.js View on Github external
// `external:false` skips processing of external sheets
    if (this.options.external !== false) {
      const externalSheets = document.querySelectorAll('link[rel="stylesheet"]');
      await Promise.all(externalSheets.map(
        link => this.embedLinkedStylesheet(link, compilation, outputPath)
      ));
    }

    // go through all the style tags in the document and reduce them to only critical CSS
    const styles = document.querySelectorAll('style');
    await Promise.all(styles.map(
      style => this.processStyle(style, document)
    ));

    // serialize the document back to HTML and we're done
    const html = parse5.serialize(document, PARSE5_OPTS);
    return { html };
  }
github bazelbuild / rules_nodejs / packages / inject-html / index.js View on Github external
const noModuleScript = treeAdapter.createElement('script', undefined, nomodule.concat([
        {name: 'src', value: `/${relative(s)}?v=${timestamp()}`},
      ]));
      treeAdapter.appendChild(body, noModuleScript);
    }
  }

  for (const s of params.filter(s => /\.css$/.test(s))) {
    const stylesheet = treeAdapter.createElement('link', undefined, [
      {name: 'rel', value: 'stylesheet'},
      {name: 'href', value: `/${relative(s)}?v=${timestamp()}`},
    ]);
    treeAdapter.appendChild(head, stylesheet);
  }

  const content = parse5.serialize(document, {treeAdapter});
  write(outputFile, content, {encoding: 'utf-8'});
  return 0;
}
github Promact / md2 / libs / @angular / platform-server / bundles / platform-server.umd.js View on Github external
Parse5DomAdapter.prototype.getInnerHTML = function (el) {
          return parse5.serialize(this.templateAwareRoot(el), { treeAdapter: treeAdapter });
      };
      /**
github vuejs / rollup-plugin-vue / src / compiler.js View on Github external
processStyle (node, filePath, content) {
    const lang = checkLang(node) || 'css'
    let style = this.checkSrc(node, filePath)
    const injectFnName = '__$styleInject'
    if (!style) {
      style = parse5.serialize(node)
      const location = content.indexOf(style)
      const before = padContent(content.slice(0, location))
      style = before + style
    }
    let options = this.options.postcss
    options.from = filePath
    options.to = filePath
    return this.compileAsPromise('style', style, lang, filePath)
        .then((res) => {
          return postcss(this.options.postcss.plugins || [])
              .process(res.code, options)
              .then((res) => {
                const code = `export ${injectFnName}(${JSON.stringify(res.css)});`
                return {code: code, type: 'style'}
              })
        })
github dharmeshpipariya-zz / md2 / vendor / @angular / platform-server / bundles / platform-server.umd.js View on Github external
Parse5DomAdapter.prototype.getInnerHTML = function (el) {
            return parse5.serialize(this.templateAwareRoot(el), { treeAdapter: treeAdapter });
        };
        Parse5DomAdapter.prototype.getTemplateContent = function (el) { return null; };
github albertnadal / ng2-daterange-picker / node_modules / @angular / platform-server / @angular / platform-server.js View on Github external
getInnerHTML(el) {
        return parse5$1.serialize(this.templateAwareRoot(el), { treeAdapter });
    }
    /**
github motss / lit-ntml / src / index.ts View on Github external
async function parsePartial(
  fn: typeof parse | typeof parseFragment,
  strings: TemplateStringsArray,
  ...exps: any[]
) {
  try {
    const content = await processLiterals(strings, ...exps);
    return serialize(fn(content));
  } catch (e) {
    throw e;
  }
}