Files
node/tools/eslint/node_modules/parse5/lib/serializer/stream.js
T
Vse Mozhet Byt b4fea2a3d6 doc: add eslint-plugin-markdown
* install eslint-plugin-markdown
* add doc/.eslintrc.yaml
* add `<!-- eslint-disable rule -->` or `<!-- eslint-disable -->`
  for the rest of problematic code
* .js files in doc folder added to .eslintignore
* update Makefile and vcbuild.bat

PR-URL: https://github.com/nodejs/node/pull/12563
Refs: https://github.com/nodejs/node/pull/12557#issuecomment-296015032
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
2017-04-25 00:06:17 +03:00

50 lines
1.4 KiB
JavaScript

'use strict';
var ReadableStream = require('stream').Readable,
inherits = require('util').inherits,
Serializer = require('./index');
/**
* Streaming AST node to an HTML serializer.
* A [readable stream]{@link https://nodejs.org/api/stream.html#stream_class_stream_readable}.
* @class SerializerStream
* @memberof parse5
* @instance
* @extends stream.Readable
* @param {ASTNode} node - Node to serialize.
* @param {SerializerOptions} [options] - Serialization options.
* @example
* var parse5 = require('parse5');
* var fs = require('fs');
*
* var file = fs.createWriteStream('/home/index.html');
*
* // Serializes the parsed document to HTML and writes it to the file.
* var document = parse5.parse('<body>Who is John Galt?</body>');
* var serializer = new parse5.SerializerStream(document);
*
* serializer.pipe(file);
*/
var SerializerStream = module.exports = function (node, options) {
ReadableStream.call(this);
this.serializer = new Serializer(node, options);
Object.defineProperty(this.serializer, 'html', {
//NOTE: To make `+=` concat operator work properly we define
//getter which always returns empty string
get: function () {
return '';
},
set: this.push.bind(this)
});
};
inherits(SerializerStream, ReadableStream);
//Readable stream implementation
SerializerStream.prototype._read = function () {
this.serializer.serialize();
this.push(null);
};