Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-md-power): incorrect empty tree node #179

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugins/plugin-md-power/src/node/features/fileTree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand Down