-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathcomark-parse.ts
More file actions
106 lines (80 loc) · 2.13 KB
/
Copy pathcomark-parse.ts
File metadata and controls
106 lines (80 loc) · 2.13 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { bench, run, barplot, group } from 'mitata'
import MarkdownIt from 'markdown-it'
import MarkdownExit from 'markdown-exit'
import { markdownItComark } from 'comark/plugins/syntax'
import { createMarkdownParser } from 'comark'
// Sample markdown content to test with
const sampleMarkdown = `---
title: Benchmark Test
---
# Hello World
This is a **markdown** document with *italic* text and [links](https://example.com).
## Features
- List item 1
- List item 2
- List item 3
### Code Block
\`\`\`javascript
const hello = 'world'
console.log(hello)
\`\`\`
### Tables
| Header 1 | Header 2 | Header 3 |
|----------|----------|----------|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
### MDC Components
::alert{type="info"}
This is an alert component
::
::card{title="My Card"}
Card content here
::
### More Content
1. Numbered list
2. Another item
3. Final item
> This is a blockquote with some **bold** text
~~Strikethrough text~~
`
// Initialize markdown-it with MDC plugin
const markdownIt = new MarkdownIt({
html: true,
linkify: true,
})
.enable(['table', 'strikethrough'])
.use(markdownItComark)
// Initialize markdown-exit with MDC plugin
const markdownExit = new MarkdownExit({
html: true,
linkify: true,
})
.enable(['table', 'strikethrough'])
.use(markdownItComark)
const comark = createMarkdownParser()
const comarkNoClose = createMarkdownParser({ autoClose: false })
const comarkStreaming = createMarkdownParser()
barplot(() => {
group('parse', () => {
// Benchmark: markdown-it parsing
bench('markdown-it parse', () => {
markdownIt.parse(sampleMarkdown, {})
})
// Benchmark: markdown-exit parsing
bench('markdown-exit parse', () => {
markdownExit.parse(sampleMarkdown, {})
})
bench('comark parse', async () => {
await comark(sampleMarkdown)
})
bench('comark parse no close', async () => {
await comarkNoClose(sampleMarkdown)
})
bench('comark parse streaming', async () => {
await comarkStreaming(sampleMarkdown, { streaming: true })
})
})
})
// Run all benchmarks
console.log('🏃 Running benchmarks...\n')
await run()