@nuxtjs/mdc 0.2.5 → 0.2.7

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/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
3
  "configKey": "mdc",
4
- "version": "0.2.5"
4
+ "version": "0.2.7"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createResolver, extendViteConfig, defineNuxtModule, addTemplate, addComponent, addImports, addComponentsDir, addServerHandler } from '@nuxt/kit';
1
+ import { createResolver, extendViteConfig, defineNuxtModule, addServerHandler, addTemplate, addComponent, addImports, addComponentsDir } from '@nuxt/kit';
2
2
  import fs from 'fs';
3
3
  import { pascalCase } from 'scule';
4
4
  import { defu } from 'defu';
@@ -132,6 +132,14 @@ const module = defineNuxtModule({
132
132
  "hast-util-raw"
133
133
  );
134
134
  });
135
+ if (options.highlight) {
136
+ nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
137
+ nuxt.options.nitro.experimental.wasm = true;
138
+ addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
139
+ options.rehypePlugins = options.rehypePlugins || {};
140
+ options.rehypePlugins.highlight = options.rehypePlugins.highlight || {};
141
+ options.rehypePlugins.highlight.src = options.rehypePlugins.highlight.src || resolver.resolve("./runtime/shiki/index");
142
+ }
135
143
  const { dst: templatePath } = addTemplate({ filename: "mdc-imports.mjs", getContents: mdcImportTemplate, options, write: true });
136
144
  nuxt.options.alias["#mdc-imports"] = process.env.NODE_ENV === "development" ? pathToFileURL(templatePath).href : templatePath;
137
145
  nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
@@ -148,11 +156,6 @@ const module = defineNuxtModule({
148
156
  global: true
149
157
  });
150
158
  }
151
- if (options.highlight) {
152
- nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
153
- nuxt.options.nitro.experimental.wasm = true;
154
- addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
155
- }
156
159
  extendViteConfig((config) => {
157
160
  config.optimizeDeps = config.optimizeDeps || {};
158
161
  config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
@@ -6,9 +6,10 @@
6
6
  :excerpt="data?.excerpt"
7
7
  >
8
8
  <MDCRenderer
9
+ v-if="body"
9
10
  :tag="tag"
10
11
  :class="props.class"
11
- :body="excerpt ? data?.excerpt : data?.body"
12
+ :body="body"
12
13
  :data="data?.data"
13
14
  />
14
15
  </slot>
@@ -65,6 +66,8 @@ const { data, refresh } = await useAsyncData(key.value, async () => {
65
66
  return await parseMarkdown(props.value, props.parserOptions)
66
67
  })
67
68
 
69
+ const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body)
70
+
68
71
  watch(() => props.value, () => {
69
72
  refresh()
70
73
  })
@@ -3,7 +3,7 @@ import { h, resolveComponent, Text, defineComponent, toRaw, computed } from "vue
3
3
  import destr from "destr";
4
4
  import { kebabCase, pascalCase } from "scule";
5
5
  import { find, html } from "property-information";
6
- import { useRoute, useRuntimeConfig } from "#app";
6
+ import { useRoute, useRuntimeConfig } from "#imports";
7
7
  import htmlTags from "../parser/utils/html-tags-list";
8
8
  const DEFAULT_SLOT = "default";
9
9
  const rxOn = /^@|^v-on:/;
@@ -1,14 +1,17 @@
1
1
  <template>
2
- <div>
3
- Rendering the <ProseCode>script</ProseCode> element is dangerous and is disabled by default. Consider implementing your own <ProseCode>ProseScript</ProseCode> element to have control over script rendering.
2
+ <div v-if="isDev">
3
+ Rendering the <code>script</code> element is dangerous and is disabled by default. Consider implementing your own <code>ProseScript</code> element to have control over script rendering.
4
4
  </div>
5
5
  </template>
6
6
 
7
7
  <script setup lang="ts">
8
+ import { computed } from 'vue'
9
+
8
10
  defineProps({
9
11
  src: {
10
12
  type: String,
11
13
  default: ''
12
14
  }
13
15
  })
16
+ const isDev = computed(() => process.dev)
14
17
  </script>
@@ -6,7 +6,6 @@ import { defu } from "defu";
6
6
  import { useProcessorPlugins } from "./utils/plugins.mjs";
7
7
  import { compileHast } from "./compiler.mjs";
8
8
  import { defaults } from "./options.mjs";
9
- import { rehypeShiki } from "../shiki/index.mjs";
10
9
  import { generateToc } from "./toc.mjs";
11
10
  import { nodeTextContent } from "../utils/node.mjs";
12
11
  let moduleOptions;
@@ -22,14 +21,14 @@ export const parseMarkdown = async (md, opts = {}) => {
22
21
  rehype: { plugins: moduleOptions?.rehypePlugins },
23
22
  highlight: moduleOptions?.highlight
24
23
  }, defaults);
