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(markdown): allow plugin with array type option #2114

Merged
merged 5 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"lint-staged": "^13.2.3",
"nuxt": "3.6.3",
"rehype-figure": "^1.0.1",
"rehype-wrap-all": "^1.1.0",
"release-it": "^16.1.2",
"remark-oembed": "^1.2.2",
"vitest": "^0.33.0",
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions src/runtime/markdown-parser/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
const usePlugins = (plugins: Record<string, false | MarkdownPlugin>, stream: Processor) => {
for (const plugin of Object.values(plugins)) {
if (plugin) {
const { instance, ...options } = plugin
stream.use(instance, options)
const { instance, options, ...deprecatedOptions } = plugin
if (Object.keys(deprecatedOptions).length) {
console.warn('[Markdown] Deprecated syntax. Please use `options` key in order to pass option to remark/rehype plugins.')

Check warning on line 17 in src/runtime/markdown-parser/content.ts

View workflow job for this annotation

GitHub Actions / ci

Unexpected console statement
}
stream.use(instance, options || deprecatedOptions)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/transformers/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function importPlugins (plugins: Record<string, false | MarkdownPlugin> =
if (plugin) {
resolvedPlugins[name] = {
instance: plugin.instance || await import(/* @vite-ignore */ name).then(m => m.default || m),
...plugin
options: plugin
}
} else {
resolvedPlugins[name] = false
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/basic/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default defineNuxtConfig({
},
// Array syntax can be used to add plugins
rehypePlugins: [
'rehype-figure'
'rehype-figure',
['rehype-wrap-all', [{ selector: 'ol', wrapper: 'p' }, { selector: 'ul', wrapper: 'p' }]]
]
}
}
Expand Down