-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown-handler.js
More file actions
31 lines (28 loc) · 871 Bytes
/
markdown-handler.js
File metadata and controls
31 lines (28 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
export function convertMarkdownToHtml(markdown) {
// Ensure the marked library is available
if (typeof window.marked === 'undefined') {
console.error('Marked library is not properly loaded');
return markdown;
}
try {
// Set options only once if not already set
if (!window.markedOptionsSet) {
window.marked.setOptions({
gfm: true,
breaks: true,
sanitize: true
});
window.markedOptionsSet = true;
}
// Use the correct API based on what's available
return typeof window.marked.parse === 'function'
? window.marked.parse(markdown)
: window.marked(markdown);
} catch (error) {
console.error('Error converting markdown:', error);
return markdown;
}
}
export function updateOutputWithMarkdown(element, markdown) {
element.innerHTML = convertMarkdownToHtml(markdown);
}