@nuxtjs/mdc 0.2.3 → 0.2.5

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.3"
4
+ "version": "0.2.5"
5
5
  }
package/dist/module.mjs CHANGED
@@ -38,9 +38,9 @@ function processUnistPlugins(plugins) {
38
38
  const imports = [];
39
39
  const definitions = [];
40
40
  Object.entries(plugins).forEach(([name, plugin]) => {
41
- imports.push(`import ${pascalCase(name)} from '${name}'`);
41
+ imports.push(`import ${pascalCase(name)} from '${plugin.src || name}'`);
42
42
  if (Object.keys(plugin).length) {
43
- definitions.push(` '${name}': { instance: ${pascalCase(name)}, options: ${JSON.stringify(plugin)} },`);
43
+ definitions.push(` '${name}': { instance: ${pascalCase(name)}, options: ${JSON.stringify(plugin.options || plugin)} },`);
44
44
  } else {
45
45
  definitions.push(` '${name}': { instance: ${pascalCase(name)} },`);
46
46
  }
@@ -19,11 +19,11 @@ import { hash } from 'ohash'
19
19
  import { useAsyncData } from 'nuxt/app'
20
20
  import { parseMarkdown } from '../parser'
21
21
  import { watch, computed, type PropType } from 'vue'
22
- import { MDCParseOptions } from '../types'
22
+ import type { MDCParseOptions } from '../types'
23
23
 
24
24
  const props = defineProps({
25
25
  tag: {
26
- type: String,
26
+ type: [String, Boolean],
27
27
  default: 'div'
28
28
  },
29
29
  /**
@@ -68,4 +68,4 @@ const { data, refresh } = await useAsyncData(key.value, async () => {
68
68
  watch(() => props.value, () => {
69
69
  refresh()
70
70
  })
71
- </script>
71
+ </script>
@@ -10,7 +10,7 @@ const rxOn = /^@|^v-on:/;
10
10
  const rxBind = /^:|^v-bind:/;
11
11
  const rxModel = /^v-model/;
12
12
  const nativeInputs = ["select", "textarea", "input"];
13
- const proseComponentMap = Object.fromEntries(["p", "a", "blockquote", "code", "pre", "code", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "ul", "ol", "li", "strong", "table", "thead", "tbody", "td", "th", "tr"].map((t) => [t, `prose-${t}`]));
13
+ const proseComponentMap = Object.fromEntries(["p", "a", "blockquote", "code", "pre", "code", "em", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "ul", "ol", "li", "strong", "table", "thead", "tbody", "td", "th", "tr", "script"].map((t) => [t, `prose-${t}`]));
14
14
  export default defineComponent({
15
15
  name: "MDCRenderer",
16
16
  props: {
@@ -80,9 +80,6 @@ function renderNode(node, h2, documentMeta, parentScope = {}) {
80
80
  if (node.type === "text") {
81
81
  return h2(Text, node.value);
82
82
  }
83
- if (node.tag === "script") {
84
- return h2(Text, renderToText(node));
85
- }
86
83
  const originalTag = node.tag;
87
84
  const renderTag = findMappedTag(node, documentMeta.tags);
88
85
  if (node.tag === "binding") {
@@ -99,15 +96,6 @@ function renderNode(node, h2, documentMeta, parentScope = {}) {
99
96
  renderSlots(node, h2, documentMeta, { ...parentScope, ...props })
100
97
  );
101
98
  }
102
- function renderToText(node) {
103
- if (node.type === "text") {
104
- return node.value;
105
- }
106
- if (!node.children?.length) {
107
- return `<${node.tag}>`;
108
- }
109
- return `<${node.tag}>${node.children?.map(renderToText).join("") || ""}</${node.tag}>`;
110
- }
111
99
  function renderBinding(node, h2, documentMeta, parentScope = {}) {
112
100
  const data = {
113
101
  ...parentScope,
@@ -35,7 +35,4 @@ defineProps({
35
35
  pre code .line {
36
36
  display: block;
37
37
  }
38
- pre code .line:empty::before {
39
- content: "\200b";
40
- }
41
38
  </style>
@@ -0,0 +1,14 @@
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.
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ defineProps({
9
+ src: {
10
+ type: String,
11
+ default: ''
12
+ }
13
+ })
14
+ </script>
@@ -1,5 +1,5 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element } from 'hast';
3
- import { type Code } from 'mdast';
2
+ import type { Element } from 'hast';
3
+ import type { Code } from 'mdast';
4
4
  declare const _default: (state: State, node: Code) => Element;
5
5
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type Nodes as MdastContent } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { Nodes as MdastContent } from 'mdast';
4
4
  type Node = MdastContent & {
5
5
  name: string;
6
6
  attributes?: Properties;
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type Emphasis } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { Emphasis } from 'mdast';
4
4
  export default function emphasis(state: State, node: Emphasis & {
5
5
  attributes?: Properties;
6
6
  }): Element;
@@ -1,3 +1,3 @@
1
1
  import { type State, type Raw } from 'mdast-util-to-hast';
2
- import { type Html } from 'mdast';
2
+ import type { Html } from 'mdast';
3
3
  export default function html(state: State, node: Html): import("hast").Element | Raw | undefined;
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type Image } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { Image } from 'mdast';
4
4
  export default function image(state: State, node: Image & {
5
5
  attributes?: Properties;
6
6
  }): Element;
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type InlineCode } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { InlineCode } from 'mdast';
4
4
  export default function inlineCode(state: State, node: InlineCode & {
5
5
  attributes?: Properties;
6
6
  }): Element;
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type Link } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { Link } from 'mdast';
4
4
  export default function link(state: State, node: Link & {
5
5
  attributes?: Properties;
6
6
  }): Element;
@@ -1,4 +1,4 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element } from 'hast';
3
- import { type List } from 'mdast';
2
+ import type { Element } from 'hast';
3
+ import type { List } from 'mdast';
4
4
  export default function list(state: State, node: List): Element;
@@ -1,4 +1,4 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element } from 'hast';
3
- import { type Paragraph } from 'mdast';
2
+ import type { Element } from 'hast';
3
+ import type { Paragraph } from 'mdast';
4
4
  export default function paragraph(state: State, node: Paragraph): Element | import("hast").ElementContent[];
@@ -1,6 +1,6 @@
1
1
  import { type State } from 'mdast-util-to-hast';
2
- import { type Element, type Properties } from 'hast';
3
- import { type Strong } from 'mdast';
2
+ import type { Element, Properties } from 'hast';
3
+ import type { Strong } from 'mdast';
4
4
  export default function strong(state: State, node: Strong & {
5
5
  attributes?: Properties;
6
6
  }): Element;
@@ -1,7 +1,7 @@
1
1
  import { unified } from "unified";
2
2
  import remarkParse from "remark-parse";
3
3
  import remark2rehype from "remark-rehype";
4
- import remarkMDC, { parseFrontMatter } from "remark-mdc";
4
+ import { parseFrontMatter } from "remark-mdc";
5
5
  import { defu } from "defu";
6
6
  import { useProcessorPlugins } from "./utils/plugins.mjs";
7
7
  import { compileHast } from "./compiler.mjs";
@@ -25,7 +25,6 @@ export const parseMarkdown = async (md, opts = {}) => {
25
25
  const { content, data: frontmatter } = await parseFrontMatter(md);
26
26
  const processor = unified();
27
27
  processor.use(remarkParse);
28
- processor.use(remarkMDC);
29
28
  await useProcessorPlugins(processor, options.remark?.plugins);
30
29
  processor.use(remark2rehype, options.rehype?.options);
31
30
  if (options.highlight) {
@@ -1,6 +1,7 @@
1
1
  import handlers from "./handlers/index.mjs";
2
2
  import remarkEmoji from "remark-emoji";
3
3
  import remarkGFM from "remark-gfm";
4
+ import remarkMDC from "remark-mdc";
4
5
  import rehypeExternalLinks from "rehype-external-links";
5
6
  import rehypeSortAttributeValues from "rehype-sort-attribute-values";
6
7
  import rehypeSortAttributes from "rehype-sort-attributes";
@@ -8,6 +9,9 @@ import rehypeRaw from "rehype-raw";
8
9
  export const defaults = {
9
10
  remark: {
10
11
  plugins: {
12
+ "remark-mdc": {
13
+ instance: remarkMDC
14
+ },
11
15
  "remark-emoji": {
12
16
  instance: remarkEmoji
13
17
  },
@@ -5,15 +5,28 @@ const defaults = {
5
5
  default: "github-light",
6
6
  dark: "github-dark"
7
7
  },
8
- highlighter: (code, lang, theme, highlights) => {
9
- return $fetch("/api/_mdc/highlight", {
10
- params: {
11
- code,
12
- lang,
13
- theme: JSON.stringify(theme),
14
- highlights: JSON.stringify(highlights)
8
+ async highlighter(code, lang, theme, highlights) {
9
+ if (process.browser && window.sessionStorage.getItem("mdc-shiki-highlighter") === "browser") {
10
+ return import("./highlighter").then(({ useShikiHighlighter }) => {
11
+ return useShikiHighlighter().getHighlightedAST(code, lang, theme, { highlights });
12
+ });
13
+ }
14
+ try {
15
+ return await $fetch("/api/_mdc/highlight", {
16
+ params: {
17
+ code,
18
+ lang,
19
+ theme: JSON.stringify(theme),
20
+ highlights: JSON.stringify(highlights)
21
+ }
22
+ });
23
+ } catch (e) {
24
+ if (process.browser && e?.response?.status === 404) {
25
+ window.sessionStorage.setItem("mdc-shiki-highlighter", "browser");
26
+ return this.highlighter?.(code, lang, theme, highlights);
15
27
  }
16
- });
28
+ }
29
+ return Promise.resolve({ tree: [{ type: "text", value: code }], className: "", style: "" });
17
30
  }
18
31
  };
19
32
  export function rehypeShiki(opts = {}) {
@@ -37,7 +50,7 @@ export function rehypeShiki(opts = {}) {
37
50
  if (_node.children[0]?.tagName === "code") {
38
51
  _node.children[0].children = tree2;
39
52
  } else {
40
- _node.children = tree2[0].children;
53
+ _node.children = tree2[0].children || tree2[0];
41
54
  }
42
55
  if (style)
43
56
  styles.push(style);
@@ -14,4 +14,6 @@ export type MDCRoot = {
14
14
  children: Array<MDCNode>;
15
15
  };
16
16
  export interface MDCData extends Record<string, any> {
17
+ title: string;
18
+ description: string;
17
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
@@ -23,10 +23,10 @@
23
23
  ],
24
24
  "scripts": {
25
25
  "prepack": "nuxi prepare playground; nuxt-module-build",
26
- "build": "nuxi prepare playground; nuxt-module-build",
26
+ "build": "nuxi prepare playground; nuxt-module-build build",
27
27
  "dev": "nuxi dev playground",
28
28
  "dev:build": "nuxi build playground",
29
- "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
29
+ "dev:prepare": "nuxt-module-build build --stub && nuxi prepare playground",
30
30
  "dev:docs": "nuxi dev docs",
31
31
  "release": "release-it",
32
32
  "lint": "eslint .",
@@ -34,13 +34,13 @@
34
34
  "test:watch": "vitest watch"
35
35
  },
36
36
  "dependencies": {
37
- "@nuxt/kit": "^3.7.4",
37
+ "@nuxt/kit": "^3.8.0",
38
38
  "@types/hast": "^3.0.2",
39
39
  "@types/mdast": "^4.0.2",
40
- "@vue/compiler-core": "^3.3.4",
40
+ "@vue/compiler-core": "^3.3.7",
41
41
  "consola": "^3.2.3",
42
- "defu": "^6.1.2",
43
- "destr": "^2.0.1",
42
+ "defu": "^6.1.3",
43
+ "destr": "^2.0.2",
44
44
  "detab": "^3.0.2",
45
45
  "github-slugger": "^2.0.0",
46
46
  "hast-util-to-string": "^3.0.0",
@@ -55,7 +55,7 @@
55
55
  "rehype-sort-attributes": "^5.0.0",
56
56
  "remark-emoji": "^4.0.0",
57
57
  "remark-gfm": "^3.0.1",
58
- "remark-mdc": "^2.0.0",
58
+ "remark-mdc": "^2.1.0",
59
59
  "remark-parse": "^10.0.2",
60
60
  "remark-rehype": "^10.1.0",
61
61
  "scule": "^1.0.0",
@@ -69,14 +69,14 @@
69
69
  "@nuxt/devtools": "latest",
70
70
  "@nuxt/eslint-config": "^0.2.0",
71
71
  "@nuxt/module-builder": "^0.5.2",
72
- "@nuxt/schema": "^3.7.4",
73
- "@nuxt/test-utils": "^3.7.4",
72
+ "@nuxt/schema": "^3.8.0",
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.7",
76
+ "@types/node": "^20.8.8",
77
77
  "changelogen": "^0.5.5",
78
- "eslint": "^8.51.0",
79
- "nuxt": "^3.7.4",
78
+ "eslint": "^8.52.0",
79
+ "nuxt": "^3.8.0",
80
80
  "rehype": "^13.0.1",
81
81
  "release-it": "^16.2.1",
82
82
  "vitest": "^0.34.6"