{"library":"parse5-parser-stream","title":"Streaming HTML Parser (parse5-parser-stream)","description":"parse5-parser-stream is a dedicated package within the parse5 HTML parsing toolset, providing a streaming API for parsing HTML documents. It processes HTML incrementally as a Node.js Transform stream, making it suitable for handling large files or real-time data without loading the entire document into memory. The current stable version is 8.0.1. The broader parse5 project, which this package is part of, maintains an active development cadence with frequent patch and minor releases, alongside significant major version updates roughly every one to two years. Its key differentiators include strict adherence to the HTML5 specification, detailed tracking of source code locations for parsed elements (beneficial for tools like linters and formatters), and robust scripting support during parsing.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install parse5-parser-stream"],"cli":null},"imports":["import { ParserStream } from 'parse5-parser-stream';","const { ParserStream } = require('parse5-parser-stream');","import { DefaultTreeAdapter } from 'parse5';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { ParserStream } from 'parse5-parser-stream';\nimport { serialize } from 'parse5';\nimport { pipeline } from 'stream/promises';\n\nasync function parseHtmlStream(htmlContent: string) {\n  const parserStream = new ParserStream();\n  let document: any;\n\n  parserStream.on('end', () => {\n    document = parserStream.document;\n    console.log('Parsing complete. Document:', serialize(document));\n  });\n\n  parserStream.on('error', (err) => {\n    console.error('Parsing error:', err.message);\n  });\n\n  // A simple readable stream to feed content\n  const readableHtml = new (class extends require('stream').Readable {\n    _read() {\n      this.push(htmlContent);\n      this.push(null);\n    }\n  })();\n\n  try {\n    await pipeline(readableHtml, parserStream);\n    console.log('Successfully processed HTML stream.');\n  } catch (error) {\n    console.error('Stream pipeline failed:', error);\n  }\n}\n\n// Example usage\nconst sampleHtml = `<!DOCTYPE html>\n<html>\n  <head>\n    <title>Test Page</title>\n  </head>\n  <body>\n    <p>Hello, <span class=\"name\">World</span>!</p>\n    <!-- A comment -->\n  </body>\n</html>`;\n\nparseHtmlStream(sampleHtml);\n","lang":"typescript","description":"Demonstrates how to use `parse5-parser-stream` to parse HTML content using Node.js streams, including error handling and accessing the final document object. It shows piping a readable stream into the parser stream and then serializing the resulting document.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}