Files

25 lines
790 B
JavaScript
Raw Permalink Normal View History

// 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); };
}