@astrojs/markdoc 0.11.5-beta.1 → 0.11.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/content-entry-type.js +21 -15
- package/dist/extensions/shiki.js +2 -10
- package/dist/index.js +1 -1
- package/package.json +5 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import { parseFrontmatter } from "@astrojs/markdown-remark";
|
|
5
4
|
import Markdoc from "@markdoc/markdoc";
|
|
6
5
|
import { emitESMImage } from "astro/assets/utils";
|
|
6
|
+
import matter from "gray-matter";
|
|
7
7
|
import { htmlTokenTransform } from "./html/transform/html-token-transform.js";
|
|
8
8
|
import { setupConfig } from "./runtime.js";
|
|
9
9
|
import { getMarkdocTokenizer } from "./tokenizer.js";
|
|
@@ -15,20 +15,12 @@ async function getContentEntryType({
|
|
|
15
15
|
}) {
|
|
16
16
|
return {
|
|
17
17
|
extensions: [".mdoc"],
|
|
18
|
-
getEntryInfo
|
|
19
|
-
const parsed = safeParseFrontmatter(contents, fileURLToPath(fileUrl));
|
|
20
|
-
return {
|
|
21
|
-
data: parsed.frontmatter,
|
|
22
|
-
body: parsed.content.trim(),
|
|
23
|
-
slug: parsed.frontmatter.slug,
|
|
24
|
-
rawData: parsed.rawFrontmatter
|
|
25
|
-
};
|
|
26
|
-
},
|
|
18
|
+
getEntryInfo,
|
|
27
19
|
handlePropagation: true,
|
|
28
20
|
async getRenderModule({ contents, fileUrl, viteId }) {
|
|
29
|
-
const
|
|
21
|
+
const entry = getEntryInfo({ contents, fileUrl });
|
|
30
22
|
const tokenizer = getMarkdocTokenizer(options);
|
|
31
|
-
let tokens = tokenizer.tokenize(
|
|
23
|
+
let tokens = tokenizer.tokenize(entry.body);
|
|
32
24
|
if (options?.allowHTML) {
|
|
33
25
|
tokens = htmlTokenTransform(tokenizer, tokens);
|
|
34
26
|
}
|
|
@@ -42,6 +34,7 @@ async function getContentEntryType({
|
|
|
42
34
|
ast,
|
|
43
35
|
/* Raised generics issue with Markdoc core https://github.com/markdoc/markdoc/discussions/400 */
|
|
44
36
|
markdocConfig,
|
|
37
|
+
entry,
|
|
45
38
|
viteId,
|
|
46
39
|
astroConfig,
|
|
47
40
|
filePath
|
|
@@ -58,6 +51,7 @@ async function getContentEntryType({
|
|
|
58
51
|
raiseValidationErrors({
|
|
59
52
|
ast: partialAst,
|
|
60
53
|
markdocConfig,
|
|
54
|
+
entry,
|
|
61
55
|
viteId,
|
|
62
56
|
astroConfig,
|
|
63
57
|
filePath: partialPath
|
|
@@ -189,6 +183,7 @@ async function resolvePartials({
|
|
|
189
183
|
function raiseValidationErrors({
|
|
190
184
|
ast,
|
|
191
185
|
markdocConfig,
|
|
186
|
+
entry,
|
|
192
187
|
viteId,
|
|
193
188
|
astroConfig,
|
|
194
189
|
filePath
|
|
@@ -202,6 +197,7 @@ function raiseValidationErrors({
|
|
|
202
197
|
!(e.error.id === "attribute-value-invalid" && /^Partial .+ not found/.test(e.error.message));
|
|
203
198
|
});
|
|
204
199
|
if (validationErrors.length) {
|
|
200
|
+
const frontmatterBlockOffset = entry.rawData.split("\n").length + 2;
|
|
205
201
|
const rootRelativePath = path.relative(fileURLToPath(astroConfig.root), filePath);
|
|
206
202
|
throw new MarkdocError({
|
|
207
203
|
message: [
|
|
@@ -211,7 +207,7 @@ function raiseValidationErrors({
|
|
|
211
207
|
location: {
|
|
212
208
|
// Error overlay does not support multi-line or ranges.
|
|
213
209
|
// Just point to the first line.
|
|
214
|
-
line: validationErrors[0].lines[0],
|
|
210
|
+
line: frontmatterBlockOffset + validationErrors[0].lines[0],
|
|
215
211
|
file: viteId
|
|
216
212
|
}
|
|
217
213
|
});
|
|
@@ -228,6 +224,15 @@ function getUsedTags(markdocAst) {
|
|
|
228
224
|
}
|
|
229
225
|
return tags;
|
|
230
226
|
}
|
|
227
|
+
function getEntryInfo({ fileUrl, contents }) {
|
|
228
|
+
const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
|
|
229
|
+
return {
|
|
230
|
+
data: parsed.data,
|
|
231
|
+
body: parsed.content,
|
|
232
|
+
slug: parsed.data.slug,
|
|
233
|
+
rawData: parsed.matter
|
|
234
|
+
};
|
|
235
|
+
}
|
|
231
236
|
async function emitOptimizedImages(nodeChildren, ctx) {
|
|
232
237
|
for (const node of nodeChildren) {
|
|
233
238
|
let isComponent = node.type === "tag" && node.tag === "image";
|
|
@@ -288,9 +293,10 @@ function getStringifiedMap(componentConfigMap, componentNamePrefix) {
|
|
|
288
293
|
stringifiedComponentMap += "}";
|
|
289
294
|
return stringifiedComponentMap;
|
|
290
295
|
}
|
|
291
|
-
function
|
|
296
|
+
function parseFrontmatter(fileContents, filePath) {
|
|
292
297
|
try {
|
|
293
|
-
|
|
298
|
+
matter.clearCache();
|
|
299
|
+
return matter(fileContents);
|
|
294
300
|
} catch (e) {
|
|
295
301
|
if (e.name === "YAMLException") {
|
|
296
302
|
const err = e;
|
package/dist/extensions/shiki.js
CHANGED
|
@@ -2,22 +2,14 @@ import { createShikiHighlighter } from "@astrojs/markdown-remark";
|
|
|
2
2
|
import Markdoc from "@markdoc/markdoc";
|
|
3
3
|
import { unescapeHTML } from "astro/runtime/server/index.js";
|
|
4
4
|
async function shiki(config) {
|
|
5
|
-
const highlighter = await createShikiHighlighter(
|
|
6
|
-
langs: config?.langs,
|
|
7
|
-
theme: config?.theme,
|
|
8
|
-
themes: config?.themes
|
|
9
|
-
});
|
|
5
|
+
const highlighter = await createShikiHighlighter(config);
|
|
10
6
|
return {
|
|
11
7
|
nodes: {
|
|
12
8
|
fence: {
|
|
13
9
|
attributes: Markdoc.nodes.fence.attributes,
|
|
14
10
|
async transform({ attributes }) {
|
|
15
11
|
const lang = typeof attributes.language === "string" ? attributes.language : "plaintext";
|
|
16
|
-
const html = await highlighter.
|
|
17
|
-
wrap: config?.wrap,
|
|
18
|
-
defaultColor: config?.defaultColor,
|
|
19
|
-
transformers: config?.transformers
|
|
20
|
-
});
|
|
12
|
+
const html = await highlighter.highlight(attributes.content, lang);
|
|
21
13
|
return unescapeHTML(html);
|
|
22
14
|
}
|
|
23
15
|
}
|
package/dist/index.js
CHANGED
|
@@ -25,7 +25,7 @@ function markdocIntegration(options) {
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
"astro:server:setup": async ({ server }) => {
|
|
28
|
-
server.watcher.on("all", (
|
|
28
|
+
server.watcher.on("all", (_event, entry) => {
|
|
29
29
|
if (SUPPORTED_MARKDOC_CONFIG_FILES.some((f) => entry.endsWith(f))) {
|
|
30
30
|
server.restart();
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc in your Astro site",
|
|
4
|
-
"version": "0.11.5
|
|
4
|
+
"version": "0.11.5",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -59,20 +59,21 @@
|
|
|
59
59
|
"@markdoc/markdoc": "^0.4.0",
|
|
60
60
|
"esbuild": "^0.21.5",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
62
|
+
"gray-matter": "^4.0.3",
|
|
62
63
|
"htmlparser2": "^9.1.0",
|
|
63
64
|
"@astrojs/internal-helpers": "0.4.1",
|
|
64
|
-
"@astrojs/markdown-remark": "
|
|
65
|
+
"@astrojs/markdown-remark": "5.3.0",
|
|
65
66
|
"@astrojs/prism": "3.1.0"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"astro": "^
|
|
69
|
+
"astro": "^3.0.0 || ^4.0.0"
|
|
69
70
|
},
|
|
70
71
|
"devDependencies": {
|
|
71
72
|
"@types/markdown-it": "^14.1.2",
|
|
72
73
|
"devalue": "^5.1.1",
|
|
73
74
|
"linkedom": "^0.18.5",
|
|
74
75
|
"vite": "^5.4.8",
|
|
75
|
-
"astro": "
|
|
76
|
+
"astro": "4.16.0",
|
|
76
77
|
"astro-scripts": "0.0.14"
|
|
77
78
|
},
|
|
78
79
|
"engines": {
|