6dfd01445d
Deploy PR-Helper / deploy (push) Successful in 30s
- 引入 marked.js(~40KB)作为专业 Markdown 解析引擎 - markdown.js 精简为 20 行薄封装,保留 renderMarkdown 兼容别名 - CSS 从 .md-* 选择器改为标准 HTML 标签选择器 - 支持 GFM(表格、任务列表、删除线)、代码块语法高亮 - 天然处理流式不完整 Markdown(未闭合代码块等)
25 lines
790 B
JavaScript
25 lines
790 B
JavaScript
// Shared Markdown renderer — thin wrapper around marked.js
|
|
const Markdown = {
|
|
render(text) {
|
|
if (!text) return '';
|
|
// marked handles all parsing: headers, code blocks, inline code,
|
|
// bold/italic, lists, blockquotes, links, GFM tables, etc.
|
|
// It gracefully handles incomplete/unclosed markdown during streaming.
|
|
return marked.parse(text);
|
|
},
|
|
};
|
|
|
|
// Configure marked
|
|
marked.setOptions({
|
|
gfm: true, // GitHub Flavored Markdown (tables, task lists, strikethrough)
|
|
breaks: true, // Single newlines become <br>
|
|
});
|
|
|
|
// Expose globally
|
|
window.Markdown = Markdown;
|
|
|
|
// Backward-compatible alias
|
|
if (typeof window.renderMarkdown !== 'function') {
|
|
window.renderMarkdown = function(text) { return Markdown.render(text); };
|
|
}
|