-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_markdown.html
More file actions
78 lines (63 loc) · 2.58 KB
/
debug_markdown.html
File metadata and controls
78 lines (63 loc) · 2.58 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html>
<head>
<title>Markdown Debug Test</title>
<script src="https://cdn.jsdelivr.net/npm/marked@12.0.0/lib/marked.umd.min.js"></script>
</head>
<body>
<h1>Markdown Debug Test</h1>
<div id="test-results"></div>
<script>
function testMarkdownRendering() {
const testCases = [
"# Heading 1",
"## Heading 2",
"### Heading 3",
"**Bold text**",
"*Italic text*",
"1. First item\n2. Second item",
"- Bullet item\n- Another bullet",
"Normal paragraph with **bold** and *italic* text."
];
const resultsDiv = document.getElementById('test-results');
let html = '<h2>Test Results:</h2>';
testCases.forEach((test, index) => {
html += `<h3>Test ${index + 1}: "${test.replace(/\n/g, '\\n')}"</h3>`;
try {
// Test with default marked.js
const defaultResult = marked.parse(test);
html += `<p><strong>Default marked.js:</strong> ${defaultResult}</p>`;
// Test with custom renderer
const renderer = new marked.Renderer();
renderer.heading = function(text, level) {
return `<h${level}>${text}</h${level}>\n`;
};
renderer.list = function(token, body) {
const ordered = token.ordered;
const tag = ordered ? 'ol' : 'ul';
return `<${tag}>\n${body}</${tag}>\n`;
};
renderer.listitem = function(text) {
return `<li>${text}</li>\n`;
};
renderer.strong = function(text) {
return `<strong>${text}</strong>`;
};
renderer.em = function(text) {
return `<em>${text}</em>`;
};
marked.setOptions({ renderer });
const customResult = marked.parse(test);
html += `<p><strong>Custom renderer:</strong> ${customResult}</p>`;
} catch (error) {
html += `<p><strong>Error:</strong> ${error.message}</p>`;
}
html += '<hr>';
});
resultsDiv.innerHTML = html;
}
// Run test when page loads
window.onload = testMarkdownRendering;
</script>
</body>
</html>