@astrojs/markdoc 0.11.5-beta.0 → 0.11.5-beta.1

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.
@@ -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 entry = getEntryInfo({ contents, fileUrl });
29
+ const parsed = safeParseFrontmatter(contents, fileURLToPath(fileUrl));
22
30
  const tokenizer = getMarkdocTokenizer(options);
23
- let tokens = tokenizer.tokenize(entry.body);
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: frontmatterBlockOffset + validationErrors[0].lines[0],
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 parseFrontmatter(fileContents, filePath) {
291
+ function safeParseFrontmatter(fileContents, filePath) {
297
292
  try {
298
- matter.clearCache();
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/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-beta.0",
4
+ "version": "0.11.5-beta.1",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
7
7
  "author": "withastro",
@@ -59,10 +59,9 @@
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": "6.0.0-beta.1",
64
+ "@astrojs/markdown-remark": "6.0.0-beta.2",
66
65
  "@astrojs/prism": "3.1.0"
67
66
  },
68
67
  "peerDependencies": {
@@ -70,10 +69,10 @@
70
69
  },
71
70
  "devDependencies": {
72
71
  "@types/markdown-it": "^14.1.2",
73
- "devalue": "^5.0.0",
74
- "linkedom": "^0.18.4",
75
- "vite": "^5.4.3",
76
- "astro": "5.0.0-beta.1",
72
+ "devalue": "^5.1.1",
73
+ "linkedom": "^0.18.5",
74
+ "vite": "^5.4.8",
75
+ "astro": "5.0.0-beta.3",
77
76
  "astro-scripts": "0.0.14"
78
77
  },
79
78
  "engines": {