{"library":"stream-markdown-parser","title":"Streaming Markdown Parser","type":"library","description":"stream-markdown-parser is a pure JavaScript Markdown parsing and rendering utility library designed with streaming capabilities and framework-agnosticism. Currently at version 0.0.86, it exhibits a rapid release cadence with frequent patch and nightly builds, indicating active development. The library provides core Markdown parsing logic, extracted from the `markstream-vue` project, enabling its use in any JavaScript or TypeScript project without direct Vue dependencies. Key differentiators include its lightweight footprint, extensibility via a plugin-based architecture, comprehensive TypeScript support for type safety, and optimized performance for progressive, stream-friendly parsing. It is built upon `markdown-it-ts`, a TypeScript-first distribution of `markdown-it`, maintaining API compatibility while offering richer token type definitions for developers.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install stream-markdown-parser"],"cli":null},"imports":["import { getMarkdown } from 'stream-markdown-parser'","import { parseMarkdownToStructure } from 'stream-markdown-parser'","import { setDefaultMathOptions } from 'stream-markdown-parser'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/Simon-He95/markstream-vue","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/stream-markdown-parser","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { getMarkdown, parseMarkdownToStructure } from 'stream-markdown-parser';\n\n// Create a markdown-it-ts instance with default plugins. Reusing this instance\n// avoids redundant plugin registrations for performance.\nconst md = getMarkdown();\n\n// Imagine receiving markdown content in chunks from a stream (e.g., SSE, AI response).\nlet bufferedMarkdown = '';\n\nasync function simulateStreamingParsing(chunks: string[]) {\n  for (const chunk of chunks) {\n    bufferedMarkdown += chunk;\n    // Parse the accumulated buffer into an Abstract Syntax Tree (AST).\n    // This AST is designed to be lightweight and suitable for progressive rendering.\n    const nodes = parseMarkdownToStructure(bufferedMarkdown, md);\n    console.log('--- Current AST ---');\n    // In a real application, 'nodes' would be passed to a renderer (e.g., markstream-vue)\n    // to update the UI progressively without re-parsing the entire content from scratch.\n    console.log(JSON.stringify(nodes, null, 2).substring(0, 300) + '...');\n    await new Promise(resolve => setTimeout(resolve, 50)); // Simulate delay\n  }\n  console.log('\\n--- Final AST ---');\n  const finalNodes = parseMarkdownToStructure(bufferedMarkdown, md);\n  console.log(JSON.stringify(finalNodes, null, 2));\n}\n\n// Example usage: Simulate receiving markdown content in multiple parts.\nconst markdownChunks = [\n  '# Hello ', 'World\\n\\nThis is a ', '**streaming** ', 'parser example.\\n\\n- Item 1\\n- Item 2\\n\n```js\nconsole.log(\"Hello\");\n```\n'];\nsimulateStreamingParsing(markdownChunks);\n\n// For basic, non-streaming parsing, you can directly render to HTML if needed:\nconst staticMarkdown = '## Static Content\\n\\nThis is _just_ a test.';\nconst staticNodes = parseMarkdownToStructure(staticMarkdown, md);\nconsole.log('\\n--- Static AST ---');\nconsole.log(JSON.stringify(staticNodes, null, 2).substring(0, 300) + '...');\n// If HTML output is still required, the underlying markdown-it-ts instance can render it.\n// const htmlOutput = md.render?.(staticMarkdown); // Uncomment to see HTML output\n","lang":"typescript","description":"This quickstart demonstrates how to use stream-markdown-parser for both incremental (streaming) and static Markdown parsing, outputting a progressively built AST structure. It highlights reusing the parser instance for efficiency.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}