@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 1.88 kB
Source Map (JSON)
{"version":3,"file":"fenceState.mjs","names":[],"sources":["../../../src/Markdown/SyntaxMarkdown/fenceState.ts"],"sourcesContent":["/**\n * Walk `content` and return the language of the last *unclosed* fenced\n * code block, or `null` if every fence is closed (or there are none).\n *\n * Used by the smoother to decide whether to bypass its buffer for the\n * current input. CommonMark recognises an opening fence as a line whose\n * first non-space chars are 3+ backticks; we deliberately stay simple:\n * 3 literal backticks at line start, language word after. That covers\n * the markdown LLMs actually emit; tildes and indented fences fall back\n * to normal smoothing rather than getting clever.\n *\n * Linear scan over the input, ~10ns per char on V8. Called on every\n * smoothing tick during streaming so the simplicity matters.\n */\nexport const findOpenFenceLanguage = (content: string): string | null => {\n let inFence = false;\n let lang = '';\n let i = 0;\n const len = content.length;\n while (i < len) {\n const nl = content.indexOf('\\n', i);\n const lineEnd = nl === -1 ? len : nl;\n const line = content.slice(i, lineEnd);\n if (line.startsWith('```')) {\n if (inFence) {\n inFence = false;\n lang = '';\n } else {\n inFence = true;\n lang = line.slice(3).trim().toLowerCase();\n }\n }\n if (nl === -1) break;\n i = nl + 1;\n }\n return inFence ? lang : null;\n};\n"],"mappings":";;;;;;;;;;;;;;;AAcA,MAAa,yBAAyB,YAAmC;CACvE,IAAI,UAAU;CACd,IAAI,OAAO;CACX,IAAI,IAAI;CACR,MAAM,MAAM,QAAQ;AACpB,QAAO,IAAI,KAAK;EACd,MAAM,KAAK,QAAQ,QAAQ,MAAM,EAAE;EACnC,MAAM,UAAU,OAAO,KAAK,MAAM;EAClC,MAAM,OAAO,QAAQ,MAAM,GAAG,QAAQ;AACtC,MAAI,KAAK,WAAW,MAAM,CACxB,KAAI,SAAS;AACX,aAAU;AACV,UAAO;SACF;AACL,aAAU;AACV,UAAO,KAAK,MAAM,EAAE,CAAC,MAAM,CAAC,aAAa;;AAG7C,MAAI,OAAO,GAAI;AACf,MAAI,KAAK;;AAEX,QAAO,UAAU,OAAO"}