@nuxtjs/mdc 0.15.0 → 0.16.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/dist/module.d.mts CHANGED
@@ -67,7 +67,7 @@ interface MDCParseOptions {
67
67
  */
68
68
  depth?: number;
69
69
  searchDepth?: number;
70
- };
70
+ } | false;
71
71
  keepComments?: boolean;
72
72
  /**
73
73
  * Extract content heading from the markdown file.
package/dist/module.d.ts CHANGED
@@ -67,7 +67,7 @@ interface MDCParseOptions {
67
67
  */
68
68
  depth?: number;
69
69
  searchDepth?: number;
70
- };
70
+ } | false;
71
71
  keepComments?: boolean;
72
72
  /**
73
73
  * Extract content heading from the markdown file.
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
3
  "configKey": "mdc",
4
- "version": "0.15.0",
4
+ "version": "0.16.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -124,8 +124,8 @@ async function mdcHighlighter({
124
124
  if (options.highlighter === "custom") {
125
125
  return [
126
126
  "import { getMdcConfigs } from '#mdc-configs'",
127
- `export default function (...args) {
128
- ' const configs = await getMdcConfigs()`,
127
+ "export default async function (...args) {",
128
+ " const configs = await getMdcConfigs()",
129
129
  " for (const config of configs) {",
130
130
  " if (config.highlighter) {",
131
131
  " return config.highlighter(...args)",
@@ -18,7 +18,6 @@
18
18
  </template>
19
19
 
20
20
  <script setup lang="ts">
21
- import { hash } from 'ohash'
22
21
  import { useAsyncData } from 'nuxt/app'
23
22
  import { watch, computed, type PropType } from 'vue'
24
23
  import type { MDCParseOptions } from '@nuxtjs/mdc'
@@ -72,16 +71,27 @@ const props = defineProps({
72
71
  cacheKey: {
73
72
  type: String,
74
73
  default: undefined
74
+ },
75
+ /**
76
+ * Partial parsing (if partial is `true`, title and toc generation will not be generated)
77
+ */
78
+ partial: {
79
+ type: Boolean,
80
+ default: true
75
81
  }
76
82
  })
77
83
 
78
- const key = computed(() => props.cacheKey ?? hash(props.value))
84
+ const key = computed(() => props.cacheKey ?? hashString(props.value))
79
85
 
80
86
  const { data, refresh, error } = await useAsyncData(key.value, async () => {
81
87
  if (typeof props.value !== 'string') {
82
88
  return props.value
83
89
  }
84
- return await parseMarkdown(props.value, props.parserOptions)
90
+ return await parseMarkdown(props.value, {
91
+ ...props.parserOptions,
92
+ toc: props.partial ? false : props.parserOptions?.toc,
93
+ contentHeading: props.partial ? false : props.parserOptions?.contentHeading
94
+ })
85
95
  })
86
96
 
87
97
  const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body)
@@ -89,4 +99,18 @@ const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.bo
89
99
  watch(() => props.value, () => {
90
100
  refresh()
91
101
  })
102
+
103
+ // Simple string hashing function
104
+ function hashString(str: string | object) {
105
+ if (typeof str !== 'string') {
106
+ str = JSON.stringify(str || '')
107
+ }
108
+ let hash = 0
109
+ for (let i = 0; i < str.length; i++) {
110
+ const char = str.charCodeAt(i)
111
+ hash = ((hash << 6) - hash) + char
112
+ hash = hash & hash // Convert to 64bit integer
113
+ }
114
+ return `mdc-${hash === 0 ? '0000' : hash.toString(36)}-key`
115
+ }
92
116
  </script>
@@ -68,7 +68,8 @@ export default defineComponent({
68
68
  }
69
69
  },
