Skip to content

Commit

Permalink
fix(markdown): allow plugin with array type option (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximepvrt committed Jul 18, 2023
1 parent e5f385e commit 8469ecd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
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 @@ import { nodeTextContent } from './utils/node'
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

0 comments on commit 8469ecd

Please sign in to comment.