diff --git a/src/module.ts b/src/module.ts index 4a3d5ac..f6c1ca5 100644 --- a/src/module.ts +++ b/src/module.ts @@ -34,8 +34,21 @@ export default defineNuxtModule({ }, // Default configuration options of the Nuxt module defaults: { - remarkPlugins: {}, - rehypePlugins: {}, + remarkPlugins: { + 'remark-mdc': {}, + 'remark-emoji': {}, + 'remark-gfm': {} + }, + rehypePlugins: { + 'rehype-external-links': {}, + 'rehype-sort-attribute-values': {}, + 'rehype-sort-attributes': {}, + 'rehype-raw': { + options: { + passThrough: ['element'] + } + } + }, highlight: false, headings: { anchorLinks: { diff --git a/src/runtime/parser/options.ts b/src/runtime/parser/options.ts index 05bcb3e..d8daa54 100644 --- a/src/runtime/parser/options.ts +++ b/src/runtime/parser/options.ts @@ -1,49 +1,16 @@ -import remarkEmoji from 'remark-emoji' -import remarkGFM from 'remark-gfm' -import remarkMDC from 'remark-mdc' -import rehypeExternalLinks from 'rehype-external-links' -import rehypeSortAttributeValues from 'rehype-sort-attribute-values' -import rehypeSortAttributes from 'rehype-sort-attributes' -import rehypeRaw from 'rehype-raw' import type { MDCParseOptions } from '@nuxtjs/mdc' import handlers from './handlers' export const defaults: MDCParseOptions = { remark: { - plugins: { - 'remark-mdc': { - instance: remarkMDC - }, - 'remark-emoji': { - instance: remarkEmoji - }, - 'remark-gfm': { - instance: remarkGFM - } - } + plugins: {} }, rehype: { options: { handlers, allowDangerousHtml: true }, - plugins: { - 'rehype-external-links': { - instance: rehypeExternalLinks - }, - 'rehype-sort-attribute-values': { - instance: rehypeSortAttributeValues - }, - 'rehype-sort-attributes': { - instance: rehypeSortAttributes - }, - 'rehype-raw': { - instance: rehypeRaw, - options: { - passThrough: ['element'] - } - } - } + plugins: {} }, highlight: false, toc: { diff --git a/src/templates/mdc-imports.ts b/src/templates/mdc-imports.ts index d00cca6..ade84be 100644 --- a/src/templates/mdc-imports.ts +++ b/src/templates/mdc-imports.ts @@ -31,11 +31,15 @@ function processUnistPlugins(plugins: Record) { const definitions: string[] = [] Object.entries(plugins).forEach(([name, plugin]) => { const instanceName = `_${pascalCase(name).replace(/\W/g, '')}` - imports.push(`import ${instanceName} from '${plugin.src || name}'`) - if (Object.keys(plugin).length) { - definitions.push(` '${name}': { instance: ${instanceName}, options: ${JSON.stringify(plugin.options || plugin)} },`) + if (plugin) { + imports.push(`import ${instanceName} from '${plugin.src || name}'`) + if (Object.keys(plugin).length) { + definitions.push(` '${name}': { instance: ${instanceName}, options: ${JSON.stringify(plugin.options || plugin)} },`) + } else { + definitions.push(` '${name}': { instance: ${instanceName} },`) + } } else { - definitions.push(` '${name}': { instance: ${instanceName} },`) + definitions.push(` '${name}': false,`) } }) diff --git a/src/types/module.ts b/src/types/module.ts index f756a56..32c6f4e 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -10,11 +10,11 @@ export interface ModuleOptions { /** * A map of remark plugins to be used for processing markdown. */ - remarkPlugins?: Record + remarkPlugins?: Record /** * A map of remark plugins to be used for processing markdown. */ - rehypePlugins?: Record + rehypePlugins?: Record highlight?: { /** diff --git a/test/utils/parser.ts b/test/utils/parser.ts index 3a9ebc4..35cbd16 100644 --- a/test/utils/parser.ts +++ b/test/utils/parser.ts @@ -1,14 +1,43 @@ import { vi } from 'vitest' import { createWasmOnigEngine } from 'shiki/engine/oniguruma' -import { parseMarkdown as _parseMarkDown } from '../../src/runtime/parser' -import type { MDCParseOptions } from '../../src/types' -import { rehypeHighlight } from '../../src/runtime/highlighter/rehype-nuxt' +import remarkGFM from 'remark-gfm' +import remarkMDC from 'remark-mdc' +import rehypeExternalLinks from 'rehype-external-links' +import rehypeSortAttributeValues from 'rehype-sort-attribute-values' +import rehypeSortAttributes from 'rehype-sort-attributes' +import rehypeRaw from 'rehype-raw' import { createShikiHighlighter } from '../../src/runtime/highlighter/shiki' +import { rehypeHighlight } from '../../src/runtime/highlighter/rehype-nuxt' +import type { MDCParseOptions } from '../../src/types' +import { parseMarkdown as _parseMarkDown } from '../../src/runtime/parser' vi.mock('#mdc-imports', () => { return { - remarkPlugins: {}, - rehypePlugins: {}, + remarkPlugins: { + 'remark-mdc': { + instance: remarkMDC + }, + 'remark-gfm': { + instance: remarkGFM + } + }, + rehypePlugins: { + 'rehype-external-links': { + instance: rehypeExternalLinks + }, + 'rehype-sort-attribute-values': { + instance: rehypeSortAttributeValues + }, + 'rehype-sort-attributes': { + instance: rehypeSortAttributes + }, + 'rehype-raw': { + instance: rehypeRaw, + options: { + passThrough: ['element'] + } + } + }, highlight: {} } })