How to use the parse5.Serializer 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 waterbearlang / waterbear / bin / refactorings / 01_script_to_ns_fn.js View on Github external
// console.log(node.tagName);
    }
    if (!node['attrs']) return;
    node.attrs.forEach(function(attr){
        if (attr.name === 'script'){
            var script = attr.value;
            var nsFn = script.split('.');
            attr.name = 'ns'
            attr.value = nsFn[0];
            node.attrs.push({name: 'fn', value: nsFn[1]});
        }
    });
}
walk(document, hasScript);

var serializer = new parse5.Serializer();
var refactoredHtml = serializer.serialize(document);
fs.writeFileSync(filename, refactoredHtml);
github RubyLouvre / avalon / string-avalon.js View on Github external
var parse5 = require('parse5')
var parser = new parse5.Parser();
var serializer = new parse5.Serializer();
//https://github.com/exolution/xCube/blob/master/XParser.js
//Then feed it with an HTML document
//------------------------------------------
var expose = Date.now()
function log() {
    if (avalon.config.debug) {
// http://stackoverflow.com/questions/8785624/how-to-safely-wrap-console-log
        console.log.apply(console, arguments)
    }
}
/**
 * Creates a new object without a prototype. This object is useful for lookup without having to
 * guard against prototypically inherited properties via hasOwnProperty.
 *
 * Related micro-benchmarks:
 * - http://jsperf.com/object-create2
github angular / universal / examples / next-hello-world / src / universal_modules / platform-node / node-document.ts View on Github external
import { Parser, Serializer, TreeAdapters } from 'parse5';

// PRIVATE
import { getDOM } from '@angular/platform-browser/src/dom/dom_adapter';
// PRIVATE


const parser = new Parser(TreeAdapters.htmlparser2);
// TODO(gdi2290): fix encodeHtmlEntities: true
const serializer = new Serializer(TreeAdapters.htmlparser2, { encodeHtmlEntities: true });
const treeAdapter = parser.treeAdapter;

export function isTag (tagName, node): boolean {
  return node.type === 'tag' && node.name === tagName;
}

export function parseFragment (el: string): any {
  return parser.parseFragment(el);
}

export function parseDocument (documentHtml: string): any {
  if (documentHtml === undefined) {
    throw new Error('parseDocument requires a document string');
  }
  if (typeof documentHtml !== 'string') {
    throw new Error('parseDocument needs to be a string to be parsed correctly');
github angular / universal / modules / @angular / universal-next-prototype / hello-world / src / platform-node / node-document.ts View on Github external
import {Parser, Serializer, TreeAdapters} from 'parse5';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';


const parser = new Parser(TreeAdapters.htmlparser2);
// TODO(gdi2290): fix encodeHtmlEntities: true
const serializer = new Serializer(TreeAdapters.htmlparser2, { encodeHtmlEntities: true });
const treeAdapter = parser.treeAdapter;

export function isTag (tagName, node): boolean {
  return node.type === 'tag' && node.name === tagName;
}

export function parseFragment (el: string): any {
  return parser.parseFragment(el);
}

export function parseDocument (documentHtml: string): any {
  if (documentHtml === undefined) {
    throw new Error('parseDocument requires a document string');
  }
  if (typeof documentHtml !== 'string') {
    throw new Error('parseDocument needs to be a string to be parsed correctly');
github waterbearlang / waterbear / bin / refactorings / 02_drop_classes_for_ns.js View on Github external
if (klass === namespace){
            node.attrs.splice(index, 1);
            console.log('removing class %s', klass);
            return;
        }
        var classes = klass.split(/\s+/);
        if (classes.indexOf(namespace) > -1){
            classes.splice(classes.indexOf(namespace), 1);
            console.log('updating class %s (%s) to remove %s: %s', klass, node.attrs[index].value, namespace, classes.join(' '));
            node.attrs[index].value = classes.join(' ');
        }
    }
}
walk(document, dropNSFromClasses);

var serializer = new parse5.Serializer();
var refactoredHtml = serializer.serialize(document);
fs.writeFileSync(filename, refactoredHtml);
github panacloud / learn-angular / step9_gulp_router / node_modules / angular2 / src / dom / parse5_adapter.js View on Github external
var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};
var parse5 = require('parse5');
var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
var serializer = new parse5.Serializer(parse5.TreeAdapters.htmlparser2);
var treeAdapter = parser.treeAdapter;
var cssParse = require('css').parse;
var url = require('url');
var collection_1 = require('angular2/src/facade/collection');
var dom_adapter_1 = require('./dom_adapter');
var lang_1 = require('angular2/src/facade/lang');
var selector_1 = require('angular2/src/render/dom/compiler/selector');
var _attrToPropMap = {
    'innerHtml': 'innerHTML',
    'readonly': 'readOnly',
    'tabindex': 'tabIndex',
};
var defDoc = null;
function _notImplemented(methodName) {
    return new lang_1.BaseException('This method is not implemented in Parse5DomAdapter: ' + methodName);
}
github angular / angular / modules / angular2 / src / dom / parse5_adapter.ts View on Github external
var parse5 = require('parse5');
var parser = new parse5.Parser(parse5.TreeAdapters.htmlparser2);
var serializer = new parse5.Serializer(parse5.TreeAdapters.htmlparser2);
var treeAdapter = parser.treeAdapter;

var cssParse = require('css').parse;

var url = require('url');

import {List, MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
import {BaseException, isPresent, isBlank, global} from 'angular2/src/facade/lang';
import {SelectorMatcher, CssSelector} from 'angular2/src/render/dom/compiler/selector';

var _attrToPropMap = {
  'innerHtml': 'innerHTML',
  'readonly': 'readOnly',
  'tabindex': 'tabIndex',
};
github vuejs / vue-loader / lib / template-rewriter.js View on Github external
var parse5 = require('parse5')
var parser = new parse5.Parser()
var serializer = new parse5.Serializer()
var loaderUtils = require('loader-utils')

module.exports = function (html) {
  this.cacheable()
  var query = loaderUtils.parseQuery(this.query)
  var id = query.id
  var tree = parser.parseFragment(html)
  walk(tree, function (node) {
    if (node.attrs) {
      node.attrs.push({
        name: id,
        value: ''
      })
    }
  })
  return serializer.serialize(tree)
github tyrchen / transformer / lib / processors / HtmlProcessor.js View on Github external
constructor(doc) {
    this._doc = doc;
    this._parser = new Parser();
    this._ast = undefined;
    this._css = '';
    this._serializer = new parse5.Serializer();
    this._rules = [];
  }
github Polymer / tools / packages / dom5 / dom5.js View on Github external
function serialize(ast) {
  var serializer = new parse5.Serializer();
  return serializer.serialize(ast);
}