Skip to content

Commit 34a9331

Browse files
committed
feat: add rollup-plugin-visualizer for bundle analysis; update dependencies and improve link parsing tests and fix the text following the link is missing.
1 parent 8466a8c commit 34a9331

File tree

13 files changed

+151
-47
lines changed

13 files changed

+151
-47
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
"real-time-preview",
3636
"markstream-vue"
3737
],
38+
"sideEffects": [
39+
"src/index.css"
40+
],
3841
"exports": {
3942
".": {
4043
"types": "./dist/index.d.ts",
@@ -136,6 +139,7 @@
136139
"postcss-cli": "^11.0.1",
137140
"rollup": "^3.29.5",
138141
"rollup-plugin-dts": "^5.3.1",
142+
"rollup-plugin-visualizer": "^6.0.5",
139143
"stream-markdown-parser": "workspace:^",
140144
"tailwindcss": "^3.4.18",
141145
"terser": "^5.44.1",

packages/markdown-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"markdown-it-sub": "^2.0.0",
6060
"markdown-it-sup": "^2.0.0",
6161
"markdown-it-task-checkbox": "^1.0.6",
62-
"markdown-it-ts": "0.0.2-beta.7"
62+
"markdown-it-ts": "0.0.2-beta.8"
6363
},
6464
"devDependencies": {
6565
"@types/node": "^22.19.1",

packages/markdown-parser/src/parser/inline-parsers/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@ export function parseInlineTokens(
520520
i++
521521
return
522522
}
523-
if (content.startsWith(')') && result[result.length - 1]?.type === 'link') {
524-
content = content.slice(1)
525-
}
526523

527524
// math 公式 $ 只出现一个并且在末尾,优化掉
528525
if (Array.from(content.matchAll(/\$/g)).length === 1 && content.endsWith('$')) {

packages/markdown-parser/src/plugins/fixLinkTokens.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export function applyFixLinkTokens(md: MarkdownIt) {
8383
function fixLinkToken(tokens: MarkdownToken[]): MarkdownToken[] {
8484
if (tokens.length < 4)
8585
return tokens
86+
8687
for (let i = 0; i <= tokens.length - 1; i++) {
8788
if (i < 0) {
8889
i = 0
@@ -281,11 +282,11 @@ function fixLinkToken(tokens: MarkdownToken[]): MarkdownToken[] {
281282
if (m === -1) {
282283
href += (tokens[i + 1]?.content?.slice(0, m) || '')
283284
tokens[i + 1].content = ''
285+
count += 1
284286
}
285287
else {
286288
loading = false
287289
}
288-
count += 1
289290
}
290291
else if (tokens[i + 1].type === 'text' && tokens[i + 1]?.content?.startsWith('](')) {
291292
count += 1

playground/src/pages/index.vue

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ function goToTest() {
3434
})
3535
}
3636
37-
function goToMermaidExportDemo() {
38-
// Prefer router navigation, fallback to full redirect if it fails.
39-
router.push('/mermaid-export-demo').catch(() => {
40-
window.location.href = '/mermaid-export-demo'
41-
})
42-
}
43-
4437
// Keep persisted values within reasonable bounds on hydration.
4538
watchEffect(() => {
4639
const parsedDelay = Number(streamDelay.value)
@@ -513,15 +506,6 @@ onBeforeUnmount(() => {
513506
<Icon icon="carbon:rocket" class="w-4 h-4" />
514507
<span>Test</span>
515508
</button>
516-
<!-- Mermaid export demo -->
517-
<button
518-
class="ml-2 test-page-btn flex items-center gap-2 px-3 py-1.5 bg-green-600 hover:bg-green-500 text-white text-sm font-medium rounded-lg transition-all duration-200 shadow-md focus:outline-none focus:ring-2 focus:ring-green-500/50"
519-
title="Mermaid export demo"
520-
@click="goToMermaidExportDemo"
521-
>
522-
<Icon icon="carbon:download" class="w-4 h-4" />
523-
<span>Mermaid Export</span>
524-
</button>
525509
</div>
526510
</div>
527511
</div>

pnpm-lock.yaml

Lines changed: 23 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/exports.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { App, Component, Plugin } from 'vue'
22
import type { LanguageIconResolver } from './utils/languageIcon'
33
import { setDefaultMathOptions } from 'stream-markdown-parser'
4+
import { defineAsyncComponent } from 'vue'
45
import AdmonitionNode from './components/AdmonitionNode'
56

67
import BlockquoteNode from './components/BlockquoteNode'
78
import CheckboxNode from './components/CheckboxNode'
8-
import CodeBlockNode from './components/CodeBlockNode'
99
import DefinitionListNode from './components/DefinitionListNode'
1010
import EmojiNode from './components/EmojiNode'
1111
import FootnoteNode from './components/FootnoteNode'
@@ -20,8 +20,6 @@ import LinkNode from './components/LinkNode'
2020
import ListItemNode from './components/ListItemNode'
2121
import ListNode from './components/ListNode'
2222
import MarkdownCodeBlockNode from './components/MarkdownCodeBlockNode'
23-
import MathBlockNode from './components/MathBlockNode'
24-
import MathInlineNode from './components/MathInlineNode'
2523
import MermaidBlockNode from './components/MermaidBlockNode'
2624
import MarkdownRender from './components/NodeRenderer'
2725
import ParagraphNode from './components/ParagraphNode'
@@ -38,9 +36,14 @@ import { setDefaultI18nMap } from './composables/useSafeI18n'
3836
import { setLanguageIconResolver } from './utils/languageIcon'
3937
import { clearGlobalCustomComponents, getCustomNodeComponents, removeCustomComponents, setCustomComponents } from './utils/nodeComponents'
4038
import './index.css'
39+
// Re-add top-level worker imports so builds emit worker bundles into `dist/`
4140
import './workers/katexRenderer.worker?worker'
4241
import './workers/mermaidParser.worker?worker'
4342

43+
const CodeBlockNode = defineAsyncComponent(() => import('./components/CodeBlockNode'))
44+
const MathBlockNode = defineAsyncComponent(() => import('./components/MathBlockNode'))
45+
const MathInlineNode = defineAsyncComponent(() => import('./components/MathInlineNode'))
46+
4447
// Export centralized props interfaces so they appear in package d.ts
4548
export * from './utils'
4649

test/__snapshots__/e2e.markdown.test.ts.snap

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,20 @@ exports[`e2e markdown parsing (fixtures) > parses fixture escaped-brackets.md >
5757
{
5858
"children": [
5959
"text",
60+
"text_special",
61+
"text",
62+
"text_special",
6063
],
61-
"firstText": "A line with an escaped bracket: [not a link]",
64+
"firstText": "A line with an escaped bracket: ",
6265
"type": "paragraph",
6366
},
6467
{
6568
"children": [
6669
"text",
70+
"text_special",
71+
"text",
6772
],
68-
"firstText": "And a literal backslash and more text.",
73+
"firstText": "And a literal backslash ",
6974
"type": "paragraph",
7075
},
7176
]
@@ -178,8 +183,12 @@ exports[`e2e markdown parsing (fixtures) > parses fixture math.md > math.md 1`]
178183
{
179184
"children": [
180185
"text",
186+
"text_special",
187+
"text",
188+
"text_special",
189+
"text",
181190
],
182-
"firstText": "Inline math (alpha + beta) and another form (x_i).",
191+
"firstText": "Inline math (",
183192
"type": "paragraph",
184193
},
185194
{

test/e2e.markdown.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ describe('e2e markdown parsing (fixtures)', () => {
9191
}
9292
else {
9393
// generic: record if has children
94-
out.children = (n as any).children ? (n as any).children.map(item => item.type) : undefined
94+
out.children = (n as any).children ? (n as any).children.map((item: any) => item.type) : undefined
9595
}
9696
// Tolerate environment differences for escaped backslash in a specific fixture
9797
if (f === 'escaped-brackets.md' && typeof out.firstText === 'string') {

test/e2e/__snapshots__/node-renderer.e2e.test.ts.snap

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,21 @@ exports[`markdownRender node e2e coverage > renders heading node 1`] = `
310310
</div>"
311311
`;
312312
313+
exports[`markdownRender node e2e coverage > renders heading node 2`] = `
314+
"<div data-v-8dfe8a80="" class="markdown-renderer">
315+
<div data-v-8dfe8a80="" class="node-spacer" style="height: 0px;" aria-hidden="true"></div>
316+
<div data-v-8dfe8a80="" class="node-slot" data-node-index="0" data-node-type="heading">
317+
<div data-v-8dfe8a80="" class="node-content">
318+
<!-- Skip wrapping code_block nodes in transitions to avoid touching Monaco editor internals -->
319+
<transition-stub data-v-8dfe8a80="" name="typewriter" appear="true" persisted="false" css="true">
320+
<h1 data-v-9f883140="" data-v-8dfe8a80="" class="heading-node heading-1" dir="auto" typewriter="true" is-dark="false"><span data-v-a84b8095="" data-v-9f883140="" class="whitespace-pre-wrap break-words text-node" index-key="markdown-renderer-0-0">Heading Node Title</span></h1>
321+
</transition-stub>
322+
</div>
323+
</div>
324+
<div data-v-8dfe8a80="" class="node-spacer" style="height: 0px;" aria-hidden="true"></div>
325+
</div>"
326+
`;
327+
313328
exports[`markdownRender node e2e coverage > renders highlight node 1`] = `
314329
"<div data-v-8dfe8a80="" class="markdown-renderer">
315330
<div data-v-8dfe8a80="" class="node-spacer" style="height: 0px;" aria-hidden="true"></div>

0 commit comments

Comments
 (0)