@nuxtjs/mdc 0.2.7 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +216 -22
- package/dist/module.json +1 -1
- package/dist/module.mjs +13 -10
- package/dist/runtime/components/MDCRenderer.vue.d.ts +2 -2
- package/dist/runtime/components/prose/ProsePre.vue +1 -3
- package/dist/runtime/shiki/highlighter.mjs +15 -6
- package/dist/runtime/shiki/index.mjs +2 -2
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +25 -25
package/README.md
CHANGED
|
@@ -44,48 +44,241 @@ export default defineNuxtConfig({
|
|
|
44
44
|
})
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
That's it! You can start writing and rendering markdown files ✨
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
## Rendering
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
|
|
53
|
-
|
|
54
|
-
async function main(mdc: string) {
|
|
55
|
-
const ast = await parseMarkdown(mdc)
|
|
51
|
+
`@nuxtjs/mdc` exposes three components to render markdown files.
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return ast
|
|
60
|
-
}
|
|
61
|
-
```
|
|
53
|
+
### `<MDC>`
|
|
62
54
|
|
|
63
|
-
|
|
55
|
+
Using `<MDC>`, you can parse and render markdown contents right inside your components/pages. This component takes raw markdown, parses it using the `parseMarkdown` function, and then renders it with `<MDCRenderer>`.
|
|
64
56
|
|
|
65
57
|
```html
|
|
58
|
+
<script setup lang="ts">
|
|
59
|
+
const md = `
|
|
60
|
+
::alert
|
|
61
|
+
Hello MDC
|
|
62
|
+
::
|
|
63
|
+
`
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
66
|
<template>
|
|
67
67
|
<MDC :value="md" tag="article" />
|
|
68
68
|
</template>
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Note that `::alert` will use the `components/global/Alert.vue` component.
|
|
72
|
+
|
|
73
|
+
### `<MDCRenderer>`
|
|
74
|
+
|
|
75
|
+
This component will take the result of [`parseMarkdown`](#parsing-markdown) function and render the contents. For example, this is an extended version of the sample code in the [Browser section](#browser) which uses `MDCRenderer` to render the parsed markdown.
|
|
69
76
|
|
|
77
|
+
```html [mdc-test.vue]
|
|
70
78
|
<script setup lang="ts">
|
|
71
|
-
|
|
79
|
+
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
|
|
80
|
+
|
|
81
|
+
const ast = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<MDCRenderer :body="ast.body" :data="ast.data" />
|
|
86
|
+
</template>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `<MDCSlot>`
|
|
90
|
+
|
|
91
|
+
This component is a replacement for Vue's `<slot/>` component, specifically designed for MDC. Using this component, you can render a component's children while removing one or multiple wrapping elements. In the below example, the Alert component receives text and its default slot (children). But if the component renders this slot using the normal `<slot/>`, it will render a `<p>` element around the text.
|
|
92
|
+
|
|
93
|
+
```md [markdown.md]
|
|
72
94
|
::alert
|
|
73
|
-
|
|
95
|
+
This is an Alert
|
|
74
96
|
::
|
|
75
|
-
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
```html [Alert.vue]
|
|
100
|
+
<template>
|
|
101
|
+
<div class="alert">
|
|
102
|
+
<!-- Slot will render <p> tag around the text -->
|
|
103
|
+
<slot />
|
|
104
|
+
</div>
|
|
105
|
+
</template>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
It is the default behavior of markdown to wrap every text inside a paragraph. MDC didn't come to break markdown behavior; instead, the goal of MDC is to make markdown powerful. In this example and all similar situations, you can use `<MDCSlot />` to remove unwanted wrappers.
|
|
109
|
+
|
|
110
|
+
```html [Alert.vue]
|
|
111
|
+
<template>
|
|
112
|
+
<div class="alert">
|
|
113
|
+
<!-- MDCSlot will only render the actual text without the wrapping <p> -->
|
|
114
|
+
<MDCSlot unwrap="p" />
|
|
115
|
+
</div>
|
|
116
|
+
</template>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Prose Components
|
|
120
|
+
|
|
121
|
+
Prose components are a list of components that will be rendered instead of regular HTML tags. For example, instead of rendering a `<p>` tag, `@nuxtjs/mdc` renders a `<ProseP>` component. This is useful when you want to add extra features to your markdown files. For example, you can add a `copy` button to your code blocks.
|
|
122
|
+
|
|
123
|
+
You can disable prose components by setting the `prose` option to `false` in `nuxt.config.ts`. Or extend the map of prose components to add your own components.
|
|
124
|
+
|
|
125
|
+
```ts [nuxt.config.ts]
|
|
126
|
+
export default defineNuxtConfig({
|
|
127
|
+
modules: ['@nuxtjs/mdc'],
|
|
128
|
+
mdc: {
|
|
129
|
+
components: {
|
|
130
|
+
prose: false, // Disable predefined prose components
|
|
131
|
+
map: {
|
|
132
|
+
p: 'MyCustomPComponent'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Here is the list of available prose components:
|
|
140
|
+
|
|
141
|
+
| Tag | Component | Source | Description |
|
|
142
|
+
| -- | -- | -- | -- |
|
|
143
|
+
| `p` | `<ProseP>` | [ProseP.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseP.vue) | Paragraph |
|
|
144
|
+
| `h1` | `<ProseH1>` | [ProseH1.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH1.vue) | Heading 1 |
|
|
145
|
+
| `h2` | `<ProseH2>` | [ProseH2.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH2.vue) | Heading 2 |
|
|
146
|
+
| `h3` | `<ProseH3>` | [ProseH3.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH3.vue) | Heading 3 |
|
|
147
|
+
| `h4` | `<ProseH4>` | [ProseH4.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH4.vue) | Heading 4 |
|
|
148
|
+
| `h5` | `<ProseH5>` | [ProseH5.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH5.vue) | Heading 5 |
|
|
149
|
+
| `h6` | `<ProseH6>` | [ProseH6.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseH6.vue) | Heading 6 |
|
|
150
|
+
| `ul` | `<ProseUl>` | [ProseUl.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseUl.vue) | Unordered List |
|
|
151
|
+
| `ol` | `<ProseOl>` | [ProseOl.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseOl.vue) | Ordered List |
|
|
152
|
+
| `li` | `<ProseLi>` | [ProseLi.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseLi.vue) | List Item |
|
|
153
|
+
| `blockquote` | `<ProseBlockquote>` | [ProseBlockquote.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseBlockquote.vue) | Blockquote |
|
|
154
|
+
| `hr` | `<ProseHr>` | [ProseHr.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseHr.vue) | Horizontal Rule |
|
|
155
|
+
| `pre` | `<ProsePre>` | [ProsePre.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProsePre.vue) | Preformatted Text |
|
|
156
|
+
| `code` | `<ProseCode>` | [ProseCode.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseCode.vue) | Code Block |
|
|
157
|
+
| `table` | `<ProseTable>` | [ProseTable.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseTable.vue) | Table |
|
|
158
|
+
| `thead` | `<ProseThead>` | [ProseThead.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseThead.vue) | Table Head |
|
|
159
|
+
| `tbody` | `<ProseTbody>` | [ProseTbody.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseTbody.vue) | Table Body |
|
|
160
|
+
| `tr` | `<ProseTr>` | [ProseTr.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseTr.vue) | Table Row |
|
|
161
|
+
| `th` | `<ProseTh>` | [ProseTh.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseTh.vue) | Table Header |
|
|
162
|
+
| `td` | `<ProseTd>` | [ProseTd.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseTd.vue) | Table Data |
|
|
163
|
+
| `a` | `<ProseA>` | [ProseA.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseA.vue) | Anchor Link |
|
|
164
|
+
| `img` | `<ProseImg>` | [ProseImg.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseImg.vue) | Image |
|
|
165
|
+
| `em` | `<ProseEm>` | [ProseEm.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseEm.vue) | Emphasis |
|
|
166
|
+
| `strong` | `<ProseStrong>` | [ProseStrong.vue](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/components/prose/ProseStrong.vue) | Strong |
|
|
167
|
+
|
|
168
|
+
## Parsing Markdown
|
|
169
|
+
|
|
170
|
+
Nuxt MDC exposes a handy helper to parse MDC files. You can import the `parseMarkdown` function from `@nuxtjs/mdc/runtime` and use it to parse markdown files written with MDC syntax.
|
|
171
|
+
|
|
172
|
+
### Node.js
|
|
173
|
+
|
|
174
|
+
```ts
|
|
175
|
+
// server/api/parse-mdc.ts
|
|
176
|
+
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
|
|
177
|
+
|
|
178
|
+
export default eventHandler(async () => {
|
|
179
|
+
const mdc = [
|
|
180
|
+
'# Hello MDC',
|
|
181
|
+
'',
|
|
182
|
+
'::alert',
|
|
183
|
+
'This is an Alert',
|
|
184
|
+
'::'
|
|
185
|
+
].join('\n')
|
|
186
|
+
|
|
187
|
+
const ast = await parseMarkdown(mdc)
|
|
188
|
+
|
|
189
|
+
return ast
|
|
190
|
+
})
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Browser
|
|
194
|
+
|
|
195
|
+
The `parseMarkdown` function is a universal helper, and you can also use it in the browser, for example inside a Vue component.
|
|
196
|
+
|
|
197
|
+
```vue
|
|
198
|
+
<script setup lang="ts">
|
|
199
|
+
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
|
|
200
|
+
|
|
201
|
+
const ast = await useAsyncData('markdown', () => parseMarkdown('::alert\nMissing markdown input\n::'))
|
|
76
202
|
</script>
|
|
203
|
+
|
|
204
|
+
<template>
|
|
205
|
+
<MDCRenderer :body="ast.body" :data="ast.data" />
|
|
206
|
+
</template>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Options
|
|
210
|
+
|
|
211
|
+
The `parseMarkdown` helper also accepts options as the second argument to control the parser's behavior. (Checkout [`MDCParseOptions` interface↗︎](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/types/parser.ts)).
|
|
212
|
+
|
|
213
|
+
| Name | Default | Description |
|
|
214
|
+
| -- | -- | -- |
|
|
215
|
+
| `remark.plugins` | `{}` | Register / Configure parser's remark plugins. |
|
|
216
|
+
| `rehype.options` | `{}` | Configure `remark-rehype` options. |
|
|
217
|
+
| `rehype.plugins` | `{}` | Register / Configure parser's rehype plugins. |
|
|
218
|
+
| `highlight` | `false` | Control whether code blocks should highlight or not. You can also provide a custom highlighter. |
|
|
219
|
+
| `toc.depth` | `2` | Maximum heading depth to include in the table of contents. |
|
|
220
|
+
| `toc.searchDepth` | `2` | Maximum depth of nested tags to search for heading. |
|
|
221
|
+
|
|
222
|
+
Checkout [`MDCParseOptions` types↗︎](https://github.com/nuxt-modules/mdc/blob/main/src/runtime/types/parser.ts).
|
|
223
|
+
|
|
224
|
+
## Configurations
|
|
225
|
+
|
|
226
|
+
You can configure the module by providing the `mdc` property in your `nuxt.config.js`; here are the default options:
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
import { defineNuxtConfig } from 'nuxt/config'
|
|
230
|
+
|
|
231
|
+
export default defineNuxtConfig({
|
|
232
|
+
modules: ['@nuxtjs/mdc'],
|
|
233
|
+
mdc: {
|
|
234
|
+
remarkPlugins: {
|
|
235
|
+
plugins: {
|
|
236
|
+
// Register/Configure remark plugin to extend the parser
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
rehypePlugins: {
|
|
240
|
+
options: {
|
|
241
|
+
// Configure rehype options to extend the parser
|
|
242
|
+
},
|
|
243
|
+
plugins: {
|
|
244
|
+
// Register/Configure rehype plugin to extend the parser
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
headings: {
|
|
248
|
+
anchorLinks: {
|
|
249
|
+
// Enable/Disable heading anchor links. { h1: true, h2: false }
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
highlight: false, // Control syntax highlighting
|
|
253
|
+
components: {
|
|
254
|
+
prose: false, // Add predefined map to render Prose Components instead of HTML tags, like p, ul, code
|
|
255
|
+
map: {
|
|
256
|
+
// This map will be used in `<MDCRenderer>` to control rendered components
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
})
|
|
77
261
|
```
|
|
78
262
|
|
|
79
|
-
|
|
263
|
+
Checkout [`ModuleOptions` types↗︎](https://github.com/nuxt-modules/mdc/blob/main/src/types.ts).
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
80
266
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
-
|
|
84
|
-
|
|
267
|
+
You can contribute to this module online with CodeSandbox:
|
|
268
|
+
|
|
269
|
+
[](https://codesandbox.io/s/github/nuxt-modules/mdc/tree/main/?fontsize=14&hidenavigation=1&theme=dark)
|
|
270
|
+
|
|
271
|
+
Or locally:
|
|
272
|
+
|
|
273
|
+
1. Clone this repository
|
|
274
|
+
2. Install dependencies using `pnpm install`
|
|
275
|
+
3. Start the development server using `pnpm dev`
|
|
85
276
|
|
|
86
277
|
## License
|
|
87
278
|
|
|
88
|
-
[MIT](
|
|
279
|
+
[MIT License](https://github.com/nuxt-modules/mdc/blob/main/LICENSE)
|
|
280
|
+
|
|
281
|
+
Copyright (c) NuxtLabs
|
|
89
282
|
|
|
90
283
|
<!-- Badges -->
|
|
91
284
|
[npm-version-src]: https://img.shields.io/npm/v/@nuxtjs/mdc/latest.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
@@ -97,5 +290,6 @@ Hello MDC
|
|
|
97
290
|
[license-src]: https://img.shields.io/github/license/nuxt-modules/mdc.svg?style=flat&colorA=18181B&colorB=28CF8D
|
|
98
291
|
[license-href]: https://github.com/nuxt-modules/mdc/blob/main/LICENSE
|
|
99
292
|
|
|
293
|
+
|
|
100
294
|
[nuxt-src]: https://img.shields.io/badge/Nuxt-18181B?logo=nuxt.js
|
|
101
295
|
[nuxt-href]: https://nuxt.com
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createResolver, extendViteConfig, defineNuxtModule, addServerHandler, addTemplate, addComponent, addImports, addComponentsDir } from '@nuxt/kit';
|
|
1
|
+
import { createResolver, extendViteConfig, defineNuxtModule, addServerHandler, addTemplate, addComponent, addImports, addServerImports, addComponentsDir } from '@nuxt/kit';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { pascalCase } from 'scule';
|
|
4
4
|
import { defu } from 'defu';
|
|
@@ -123,14 +123,15 @@ const module = defineNuxtModule({
|
|
|
123
123
|
} : {}
|
|
124
124
|
});
|
|
125
125
|
nuxt.hook("vite:extendConfig", (viteConfig) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
const optimizeList = ["is-buffer", "debug", "flat", "node-emoji", "extend", "hast-util-raw"];
|
|
127
|
+
viteConfig.optimizeDeps ||= {};
|
|
128
|
+
viteConfig.optimizeDeps.include ||= [];
|
|
129
|
+
const list = viteConfig.optimizeDeps.include;
|
|
130
|
+
optimizeList.forEach((pkg) => {
|
|
131
|
+
if (!list.includes(pkg)) {
|
|
132
|
+
list.push(pkg);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
134
135
|
});
|
|
135
136
|
if (options.highlight) {
|
|
136
137
|
nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
|
|
@@ -138,7 +139,7 @@ const module = defineNuxtModule({
|
|
|
138
139
|
addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
|
|
139
140
|
options.rehypePlugins = options.rehypePlugins || {};
|
|
140
141
|
options.rehypePlugins.highlight = options.rehypePlugins.highlight || {};
|
|
141
|
-
options.rehypePlugins.highlight.src = options.rehypePlugins.highlight.src || resolver.
|
|
142
|
+
options.rehypePlugins.highlight.src = options.rehypePlugins.highlight.src || await resolver.resolvePath("./runtime/shiki/index");
|
|
142
143
|
}
|
|
143
144
|
const { dst: templatePath } = addTemplate({ filename: "mdc-imports.mjs", getContents: mdcImportTemplate, options, write: true });
|
|
144
145
|
nuxt.options.alias["#mdc-imports"] = process.env.NODE_ENV === "development" ? pathToFileURL(templatePath).href : templatePath;
|
|
@@ -148,6 +149,8 @@ const module = defineNuxtModule({
|
|
|
148
149
|
addComponent({ name: "MDCRenderer", filePath: resolver.resolve("./runtime/components/MDCRenderer") });
|
|
149
150
|
addComponent({ name: "MDCSlot", filePath: resolver.resolve("./runtime/components/MDCSlot") });
|
|
150
151
|
addImports({ from: resolver.resolve("./runtime/utils/node"), name: "flatUnwrap", as: "unwrapSlot" });
|
|
152
|
+
addImports({ from: resolver.resolve("./runtime/parser"), name: "parseMarkdown", as: "parseMarkdown" });
|
|
153
|
+
addServerImports([{ from: resolver.resolve("./runtime/parser"), name: "parseMarkdown", as: "parseMarkdown" }]);
|
|
151
154
|
if (options.components?.prose) {
|
|
152
155
|
addComponentsDir({
|
|
153
156
|
path: resolver.resolve("./runtime/components/prose"),
|
|
@@ -76,9 +76,9 @@ declare const _default: DefineComponent<{
|
|
|
76
76
|
default: () => {};
|
|
77
77
|
};
|
|
78
78
|
}>>, {
|
|
79
|
-
tag: string | boolean;
|
|
80
79
|
data: Record<string, any>;
|
|
81
|
-
|
|
80
|
+
tag: string | boolean;
|
|
82
81
|
prose: boolean;
|
|
82
|
+
components: Record<string, string | DefineComponent<any, any, any>>;
|
|
83
83
|
}, {}>;
|
|
84
84
|
export default _default;
|
|
@@ -42,7 +42,15 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
42
42
|
await Promise.all(themeNames.map((theme3) => highlighter.loadTheme(theme3)));
|
|
43
43
|
}
|
|
44
44
|
if (lang && !highlighter.getLoadedLanguages().includes(lang)) {
|
|
45
|
-
|
|
45
|
+
try {
|
|
46
|
+
await highlighter.loadLanguage(lang);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
if (highlights.length) {
|
|
49
|
+
console.warn("[@nuxtjs/mdc] Defaulting to no language to be able to highlight lines:", error.message);
|
|
50
|
+
lang = "";
|
|
51
|
+
} else
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
const root = highlighter.codeToHast(code.trimEnd(), {
|
|
48
56
|
lang,
|
|
@@ -56,15 +64,16 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
56
64
|
}
|
|
57
65
|
node.properties.line = line;
|
|
58
66
|
if (code?.includes("\n")) {
|
|
59
|
-
if (node.children.length === 0) {
|
|
60
|
-
node.children
|
|
67
|
+
if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "element" && node.children[0].children.length === 1 && node.children[0].children[0].type === "text" && node.children[0].children[0].value === "") {
|
|
68
|
+
node.children = [{
|
|
61
69
|
type: "element",
|
|
62
70
|
tagName: "span",
|
|
63
71
|
properties: {
|
|
64
72
|
emptyLinePlaceholder: true
|
|
65
73
|
},
|
|
66
|
-
children: [{ type: "text", value: "" }]
|
|
67
|
-
}
|
|
74
|
+
children: [{ type: "text", value: "\n" }]
|
|
75
|
+
}];
|
|
76
|
+
return;
|
|
68
77
|
}
|
|
69
78
|
const last = node.children.at(-1);
|
|
70
79
|
if (last?.type === "element" && last.tagName === "span") {
|
|
@@ -109,7 +118,7 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
109
118
|
style: styles.join("")
|
|
110
119
|
};
|
|
111
120
|
} catch (error) {
|
|
112
|
-
console.warn("[@nuxtjs/mdc] Failed to highlight code block", error.message);
|
|
121
|
+
console.warn("[@nuxtjs/mdc] Failed to highlight code block:", error.message);
|
|
113
122
|
return {
|
|
114
123
|
tree: [{ type: "text", value: code }],
|
|
115
124
|
className: "",
|
|
@@ -7,7 +7,7 @@ const defaults = {
|
|
|
7
7
|
},
|
|
8
8
|
async highlighter(code, lang, theme, highlights) {
|
|
9
9
|
if (process.browser && window.sessionStorage.getItem("mdc-shiki-highlighter") === "browser") {
|
|
10
|
-
return import("./highlighter").then(({ useShikiHighlighter }) => {
|
|
10
|
+
return import("./highlighter.mjs").then(({ useShikiHighlighter }) => {
|
|
11
11
|
return useShikiHighlighter().getHighlightedAST(code, lang, theme, { highlights });
|
|
12
12
|
});
|
|
13
13
|
}
|
|
@@ -37,7 +37,7 @@ export function rehypeShiki(opts = {}) {
|
|
|
37
37
|
const styles = [];
|
|
38
38
|
visit(
|
|
39
39
|
tree,
|
|
40
|
-
(node) => ["pre", "code"].includes(node.tagName) && !!node.properties?.language,
|
|
40
|
+
(node) => ["pre", "code"].includes(node.tagName) && !!(node.properties?.language || node.properties?.highlights),
|
|
41
41
|
(node) => {
|
|
42
42
|
const _node = node;
|
|
43
43
|
const task = options.highlighter(
|
package/dist/types.d.mts
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.9",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"scripts": {
|
|
25
|
-
"prepack": "
|
|
26
|
-
"build": "
|
|
25
|
+
"prepack": "nuxt-module-build prepare; nuxt-module-build",
|
|
26
|
+
"build": "nuxt-module-build prepare; nuxt-module-build build",
|
|
27
27
|
"dev": "nuxi dev playground",
|
|
28
28
|
"dev:build": "nuxi build playground",
|
|
29
|
-
"dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
|
|
29
|
+
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
30
30
|
"dev:docs": "nuxi dev docs",
|
|
31
31
|
"release": "release-it",
|
|
32
32
|
"lint": "eslint .",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"test:watch": "vitest watch"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "^3.8.
|
|
38
|
-
"@types/hast": "^3.0.
|
|
39
|
-
"@types/mdast": "^4.0.
|
|
40
|
-
"@vue/compiler-core": "^3.3.
|
|
37
|
+
"@nuxt/kit": "^3.8.2",
|
|
38
|
+
"@types/hast": "^3.0.3",
|
|
39
|
+
"@types/mdast": "^4.0.3",
|
|
40
|
+
"@vue/compiler-core": "^3.3.11",
|
|
41
41
|
"consola": "^3.2.3",
|
|
42
42
|
"defu": "^6.1.3",
|
|
43
43
|
"destr": "^2.0.2",
|
|
@@ -47,41 +47,41 @@
|
|
|
47
47
|
"mdast-util-to-hast": "^13.0.2",
|
|
48
48
|
"micromark-util-sanitize-uri": "^2.0.0",
|
|
49
49
|
"ohash": "^1.1.3",
|
|
50
|
-
"property-information": "^6.
|
|
50
|
+
"property-information": "^6.4.0",
|
|
51
51
|
"rehype-external-links": "^3.0.0",
|
|
52
52
|
"rehype-raw": "^6.1.1",
|
|
53
53
|
"rehype-slug": "^6.0.0",
|
|
54
54
|
"rehype-sort-attribute-values": "^5.0.0",
|
|
55
55
|
"rehype-sort-attributes": "^5.0.0",
|
|
56
|
-
"remark-emoji": "^4.0.
|
|
56
|
+
"remark-emoji": "^4.0.1",
|
|
57
57
|
"remark-gfm": "^3.0.1",
|
|
58
58
|
"remark-mdc": "^2.1.0",
|
|
59
59
|
"remark-parse": "^10.0.2",
|
|
60
60
|
"remark-rehype": "^10.1.0",
|
|
61
|
-
"scule": "^1.1.
|
|
62
|
-
"shikiji": "^0.
|
|
63
|
-
"ufo": "^1.3.
|
|
64
|
-
"unified": "^11.0.
|
|
61
|
+
"scule": "^1.1.1",
|
|
62
|
+
"shikiji": "^0.9.3",
|
|
63
|
+
"ufo": "^1.3.2",
|
|
64
|
+
"unified": "^11.0.4",
|
|
65
65
|
"unist-builder": "^4.0.0",
|
|
66
66
|
"unist-util-visit": "^5.0.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@nuxt/devtools": "latest",
|
|
70
70
|
"@nuxt/eslint-config": "^0.2.0",
|
|
71
|
-
"@nuxt/module-builder": "^0.5.
|
|
72
|
-
"@nuxt/schema": "^3.8.
|
|
73
|
-
"@nuxt/test-utils": "^3.8.
|
|
74
|
-
"@
|
|
75
|
-
"@types/mdurl": "^1.0.
|
|
76
|
-
"@types/node": "^20.
|
|
71
|
+
"@nuxt/module-builder": "^0.5.4",
|
|
72
|
+
"@nuxt/schema": "^3.8.2",
|
|
73
|
+
"@nuxt/test-utils": "^3.8.1",
|
|
74
|
+
"@nuxt/ui": "^2.11.1",
|
|
75
|
+
"@types/mdurl": "^1.0.5",
|
|
76
|
+
"@types/node": "^20.10.4",
|
|
77
77
|
"changelogen": "^0.5.5",
|
|
78
|
-
"eslint": "^8.
|
|
79
|
-
"nuxt": "^3.8.
|
|
78
|
+
"eslint": "^8.55.0",
|
|
79
|
+
"nuxt": "^3.8.2",
|
|
80
80
|
"rehype": "^13.0.1",
|
|
81
|
-
"release-it": "^
|
|
82
|
-
"vitest": "^0.
|
|
81
|
+
"release-it": "^17.0.1",
|
|
82
|
+
"vitest": "^1.0.4"
|
|
83
83
|
},
|
|
84
|
-
"packageManager": "pnpm@8.
|
|
84
|
+
"packageManager": "pnpm@8.12.1",
|
|
85
85
|
"release-it": {
|
|
86
86
|
"git": {
|
|
87
87
|
"commitMessage": "chore(release): release v${version}"
|