From 5059a2e670ef57c994d9078f8b15bbfff824d29d Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sat, 14 Sep 2024 22:58:35 +0800 Subject: [PATCH] fix(plugin-md-power): incorrect empty tree node --- .../src/node/features/fileTree/index.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-md-power/src/node/features/fileTree/index.ts b/plugins/plugin-md-power/src/node/features/fileTree/index.ts index 7508b1d55..818f307a8 100644 --- a/plugins/plugin-md-power/src/node/features/fileTree/index.ts +++ b/plugins/plugin-md-power/src/node/features/fileTree/index.ts @@ -18,6 +18,7 @@ export async function fileTreePlugin(app: App, md: Markdown) { const validate = (info: string): boolean => info.trim().startsWith(type) const render = (tokens: Token[], idx: number): string => { if (tokens[idx].nesting === 1) { + const hasRes: number[] = [] // level stack for ( let i = idx + 1; !(tokens[i].nesting === -1 @@ -28,6 +29,7 @@ export async function fileTreePlugin(app: App, md: Markdown) { if (token.type === 'list_item_open') { const result = resolveTreeNodeInfo(tokens, token, i) if (result) { + hasRes.push(token.level) const [info, inline] = result const { filename, type, expanded, empty } = info const icon = type === 'file' ? getFileIcon(filename) : folderIcon @@ -40,10 +42,15 @@ export async function fileTreePlugin(app: App, md: Markdown) { updateInlineToken(inline, info, `${classPrefix}${icon.name}`) addIcon(icon) } + else { + hasRes.push(-1) + } } else if (token.type === 'list_item_close') { - token.type = itemClose - token.tag = componentName + if (token.level === hasRes.pop()) { + token.type = itemClose + token.tag = componentName + } } } const info = tokens[idx].info.trim()