1'use strict'; 2 3const ParserStream = require('parse5-parser-stream'); 4const $ = require('parse5/lib/common/html').TAG_NAMES; 5 6class PlainTextConversionStream extends ParserStream { 7 constructor(options) { 8 super(options); 9 10 // NOTE: see https://html.spec.whatwg.org/#read-text 11 this.parser._insertFakeElement($.HTML); 12 this.parser._insertFakeElement($.HEAD); 13 this.parser.openElements.pop(); 14 this.parser._insertFakeElement($.BODY); 15 this.parser._insertFakeElement($.PRE); 16 this.parser.treeAdapter.insertText(this.parser.openElements.current, '\n'); 17 this.parser.switchToPlaintextParsing(); 18 } 19} 20 21module.exports = PlainTextConversionStream; 22