@nuxtjs/mdc 0.1.0
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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/module.cjs +5 -0
- package/dist/module.d.mts +55 -0
- package/dist/module.d.ts +55 -0
- package/dist/module.json +5 -0
- package/dist/module.mjs +174 -0
- package/dist/runtime/components/MDC.vue +36 -0
- package/dist/runtime/components/MDCRenderer.vue +293 -0
- package/dist/runtime/components/MDCRenderer.vue.d.ts +92 -0
- package/dist/runtime/components/MDCSlot.vue +60 -0
- package/dist/runtime/components/MDCSlot.vue.d.ts +5 -0
- package/dist/runtime/components/prose/ProseA.vue +22 -0
- package/dist/runtime/components/prose/ProseBlockquote.vue +5 -0
- package/dist/runtime/components/prose/ProseCode.vue +3 -0
- package/dist/runtime/components/prose/ProseEm.vue +5 -0
- package/dist/runtime/components/prose/ProseH1.vue +20 -0
- package/dist/runtime/components/prose/ProseH2.vue +20 -0
- package/dist/runtime/components/prose/ProseH3.vue +20 -0
- package/dist/runtime/components/prose/ProseH4.vue +20 -0
- package/dist/runtime/components/prose/ProseH5.vue +20 -0
- package/dist/runtime/components/prose/ProseH6.vue +20 -0
- package/dist/runtime/components/prose/ProseHr.vue +3 -0
- package/dist/runtime/components/prose/ProseImg.vue +42 -0
- package/dist/runtime/components/prose/ProseLi.vue +3 -0
- package/dist/runtime/components/prose/ProseOl.vue +5 -0
- package/dist/runtime/components/prose/ProseP.vue +3 -0
- package/dist/runtime/components/prose/ProsePre.vue +39 -0
- package/dist/runtime/components/prose/ProseStrong.vue +5 -0
- package/dist/runtime/components/prose/ProseTable.vue +5 -0
- package/dist/runtime/components/prose/ProseTbody.vue +5 -0
- package/dist/runtime/components/prose/ProseTd.vue +5 -0
- package/dist/runtime/components/prose/ProseTh.vue +5 -0
- package/dist/runtime/components/prose/ProseThead.vue +5 -0
- package/dist/runtime/components/prose/ProseTr.vue +5 -0
- package/dist/runtime/components/prose/ProseUl.vue +5 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.mjs +3 -0
- package/dist/runtime/parser/compiler.d.ts +1 -0
- package/dist/runtime/parser/compiler.mjs +78 -0
- package/dist/runtime/parser/handlers/code.d.ts +5 -0
- package/dist/runtime/parser/handlers/code.mjs +31 -0
- package/dist/runtime/parser/handlers/containerComponent.d.ts +10 -0
- package/dist/runtime/parser/handlers/containerComponent.mjs +15 -0
- package/dist/runtime/parser/handlers/emphasis.d.ts +6 -0
- package/dist/runtime/parser/handlers/emphasis.mjs +10 -0
- package/dist/runtime/parser/handlers/html.d.ts +3 -0
- package/dist/runtime/parser/handlers/html.mjs +14 -0
- package/dist/runtime/parser/handlers/image.d.ts +6 -0
- package/dist/runtime/parser/handlers/image.mjs +13 -0
- package/dist/runtime/parser/handlers/index.d.ts +22 -0
- package/dist/runtime/parser/handlers/index.mjs +22 -0
- package/dist/runtime/parser/handlers/inlineCode.d.ts +6 -0
- package/dist/runtime/parser/handlers/inlineCode.mjs +12 -0
- package/dist/runtime/parser/handlers/link.d.ts +6 -0
- package/dist/runtime/parser/handlers/link.mjs +18 -0
- package/dist/runtime/parser/handlers/list.d.ts +4 -0
- package/dist/runtime/parser/handlers/list.mjs +26 -0
- package/dist/runtime/parser/handlers/paragraph.d.ts +4 -0
- package/dist/runtime/parser/handlers/paragraph.mjs +19 -0
- package/dist/runtime/parser/handlers/strong.d.ts +6 -0
- package/dist/runtime/parser/handlers/strong.mjs +10 -0
- package/dist/runtime/parser/handlers/utils.d.ts +19 -0
- package/dist/runtime/parser/handlers/utils.mjs +33 -0
- package/dist/runtime/parser/index.d.ts +11 -0
- package/dist/runtime/parser/index.mjs +60 -0
- package/dist/runtime/parser/options.d.ts +2 -0
- package/dist/runtime/parser/options.mjs +50 -0
- package/dist/runtime/parser/shiki.d.ts +8 -0
- package/dist/runtime/parser/shiki.mjs +55 -0
- package/dist/runtime/parser/toc.d.ts +3 -0
- package/dist/runtime/parser/toc.mjs +59 -0
- package/dist/runtime/parser/utils/html-tags-list.d.ts +2 -0
- package/dist/runtime/parser/utils/html-tags-list.mjs +119 -0
- package/dist/runtime/parser/utils/plugins.d.ts +3 -0
- package/dist/runtime/parser/utils/plugins.mjs +10 -0
- package/dist/runtime/parser/utils/props.d.ts +5 -0
- package/dist/runtime/parser/utils/props.mjs +33 -0
- package/dist/runtime/shiki/event-handler.d.ts +8 -0
- package/dist/runtime/shiki/event-handler.mjs +15 -0
- package/dist/runtime/shiki/highlighter.d.ts +25 -0
- package/dist/runtime/shiki/highlighter.mjs +298 -0
- package/dist/runtime/shiki/mdc.tmLanguage.d.ts +323 -0
- package/dist/runtime/shiki/mdc.tmLanguage.mjs +582 -0
- package/dist/runtime/shiki/types.d.ts +32 -0
- package/dist/runtime/shiki/types.mjs +0 -0
- package/dist/runtime/types/hast.d.ts +255 -0
- package/dist/runtime/types/hast.mjs +0 -0
- package/dist/runtime/types/index.d.ts +3 -0
- package/dist/runtime/types/index.mjs +3 -0
- package/dist/runtime/types/parser.d.ts +30 -0
- package/dist/runtime/types/parser.mjs +0 -0
- package/dist/runtime/types/toc.d.ts +12 -0
- package/dist/runtime/types/toc.mjs +0 -0
- package/dist/runtime/types/tree.d.ts +17 -0
- package/dist/runtime/types/tree.mjs +0 -0
- package/dist/runtime/types/unist.d.ts +107 -0
- package/dist/runtime/types/unist.mjs +0 -0
- package/dist/runtime/utils/ast.d.ts +6 -0
- package/dist/runtime/utils/ast.mjs +29 -0
- package/dist/runtime/utils/node.d.ts +37 -0
- package/dist/runtime/utils/node.mjs +75 -0
- package/dist/runtime/utils/slot.d.ts +3 -0
- package/dist/runtime/utils/slot.mjs +8 -0
- package/dist/runtime/utils/ssrSlot.d.ts +1 -0
- package/dist/runtime/utils/ssrSlot.mjs +8 -0
- package/dist/types.d.mts +7 -0
- package/dist/types.d.ts +7 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) NuxtLabs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Nuxt MDC
|
|
2
|
+
|
|
3
|
+
MDC supercharges regular Markdown to write documents interacting deeply with any Vue component.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Using Yarn
|
|
9
|
+
yarn add --dev @nuxtjs/mdc
|
|
10
|
+
# Using NPM
|
|
11
|
+
npm install --save-dev @nuxtjs/mdc
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then, add `@nuxtjs/mdc` to the modules section of your `nuxt.config.ts`
|
|
15
|
+
|
|
16
|
+
```ts [nuxt.config.ts]
|
|
17
|
+
export default defineNuxtConfig({
|
|
18
|
+
modules: ['@nuxtjs/mdc']
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
Parse MDC content in any environment:
|
|
25
|
+
|
|
26
|
+
```ts [parse-mdc.ts]
|
|
27
|
+
import { parseMarkdown } from '@nuxtjs/mdc/runtime'
|
|
28
|
+
|
|
29
|
+
async function main(mdc: string) {
|
|
30
|
+
const ast = await parseMarkdown(mdc)
|
|
31
|
+
|
|
32
|
+
// Do your magic with parsed AST tree
|
|
33
|
+
|
|
34
|
+
return ast
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Render MDC content with `<MDC>` component:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<template>
|
|
42
|
+
<MDC :value="md" tag="article" />
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script setup lang="ts">
|
|
46
|
+
const md = `
|
|
47
|
+
::alert
|
|
48
|
+
Hello MDC
|
|
49
|
+
::
|
|
50
|
+
`
|
|
51
|
+
</script>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## 💻 Development
|
|
56
|
+
|
|
57
|
+
- Clone repository
|
|
58
|
+
- Install dependencies using `pnpm install`
|
|
59
|
+
- Prepare using `pnpm dev:prepare`
|
|
60
|
+
- Try playground using `pnpm dev`
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
[MIT](./LICENSE) - Made with 💚
|
package/dist/module.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { Theme as Theme$1 } from 'shiki-es';
|
|
3
|
+
|
|
4
|
+
type Theme = Theme$1 | Record<string, Theme$1>;
|
|
5
|
+
|
|
6
|
+
interface UnistPlugin {
|
|
7
|
+
src?: string;
|
|
8
|
+
options?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
interface ModuleOptions {
|
|
11
|
+
remarkPlugins?: Record<string, UnistPlugin>;
|
|
12
|
+
rehypePlugins?: Record<string, UnistPlugin>;
|
|
13
|
+
highlight?: {
|
|
14
|
+
theme?: Theme;
|
|
15
|
+
highlighter?: string;
|
|
16
|
+
} | false;
|
|
17
|
+
headings?: {
|
|
18
|
+
anchorLinks?: {
|
|
19
|
+
[heading in 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6']?: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
components?: {
|
|
23
|
+
prose?: boolean;
|
|
24
|
+
map?: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
29
|
+
|
|
30
|
+
declare module '@nuxt/schema' {
|
|
31
|
+
interface PublicRuntimeConfig {
|
|
32
|
+
mdc: {
|
|
33
|
+
components: {
|
|
34
|
+
prose: boolean;
|
|
35
|
+
map: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
headings: ModuleOptions['headings'];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface ConfigSchema {
|
|
41
|
+
runtimeConfig: {
|
|
42
|
+
public?: {
|
|
43
|
+
mdc: {
|
|
44
|
+
components: {
|
|
45
|
+
prose: boolean;
|
|
46
|
+
map: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
headings: ModuleOptions['headings'];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { _default as default };
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
|
+
import { Theme as Theme$1 } from 'shiki-es';
|
|
3
|
+
|
|
4
|
+
type Theme = Theme$1 | Record<string, Theme$1>;
|
|
5
|
+
|
|
6
|
+
interface UnistPlugin {
|
|
7
|
+
src?: string;
|
|
8
|
+
options?: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
interface ModuleOptions {
|
|
11
|
+
remarkPlugins?: Record<string, UnistPlugin>;
|
|
12
|
+
rehypePlugins?: Record<string, UnistPlugin>;
|
|
13
|
+
highlight?: {
|
|
14
|
+
theme?: Theme;
|
|
15
|
+
highlighter?: string;
|
|
16
|
+
} | false;
|
|
17
|
+
headings?: {
|
|
18
|
+
anchorLinks?: {
|
|
19
|
+
[heading in 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6']?: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
components?: {
|
|
23
|
+
prose?: boolean;
|
|
24
|
+
map?: Record<string, string>;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
|
|
29
|
+
|
|
30
|
+
declare module '@nuxt/schema' {
|
|
31
|
+
interface PublicRuntimeConfig {
|
|
32
|
+
mdc: {
|
|
33
|
+
components: {
|
|
34
|
+
prose: boolean;
|
|
35
|
+
map: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
headings: ModuleOptions['headings'];
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
interface ConfigSchema {
|
|
41
|
+
runtimeConfig: {
|
|
42
|
+
public?: {
|
|
43
|
+
mdc: {
|
|
44
|
+
components: {
|
|
45
|
+
prose: boolean;
|
|
46
|
+
map: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
headings: ModuleOptions['headings'];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export { _default as default };
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { createResolver, extendViteConfig, defineNuxtModule, addTemplate, addComponent, addComponentsDir, addServerHandler } from '@nuxt/kit';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import { pascalCase } from 'scule';
|
|
4
|
+
import { defu } from 'defu';
|
|
5
|
+
import { RENDER_SLOT } from '@vue/compiler-core';
|
|
6
|
+
|
|
7
|
+
const mdcImportTemplate = async ({ nuxt, options }) => {
|
|
8
|
+
const resolver = createResolver(import.meta.url);
|
|
9
|
+
const imports = [];
|
|
10
|
+
const { imports: remarkImports, definitions: remarkDefinitions } = processUnistPlugins(options.remarkPlugins);
|
|
11
|
+
const { imports: rehypeImports, definitions: rehypeDefinitions } = processUnistPlugins(options.rehypePlugins);
|
|
12
|
+
let highlighter = "false";
|
|
13
|
+
if (options.highlight) {
|
|
14
|
+
highlighter = JSON.stringify(options.highlight);
|
|
15
|
+
if (options.highlight.highlighter) {
|
|
16
|
+
const path = await resolver.resolvePath(options.highlight.highlighter, { alias: nuxt.options.alias });
|
|
17
|
+
imports.push(`import syntaxHighlighter from '${path}'`);
|
|
18
|
+
highlighter = highlighter.replace(`"${options.highlight.highlighter}"`, "syntaxHighlighter");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return [
|
|
22
|
+
...remarkImports,
|
|
23
|
+
...rehypeImports,
|
|
24
|
+
...imports,
|
|
25
|
+
"",
|
|
26
|
+
"export const remarkPlugins = {",
|
|
27
|
+
...remarkDefinitions,
|
|
28
|
+
"}",
|
|
29
|
+
"",
|
|
30
|
+
"export const rehypePlugins = {",
|
|
31
|
+
...rehypeDefinitions,
|
|
32
|
+
"}",
|
|
33
|
+
"",
|
|
34
|
+
`export const highlight = ${highlighter}`
|
|
35
|
+
].join("\n");
|
|
36
|
+
};
|
|
37
|
+
function processUnistPlugins(plugins) {
|
|
38
|
+
const imports = [];
|
|
39
|
+
const definitions = [];
|
|
40
|
+
Object.entries(plugins).forEach(([name, plugin]) => {
|
|
41
|
+
imports.push(`import ${pascalCase(name)} from '${name}'`);
|
|
42
|
+
if (Object.keys(plugin).length) {
|
|
43
|
+
definitions.push(` '${name}': { instance: ${pascalCase(name)}, ...(${JSON.stringify(plugin)}) },`);
|
|
44
|
+
} else {
|
|
45
|
+
definitions.push(` '${name}': { instance: ${pascalCase(name)} },`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
return { imports, definitions };
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const registerMDCSlotTransformer = (resolver) => {
|
|
52
|
+
extendViteConfig((config) => {
|
|
53
|
+
const compilerOptions = config.vue.template.compilerOptions;
|
|
54
|
+
config.plugins = config.plugins || [];
|
|
55
|
+
config.plugins.push({
|
|
56
|
+
name: "mdc-render-slot-import",
|
|
57
|
+
enforce: "post",
|
|
58
|
+
transform(code) {
|
|
59
|
+
if (code.includes("_renderMDCSlot")) {
|
|
60
|
+
return {
|
|
61
|
+
code: `import { renderSlot as _renderMDCSlot } from '${resolver.resolve("./runtime/utils/slot")}';
|
|
62
|
+
${code}`,
|
|
63
|
+
map: { mappings: "" }
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
if (code.includes("_ssrRenderMDCSlot")) {
|
|
67
|
+
return {
|
|
68
|
+
code: `import { ssrRenderSlot as _ssrRenderMDCSlot } from '${resolver.resolve("./runtime/utils/ssrSlot")}';
|
|
69
|
+
${code}`,
|
|
70
|
+
map: { mappings: "" }
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
compilerOptions.nodeTransforms = [
|
|
76
|
+
function viteMDCSlot(node, context) {
|
|
77
|
+
if (node.tag === "MDCSlot") {
|
|
78
|
+
const transform = context.ssr ? context.nodeTransforms.find((nt) => nt.name === "ssrTransformSlotOutlet") : context.nodeTransforms.find((nt) => nt.name === "transformSlotOutlet");
|
|
79
|
+
return () => {
|
|
80
|
+
node.tag = "slot";
|
|
81
|
+
node.type = 1;
|
|
82
|
+
node.tagType = 2;
|
|
83
|
+
transform?.(node, context);
|
|
84
|
+
const codegen = context.ssr ? node.ssrCodegenNode : node.codegenNode;
|
|
85
|
+
codegen.callee = codegen.callee === RENDER_SLOT ? "_renderMDCSlot" : "_ssrRenderMDCSlot";
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (context.nodeTransforms[0].name !== "viteMDCSlot") {
|
|
89
|
+
const index = context.nodeTransforms.findIndex((f) => f.name === "viteMDCSlot");
|
|
90
|
+
const nt = context.nodeTransforms.splice(index, 1);
|
|
91
|
+
context.nodeTransforms.unshift(nt[0]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const module = defineNuxtModule({
|
|
99
|
+
meta: {
|
|
100
|
+
name: "@nuxtjs/mdc",
|
|
101
|
+
configKey: "mdc"
|
|
102
|
+
},
|
|
103
|
+
// Default configuration options of the Nuxt module
|
|
104
|
+
defaults: {
|
|
105
|
+
remarkPlugins: {},
|
|
106
|
+
rehypePlugins: {},
|
|
107
|
+
highlight: false,
|
|
108
|
+
headings: {
|
|
109
|
+
anchorLinks: {
|
|
110
|
+
h2: true,
|
|
111
|
+
h3: true,
|
|
112
|
+
h4: true
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
components: {
|
|
116
|
+
prose: true,
|
|
117
|
+
map: {}
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
async setup(options, nuxt) {
|
|
121
|
+
const resolver = createResolver(import.meta.url);
|
|
122
|
+
nuxt.options.runtimeConfig.public.mdc = defu(nuxt.options.runtimeConfig.public.mdc, {
|
|
123
|
+
components: {
|
|
124
|
+
prose: options.components.prose,
|
|
125
|
+
map: options.components.map
|
|
126
|
+
},
|
|
127
|
+
headings: options.headings
|
|
128
|
+
});
|
|
129
|
+
nuxt.hook("vite:extendConfig", (viteConfig) => {
|
|
130
|
+
viteConfig.optimizeDeps?.include?.push(
|
|
131
|
+
"is-buffer",
|
|
132
|
+
"debug",
|
|
133
|
+
"flat",
|
|
134
|
+
"node-emoji",
|
|
135
|
+
"extend",
|
|
136
|
+
"hast-util-raw"
|
|
137
|
+
);
|
|
138
|
+
});
|
|
139
|
+
nuxt.options.alias["#mdc-imports"] = addTemplate({ filename: "mdc-imports.mjs", getContents: mdcImportTemplate, options, write: true }).dst;
|
|
140
|
+
nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
|
|
141
|
+
nuxt.options.nitro.alias["#mdc-imports"] = nuxt.options.alias["#mdc-imports"];
|
|
142
|
+
addComponent({ name: "MDC", filePath: resolver.resolve("./runtime/components/MDC") });
|
|
143
|
+
addComponent({ name: "MDCRenderer", filePath: resolver.resolve("./runtime/components/MDCRenderer") });
|
|
144
|
+
addComponent({ name: "MDCSlot", filePath: resolver.resolve("./runtime/components/MDCSlot") });
|
|
145
|
+
if (options.components?.prose) {
|
|
146
|
+
addComponentsDir({
|
|
147
|
+
path: resolver.resolve("./runtime/components/prose"),
|
|
148
|
+
pathPrefix: false,
|
|
149
|
+
prefix: "",
|
|
150
|
+
global: true
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
|
|
154
|
+
const _layers = [...nuxt.options._layers].reverse();
|
|
155
|
+
for (const layer of _layers) {
|
|
156
|
+
const srcDir = layer.config.srcDir;
|
|
157
|
+
const globalComponents = resolver.resolve(srcDir, "components/mdc");
|
|
158
|
+
const dirStat = await fs.promises.stat(globalComponents).catch(() => null);
|
|
159
|
+
if (dirStat && dirStat.isDirectory()) {
|
|
160
|
+
nuxt.hook("components:dirs", (dirs) => {
|
|
161
|
+
dirs.unshift({
|
|
162
|
+
path: globalComponents,
|
|
163
|
+
global: true,
|
|
164
|
+
pathPrefix: false,
|
|
165
|
+
prefix: ""
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
registerMDCSlotTransformer(resolver);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
export { module as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<component :is="tag">
|
|
3
|
+
<slot
|
|
4
|
+
:data="data?.data"
|
|
5
|
+
:body="data?.body"
|
|
6
|
+
>
|
|
7
|
+
<MDCRenderer
|
|
8
|
+
:body="data?.body"
|
|
9
|
+
:data="data?.data"
|
|
10
|
+
/>
|
|
11
|
+
</slot>
|
|
12
|
+
</component>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<script setup lang="ts">
|
|
16
|
+
import { useAsyncData } from 'nuxt/app'
|
|
17
|
+
import { parseMarkdown } from '../parser'
|
|
18
|
+
import { watch } from 'vue'
|
|
19
|
+
|
|
20
|
+
const props = defineProps({
|
|
21
|
+
tag: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: 'div'
|
|
24
|
+
},
|
|
25
|
+
value: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: true
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const { data, refresh } = await useAsyncData(async () => await parseMarkdown(props.value, { highlight: {}}))
|
|
32
|
+
|
|
33
|
+
watch(() => props.value, () => {
|
|
34
|
+
refresh()
|
|
35
|
+
})
|
|
36
|
+
</script>
|