0.0.7 • Published 4 months ago

markdown-streamx v0.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
4 months ago

markdown-streamx

!IMPORTANT Just a toy

markdown-streamx does not check whether the input is a complete and correct,so you must ensure that the markdown you enter is normal and there is no strange usage.

Tranform a stream of Markdown into HTML

Live Demo

Usage

createMarkdownStreamRender

import { createMarkdownStreamRender } from "markdown-streamx";

async function procressFoo() {
  // for example, a LLM markdown stream
  // const response = await fetch("/api/chat", {
  //   method: "POST",
  //   body: JSON.stringify({
  //     question: "使用vue3写一个 v-for demo",
  //   }),
  // });
  // const markdownStream = response.body;

  const markdownStream = createStream(md);
  const container = document.createElement("div");
  document.body.appendChild(container);
  await createMarkdownStreamRender(markdownStream, container);
}

processMarkdownStreamChunk

const markdownStream = createStream(md);

processMarkdownStreamChunk(stream, (ast) => {
  console.log(ast);
});

!IMPORTANT the ast in processMarkdownStreamChunk above

// md: aaa*\`bar\` foo \`zzz\`*bbb
// chunkSize=10: ['aaa*`bar` ', 'foo `zzz`*', 'bbb']

processMarkdownStreamChunk(stream, (ast) => {
  console.log(ast);
});
// "{"operate":"blockOpen","type":"paragraphOpen","chunk":"paragraphOpen"}",
// "{"operate":"append","type":"text","chunk":"aaa"}",
// "{"operate":"append","type":"italicOpen","chunk":"*"}",
// "{"operate":"append","type":"inlineCodeOpen","chunk":"\`"}",
// "{"operate":"append","type":"inlineCode","chunk":"bar"}",
// "{"operate":"append","type":"inlineCodeClose","chunk":"\`"}",
// "{"operate":"append","type":"italic","chunk":" "}",
// "{"operate":"append","type":"italic","chunk":"foo "}",
// "{"operate":"append","type":"inlineCodeOpen","chunk":"\`"}",
// "{"operate":"append","type":"inlineCode","chunk":"zzz"}",
// "{"operate":"append","type":"inlineCodeClose","chunk":"\`"}",
// "{"operate":"append","type":"italicClose","chunk":"*"}",
// "{"operate":"append","type":"text","chunk":"bbb"}",
0.0.7

4 months ago

0.0.6

4 months ago

0.0.5

4 months ago

0.0.4

4 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago