Optionaloptions: ParserOptions<T>Calling the writable.end() method signals that no more data will be written
to the Writable. The optional chunk and encoding arguments allow one
final additional chunk of data to be written immediately before closing the
stream.
Calling the write method after calling end will raise an error.
// Write 'hello, ' and then end with 'world!'.
import fs from 'node:fs';
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
// Writing more now is not allowed!
Optionalchunk: anyOptional data to write. For streams not operating in object mode, chunk must be a {string}, {Buffer},
{TypedArray} or {DataView}. For object mode streams, chunk may be any JavaScript value other than null.
Optionalencoding: anyThe encoding if chunk is a string
Optionalcallback: anyCallback for when the stream is finished.
Raised when parser encounters a <script> element. If this event has listeners, parsing will be suspended once
it is emitted. So, if <script> has the src attribute, you can fetch it, execute and then resume parsing just
like browsers do.
Name of the event
const ParserStream = require('parse5-parser-stream');
const http = require('http');
const parser = new ParserStream();
parser.on('script', (scriptElement, documentWrite, resume) => {
const src = scriptElement.attrs.find(({ name }) => name === 'src').value;
http.get(src, res => {
// Fetch the script content, execute it with DOM built around `parser.document` and
// `document.write` implemented using `documentWrite`.
...
// Then resume parsing.
resume();
});
});
parser.end('<script src="example.com/script.js"></script>');
Base event handler.
Name of the event
Event handler
StaticgetOptionalfragmentContext: T["parentNode"] | nullOptionaloptions: ParserOptions<T>
Converts plain text files into HTML document as required by HTML specification. A writable stream.
Example