70
70
  async setup(props) {
71
- const $nuxt = getCurrentInstance()?.appContext?.app?.$nuxt;
71
+ const app = getCurrentInstance()?.appContext?.app;
72
+ const $nuxt = app?.$nuxt;
72
73
  const route = $nuxt?.$route || $nuxt?._route;
73
74
  const { mdc } = $nuxt?.$config?.public || {};
74
75
  const tags = {
@@ -3,7 +3,7 @@ const defaults = {
3
3
  theme: {},
4
4
  async highlighter(code, lang, theme, options) {
5
5
  try {
6
- if (import.meta.browser && window.sessionStorage.getItem("mdc-shiki-highlighter") === "browser") {
6
+ if (import.meta.client && window.sessionStorage.getItem("mdc-shiki-highlighter") === "browser") {
7
7
  return import("#mdc-highlighter").then((h) => h.default(code, lang, theme, options)).catch(() => ({}));
8
8
  }
9
9
  return await $fetch("/api/_mdc/highlight", {
@@ -15,7 +15,7 @@ const defaults = {
15
15
  }
16
16
  });
17
17
  } catch (e) {
18
- if (import.meta.browser && e?.response?.status === 404) {
18
+ if (import.meta.client && e?.response?.status === 404) {
19
19
  window.sessionStorage.setItem("mdc-shiki-highlighter", "browser");
20
20
  return this.highlighter?.(code, lang, theme, options);
21
21
  }
@@ -83,23 +83,22 @@ export const createMarkdownParser = async (inlineOptions = {}) => {
83
83
  }
84
84
  });
85
85
  });
86
- const result = processedFile?.result;
86
+ const parsedContent = processedFile?.result;
87
87
  const data = Object.assign(
88
- inlineOptions.contentHeading !== false ? contentHeading(result.body) : {},
88
+ inlineOptions.contentHeading !== false ? contentHeading(parsedContent.body) : {},
89
89
  frontmatter,
90
90
  processedFile?.data || {}
91
91
  );
92
- let toc;
93
- if (data.toc !== false) {
94
- const tocOption = defu(data.toc || {}, inlineOptions.toc, defaults.toc);
95
- toc = generateToc(result.body, tocOption);
92
+ const parsedResult = { data, body: parsedContent.body };
93
+ const userTocOption = data.toc ?? inlineOptions.toc;
94
+ if (userTocOption !== false) {
95
+ const tocOption = defu({}, userTocOption, defaults.toc);
96
+ parsedResult.toc = generateToc(parsedContent.body, tocOption);
96
97
  }
97
- return {
98
- data,
99
- body: result.body,
100
- excerpt: result.excerpt,
101
- toc
102
- };
98
+ if (parsedContent.excerpt) {
99
+ parsedResult.excerpt = parsedContent.excerpt;
100
+ }
101
+ return parsedResult;
103
102
  };
104
103
  };
105
104
  export const parseMarkdown = async (md, markdownParserOptions = {}, parseOptions = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  "typesVersions": {
50
50
  "*": {
51
51
  "*": [
52
- "./dist/*",
52
+ "./dist/* ",
53
53
  "./dist/index.d.ts"
54
54
  ],
55
55
  "config": [
@@ -58,7 +58,7 @@
58
58
  }
59
59
  },
60
60
  "scripts": {
61
- "prepack": "nuxt-module-build prepare; nuxt-module-build",
61
+ "prepack": "nuxt-module-build prepare; nuxt-module-build build",
62
62
  "build": "nuxt-module-build prepare; nuxt-module-build build",
63
63
  "dev": "npm run dev:prepare; nuxi dev playground",
64
64
  "dev:build": "nuxi build playground",
@@ -72,12 +72,12 @@
72
72
  "verify": "npm run dev:prepare && npm run lint && npm run test && npm run typecheck"
73
73
  },
74
74
  "dependencies": {
75
- "@nuxt/kit": "^3.15.4",
76
- "@shikijs/transformers": "^3.0.0",
75
+ "@nuxt/kit": "^3.16.0",
76
+ "@shikijs/transformers": "^3.2.1",
77
77
  "@types/hast": "^3.0.4",
78
78
  "@types/mdast": "^4.0.4",
79
79
  "@vue/compiler-core": "^3.5.13",
80
- "consola": "^3.4.0",
80
+ "consola": "^3.4.2",
81
81
  "debug": "4.4.0",
82
82
  "defu": "^6.1.4",
83
83
  "destr": "^2.0.3",
@@ -88,10 +88,9 @@
88
88
  "hast-util-to-string": "^3.0.1",
89
89
  "mdast-util-to-hast": "^13.2.0",
90
90
  "micromark-util-sanitize-uri": "^2.0.1",
91
- "ohash": "^1.1.4",
92
91
  "parse5": "^7.2.1",
93
92
  "pathe": "^2.0.3",
94
- "property-information": "^6.5.0",
93
+ "property-information": "^7.0.0",
95
94
  "rehype-external-links": "^3.0.0",
96
95
  "rehype-minify-whitespace": "^6.0.2",
97
96
  "rehype-raw": "^7.0.0",
@@ -106,7 +105,7 @@
106
105
  "remark-rehype": "^11.1.1",
107
106
  "remark-stringify": "^11.0.0",
108
107
  "scule": "^1.3.0",
109
- "shiki": "^3.0.0",
108
+ "shiki": "^3.2.1",
110
109
  "ufo": "^1.5.4",
111
110
  "unified": "^11.0.5",
112
111
  "unist-builder": "^4.0.0",
@@ -115,27 +114,26 @@
115
114
  "vfile": "^6.0.3"
116
115
  },
117
116
  "devDependencies": {
118
- "@nuxt/devtools": "latest",
119
- "@nuxt/eslint-config": "^1.1.0",
117
+ "@nuxt/devtools": "^2.3.0",
118
+ "@nuxt/eslint-config": "^1.2.0",
120
119
  "@nuxt/module-builder": "^0.8.4",
121
- "@nuxt/schema": "^3.15.4",
122
- "@nuxt/test-utils": "^3.17.0",
123
- "@nuxt/ui": "^2.21.0",
120
+ "@nuxt/schema": "^3.16.0",
121
+ "@nuxt/test-utils": "^3.17.2",
122
+ "@nuxt/ui": "^3.0.0",
124
123
  "@nuxtjs/mdc": "link:.",
125
- "@types/node": "^22.13.5",
126
- "changelogen": "^0.5.7",
127
- "eslint": "^9.21.0",
128
- "nuxt": "^3.15.4",
124
+ "@types/node": "^22.13.10",
125
+ "eslint": "^9.22.0",
126
+ "nuxt": "^3.16.0",
129
127
  "rehype": "^13.0.2",
130
128
  "release-it": "^18.1.2",
131
- "typescript": "5.6.2",
132
- "vitest": "^3.0.7",
133
- "vue-tsc": "^2.2.4"
129
+ "typescript": "5.8.2",
130
+ "vitest": "^3.0.9",
131
+ "vue-tsc": "^2.2.8"
134
132
  },
135
133
  "resolutions": {
136
134
  "@nuxtjs/mdc": "workspace:*"
137
135
  },
138
- "packageManager": "pnpm@10.4.0",
136
+ "packageManager": "pnpm@10.6.5",
139
137
  "release-it": {
140
138
  "git": {
141
139
  "commitMessage": "chore(release): release v${version}"
@@ -151,7 +149,11 @@
151
149
  "pnpm": {
152
150
  "onlyBuiltDependencies": [
153
151
  "@parcel/watcher",
154
- "esbuild"
152
+ "esbuild",
153
+ "vue-demi"
154
+ ],
155
+ "ignoredBuiltDependencies": [
156
+ "vue-demi"
155
157
  ]
156
158
  }
157
159
  }