24
+ if (options.rehype?.plugins?.highlight) {
25
+ options.rehype.plugins.highlight.options = options.highlight || {};
26
+ }
25
27
  const { content, data: frontmatter } = await parseFrontMatter(md);
26
28
  const processor = unified();
27
29
  processor.use(remarkParse);
28
30
  await useProcessorPlugins(processor, options.remark?.plugins);
29
31
  processor.use(remark2rehype, options.rehype?.options);
30
- if (options.highlight) {
31
- processor.use(rehypeShiki, options.highlight);
32
- }
33
32
  await useProcessorPlugins(processor, options.rehype?.plugins);
34
33
  processor.use(compileHast);
35
34
  const processedFile = await processor.process({ value: content, data: frontmatter });
@@ -1,3 +1,3 @@
1
- import { MDCNode, Toc, MDCElement, MDCRoot } from '../types';
1
+ import type { MDCNode, Toc, MDCElement, MDCRoot } from '../types';
2
2
  export declare function generateFlatToc(body: MDCNode, options: Toc): Toc;
3
3
  export declare function generateToc(body: MDCElement | MDCRoot, options: Toc): Toc;
@@ -1,3 +1,3 @@
1
- import { Processor } from 'remark-rehype/lib';
2
- import { MDCParseOptions } from '../../types';
1
+ import type { Processor } from 'remark-rehype/lib';
2
+ import type { MDCParseOptions } from '../../types';
3
3
  export declare const useProcessorPlugins: (processor: Processor, plugins?: Exclude<MDCParseOptions['rehype'] | MDCParseOptions['remark'], undefined>['plugins']) => Promise<void>;
@@ -55,21 +55,23 @@ export const useShikiHighlighter = createSingleton((opts) => {
55
55
  node.properties.class = (node.properties.class || "") + " highlight";
56
56
  }
57
57
  node.properties.line = line;
58
- if (node.children.length === 0) {
59
- node.children.push({
60
- type: "element",
61
- tagName: "span",
62
- properties: {
63
- emptyLinePlaceholder: true
64
- },
65
- children: [{ type: "text", value: "" }]
66
- });
67
- }
68
- const last = node.children.at(-1);
69
- if (last?.type === "element" && last.tagName === "span") {
70
- const text = last.children.at(-1);
71
- if (text?.type === "text")
72
- text.value += "\n";
58
+ if (code?.includes("\n")) {
59
+ if (node.children.length === 0) {
60
+ node.children.push({
61
+ type: "element",
62
+ tagName: "span",
63
+ properties: {
64
+ emptyLinePlaceholder: true
65
+ },
66
+ children: [{ type: "text", value: "" }]
67
+ });
68
+ }
69
+ const last = node.children.at(-1);
70
+ if (last?.type === "element" && last.tagName === "span") {
71
+ const text = last.children.at(-1);
72
+ if (text?.type === "text")
73
+ text.value += "\n";
74
+ }
73
75
  }
74
76
  }
75
77
  }
@@ -4,5 +4,5 @@ interface RehypeShikiOption {
4
4
  theme?: Theme;
5
5
  highlighter?: Highlighter;
6
6
  }
7
+ export default rehypeShiki;
7
8
  export declare function rehypeShiki(opts?: RehypeShikiOption): (tree: Root) => Promise<void>;
8
- export {};
@@ -29,6 +29,7 @@ const defaults = {
29
29
  return Promise.resolve({ tree: [{ type: "text", value: code }], className: "", style: "" });
30
30
  }
31
31
  };
32
+ export default rehypeShiki;
32
33
  export function rehypeShiki(opts = {}) {
33
34
  const options = { ...defaults, ...opts };
34
35
  return async (tree) => {
@@ -1,5 +1,5 @@
1
1
  import type { Options as RehypeOption } from 'remark-rehype';
2
- import { Theme, Highlighter } from '../shiki/types';
2
+ import type { Theme, Highlighter } from '../shiki/types';
3
3
  export interface RemarkPlugin {
4
4
  instance?: any;
5
5
  options?: Array<any> | Record<string, any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "remark-mdc": "^2.1.0",
59
59
  "remark-parse": "^10.0.2",
60
60
  "remark-rehype": "^10.1.0",
61
- "scule": "^1.0.0",
61
+ "scule": "^1.1.0",
62
62
  "shikiji": "^0.6.10",
63
63
  "ufo": "^1.3.1",
64
64
  "unified": "^11.0.3",
@@ -73,7 +73,7 @@
73
73
  "@nuxt/test-utils": "^3.8.0",
74
74
  "@nuxthq/ui": "^2.7.0",
75
75
  "@types/mdurl": "^1.0.4",
76
- "@types/node": "^20.8.8",
76
+ "@types/node": "^20.8.9",
77
77
  "changelogen": "^0.5.5",
78
78
  "eslint": "^8.52.0",
79
79
  "nuxt": "^3.8.0",