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