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-markdown-hint): cleanup the env passed into renderInline #397

Merged
merged 2 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions plugins/markdown/plugin-markdown-hint/src/node/cleanMarkdownEnv.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { MarkdownEnv } from 'vuepress/markdown'

export type ClearMarkdownEnv = MarkdownEnv & {
references?: unknown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是哪个插件提供的?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是 markdown-it 内部提供的。

}

export const cleanMarkdownEnv = (env: ClearMarkdownEnv): ClearMarkdownEnv => ({
filePath: env.filePath,
filePathRelative: env.filePathRelative,
base: env.base,
references: env.references,
})
8 changes: 5 additions & 3 deletions plugins/markdown/plugin-markdown-hint/src/node/hint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { PluginWithOptions } from 'markdown-it'
import type { MarkdownEnv } from 'vuepress/markdown'
import { resolveLocalePath } from 'vuepress/shared'
import { cleanMarkdownEnv } from './cleanMarkdownEnv.js'

import type { MarkdownHintPluginLocaleData } from './options.js'

Expand Down Expand Up @@ -44,7 +45,8 @@
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
info = options[localePath]?.[name]
} else {
info = md.renderInline(info, { ...env })
console.log('\nenv: ', env)

Check warning on line 48 in plugins/markdown/plugin-markdown-hint/src/node/hint.ts

View workflow job for this annotation

GitHub Actions / build-check

Unexpected console statement

Check warning on line 48 in plugins/markdown/plugin-markdown-hint/src/node/hint.ts

View workflow job for this annotation

GitHub Actions / build-check

Unexpected console statement

Check warning on line 48 in plugins/markdown/plugin-markdown-hint/src/node/hint.ts

View workflow job for this annotation

GitHub Actions / bundle-check

Unexpected console statement

Check warning on line 48 in plugins/markdown/plugin-markdown-hint/src/node/hint.ts

View workflow job for this annotation

GitHub Actions / bundle-check

Unexpected console statement
info = md.renderInline(info, cleanMarkdownEnv(env))
}

return `<div class="hint-container ${name}">\n<p class="hint-container-title">${info || name}</p>\n`
Expand All @@ -71,7 +73,7 @@
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
info = options[localePath]?.caution
} else {
info = md.renderInline(info, { ...env })
info = md.renderInline(info, cleanMarkdownEnv(env))
}

return `<div class="hint-container caution">\n<p class="hint-container-title">${
Expand Down Expand Up @@ -104,7 +106,7 @@
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
info = options[localePath]?.details
} else {
info = md.renderInline(info, { ...env })
info = md.renderInline(info, cleanMarkdownEnv(env))
}

return `<details class="hint-container details"><summary>${
Expand Down
Loading