{"_id":"@bmcmahen/streaming-markdown","name":"@bmcmahen/streaming-markdown","dist-tags":{"latest":"0.2.15"},"versions":{"0.2.15":{"name":"@bmcmahen/streaming-markdown","version":"0.2.15","author":{"name":"Damian Tarnawski","email":"gthetarnav@gmail.com"},"description":"Streaming Markdown parser, à la ChatGPT","license":"MIT","repository":{"type":"git","url":"git+https://github.com/thetarnav/streaming-markdown.git"},"homepage":"https://thetarnav.github.io/streaming-markdown","private":false,"sideEffects":false,"type":"module","browser":"./smd.min.js","module":"./smd.js","types":"./smd.d.ts","exports":{"import":{"types":"./smd.d.ts","default":"./smd.js"}},"devDependencies":{"@types/node":"^22.15.3","esbuild":"^0.25.3","typescript":"^5.8.3"},"keywords":["markdown","parser","html","ai"],"engines":{"node":">=20"},"publishConfig":{"access":"public"},"scripts":{"dev":"node ./dev.js","test":"node --test --test-reporter=dot","typecheck":"tsc --noEmit","build":"node ./build.js"},"_id":"@bmcmahen/streaming-markdown@0.2.15","bugs":{"url":"https://github.com/thetarnav/streaming-markdown/issues"},"_integrity":"sha512-BPLLqN2fY0EvLevSdVe5RPsD7666JgBFgInQPnFwctgQSB9iVvazoPwN1Wk3nOgDIDPMY+x4QLUV8qN7TzVBfQ==","_resolved":"/private/var/folders/z9/gbv_q3997z79tfjm9y_jq0w00000gq/T/3712c15270d12104a9995b4362b21f0c/bmcmahen-streaming-markdown-0.2.15.tgz","_from":"file:bmcmahen-streaming-markdown-0.2.15.tgz","_nodeVersion":"22.17.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-BPLLqN2fY0EvLevSdVe5RPsD7666JgBFgInQPnFwctgQSB9iVvazoPwN1Wk3nOgDIDPMY+x4QLUV8qN7TzVBfQ==","shasum":"d0c7dc522211669d3bed4177f5afce6443c1b3f8","tarball":"https://registry.npmjs.org/@bmcmahen/streaming-markdown/-/streaming-markdown-0.2.15.tgz","fileCount":7,"unpackedSize":91828,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIH/s4bhqAp5iY5xybt9SOONlKHRhr1sjHrr6uB15YycfAiANBDPvgd8rW4Flimyt7AGDIFAZOcx4pqPSvem3q+ZB6g=="}]},"_npmUser":{"name":"bmcmahen","email":"ben.mcmahen@gmail.com"},"directories":{},"maintainers":[{"name":"bmcmahen","email":"ben.mcmahen@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/streaming-markdown_0.2.15_1755629025987_0.8557475653289022"},"_hasShrinkwrap":false}},"time":{"created":"2025-08-19T18:43:45.868Z","0.2.15":"2025-08-19T18:43:46.185Z","modified":"2025-08-19T18:43:46.764Z"},"maintainers":[{"name":"bmcmahen","email":"ben.mcmahen@gmail.com"}],"description":"Streaming Markdown parser, à la ChatGPT","homepage":"https://thetarnav.github.io/streaming-markdown","keywords":["markdown","parser","html","ai"],"repository":{"type":"git","url":"git+https://github.com/thetarnav/streaming-markdown.git"},"author":{"name":"Damian Tarnawski","email":"gthetarnav@gmail.com"},"bugs":{"url":"https://github.com/thetarnav/streaming-markdown/issues"},"license":"MIT","readme":"# Streaming *Markdown*\n\n[![version](https://img.shields.io/npm/v/streaming-markdown?logo=npm)](https://www.npmjs.com/package/streaming-markdown) [![github](https://img.shields.io/badge/GitHub-streaming--markdown-orange?logo=github)](https://github.com/thetarnav/streaming-markdown)\n\n**Experiment making a streaming makdown parser *à la ChatGPT.***\n\n---\n\n## Installation\n\nInstall `streaming-markdown` package from npm.\n\n```bash\nnpm install streaming-markdown\n```\n\n*Or just copy [**`smd.js`**](https://github.com/thetarnav/streaming-markdown/blob/main/smd.js) file to your project.*\n\nOr use the [CDN link](https://www.jsdelivr.com/package/npm/streaming-markdown).\\\nIt's a minified *(3kB Gzip)* version of the package, with only the necessary functions exported.\\\nSee the exports in [`smd_min_entry.js`](https://github.com/thetarnav/streaming-markdown/blob/main/smd_min_entry.js).\\\nThe package uses ES module exports, so you need to use `type=\"module\"` in your script tag.\n\n```html\n<script type=\"module\">\n    import * as smd from \"https://cdn.jsdelivr.net/npm/streaming-markdown/smd.min.js\"\n    // ...\n</script>\n```\n\n## Usage\n\nFirst create new markdown `Parser` by calling `parser` function.\\\nIt's single argument is a `Renderer` object, which is an interface to render the parsed markdown tokens to the DOM.\\\nThere are two built-in renderers—`default_renderer` and `logger_renderer`—that you can try at first.\n\n```js\nimport * as smd from \"streaming-markdown\"\n\nconst element  = document.getElementById(\"markdown\")\nconst renderer = smd.default_renderer(element)\nconst parser   = smd.parser(renderer)\n```\n\n### `write` function\n\nThen, you can start streaming markdown to the `Parser` by calling `parser_write` function with the chunk of markdown string.\n\n```js\nsmd.parser_write(parser, \"# Streaming Markdown\\n\\n\")\n```\n\n*You can write **as many times as you want** to stream the markdown.*\n\nThe parser is optimistic.\nWhen it sees the start of an inline code block or code block,\nit will immediately style the element accordingly.\n\nE.g. `` `print(\"hello wor `` should be rendered as `<code>print(\"hello wor</code>`\n\nWhile the text is streamed in, the user should be able to select the text that has already been streamed in and copy it.\n*(The parser is only adding new elements to the DOM, not modifying the existing ones.)*\n\n### `end` function\n\nFinally, you can end the stream by calling `end` function.\n\nIt will reset the `Parser` state and flush the remaining markdown.\n\n```js\nsmd.parser_end(parser)\n```\n\n### Renderer interface\n\n| Field name  | Type                   | Description |\n| ----------- | ---------------------- | ----------- |\n| `data`      | `T`                    | User data object.<br>Available as first param in callbacks. |\n| `add_token` | `Renderer_Add_Token<T>`| When the tokens starts. |\n| `end_token` | `Renderer_End_Token<T>`| When the token ends. |\n| `add_text`  | `Renderer_Add_Text<T>` | To append text to current token.<br>Can be called multiple times or none. |\n| `set_attr`  | `Renderer_Set_Attr<T>` | Set additional attributes of current token eg. the link url. |\n\n## Markdown features\n\n- [x] Paragraphs\n- [x] Line breaks\n    - [x] don't end tokens\n    - [x] Escaping line breaks\n- [x] Trim unnecessary spaces\n- [x] Headers\n    - [ ] ~~Alternate syntax~~ *(not planned)*\n- [x] Code Block with indent\n- [x] Code Block with triple backticks\n    - [x] language attr\n    - [x] with many backticks\n- [x] `` `inline code` `` with backticks\n    - [x] with many backticks\n    - [x] trim spaces ` code `\n- [x] *italic* with single asterisks\n- [x] **Bold** with double asterisks\n- [x] _italic_ with underscores\n- [x] __Bold__ with double underscores\n- [x] Special cases:\n    - [x] **bold*bold>em***\n    - [x] ***bold>em*bold**\n    - [x] *em**em>bold***\n    - [x] ***bold>em**em*\n- [x] \\* or \\_ cannot be surrounded by spaces\n- [x] Strikethrough ~~example~~\n- [x] Escape characters (e.g. \\* or \\_ with \\\\\\* or \\\\\\_)\n- [x] \\[Link\\](url)\n    - [x] `href` attr\n- [ ] Raw URLs\n    - [ ] http://example.com\n    - [ ] https://example.com\n    - [ ] www.example.com\n    - [ ] example@fake.com\n    - [ ] mailto:example@fake.com\n- [x] Autolinks\n    - [ ] www.example.com\n    - [x] http://example.com\n    - [x] https://example.com\n    - [ ] example@fake.com\n    - [ ] mailto:example@fake.com\n- [ ] Reference-style Links\n- [x] Images\n    - [x] `src` attr\n- [x] Horizontal rules\n    - [x] With `---`\n    - [x] With `***`\n    - [x] With `___`\n- [x] Unordered lists\n- [x] Ordered lists\n    - [x] `start` attr\n- [x] Task lists\n- [x] Nested lists\n- [ ] One-line nested lists\n- [ ] Adding Elements in Lists\n- [x] Blockquotes\n- [x] Tables\n    - [ ] Align cols right/center\n    - [ ] Multiline cells\n- [ ] Subscript\n- [ ] Superscript\n- [ ] Emoji Shortcodes\n- [ ] Html tags (e.g. `<div>`, `<span>`, `<a>`, `<img>`, etc.)\n    - [x] Line breaks `<br>`, `<br/>`\n- [x] LaTex tags for blocks `\\[...\\]`, `$$...$$` and inline `\\(...\\)` or `$...$`\n\nIf you think that something is missing or doesn't work, please [make an issue](https://github.com/thetarnav/streaming-markdown/issues).\n\n🔴Ⓜ️⬇️\n","readmeFilename":"readme.md","_rev":"1-6400806f0c187c9be9ee9170c11f8c70"}