@astrojs/markdown-remark 5.0.0 → 5.1.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,4 +1,4 @@
1
- import type { VFile, VFileData as Data } from 'vfile';
1
+ import type { VFileData as Data, VFile } from 'vfile';
2
2
  import type { MarkdownAstroData } from './types.js';
3
3
  export declare class InvalidAstroDataError extends TypeError {
4
4
  }
@@ -8,7 +8,7 @@ type Highlighter = (code: string, language: string, options?: {
8
8
  * @param tree
9
9
  * The hast tree in which to syntax highlight code blocks.
10
10
  * @param highlighter
11
- * A fnction which receives the code and language, and returns the HTML of a syntax
11
+ * A function which receives the code and language, and returns the HTML of a syntax
12
12
  * highlighted `<pre>` element.
13
13
  */
14
14
  export declare function highlightCodeBlocks(tree: Root, highlighter: Highlighter): Promise<void>;
@@ -10,14 +10,11 @@ function rehypeHeadingIds() {
10
10
  const isMDX = isMDXFile(file);
11
11
  const astroData = safelyGetAstroData(file.data);
12
12
  visit(tree, (node) => {
13
- if (node.type !== "element")
14
- return;
13
+ if (node.type !== "element") return;
15
14
  const { tagName } = node;
16
- if (tagName[0] !== "h")
17
- return;
15
+ if (tagName[0] !== "h") return;
18
16
  const [, level] = tagName.match(/h([0-6])/) ?? [];
19
- if (!level)
20
- return;
17
+ if (!level) return;
21
18
  const depth = Number.parseInt(level);
22
19
  let text = "";
23
20
  visit(node, (child, __, parent) => {
@@ -50,8 +47,7 @@ function rehypeHeadingIds() {
50
47
  node.properties = node.properties || {};
51
48
  if (typeof node.properties.id !== "string") {
52
49
  let slug = slugger.slug(text);
53
- if (slug.endsWith("-"))
54
- slug = slug.slice(0, -1);
50
+ if (slug.endsWith("-")) slug = slug.slice(0, -1);
55
51
  node.properties.id = slug;
56
52
  }
57
53
  headings.push({ depth, slug: node.properties.id, text });
@@ -63,8 +59,7 @@ function isMDXFile(file) {
63
59
  return Boolean(file.history[0]?.endsWith(".mdx"));
64
60
  }
65
61
  function getMdxFrontmatterVariablePath(node) {
66
- if (!node.data?.estree || node.data.estree.body.length !== 1)
67
- return new Error();
62
+ if (!node.data?.estree || node.data.estree.body.length !== 1) return new Error();
68
63
  const statement = node.data.estree.body[0];
69
64
  if (statement?.type !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
70
65
  return new Error();
@@ -76,15 +71,13 @@ function getMdxFrontmatterVariablePath(node) {
76
71
  );
77
72
  expression = expression.object;
78
73
  }
79
- if (expression.type !== "Identifier" || expression.name !== "frontmatter")
80
- return new Error();
74
+ if (expression.type !== "Identifier" || expression.name !== "frontmatter") return new Error();
81
75
  return expressionPath.reverse();
82
76
  }
83
77
  function getMdxFrontmatterVariableValue(astroData, path) {
84
78
  let value = astroData.frontmatter;
85
79
  for (const key of path) {
86
- if (!value[key])
87
- return void 0;
80
+ if (!value[key]) return void 0;
88
81
  value = value[key];
89
82
  }
90
83
  return value;
@@ -3,10 +3,8 @@ function rehypeImages() {
3
3
  return () => function(tree, file) {
4
4
  const imageOccurrenceMap = /* @__PURE__ */ new Map();
5
5
  visit(tree, (node) => {
6
- if (node.type !== "element")
7
- return;
8
- if (node.tagName !== "img")
9
- return;
6
+ if (node.type !== "element") return;
7
+ if (node.tagName !== "img") return;
10
8
  if (node.properties?.src) {
11
9
  node.properties.src = decodeURI(node.properties.src);
12
10
  if (file.data.imagePaths?.has(node.properties.src)) {
@@ -5,7 +5,7 @@ const rehypePrism = () => {
5
5
  await highlightCodeBlocks(tree, (code, language) => {
6
6
  let { html, classLanguage } = runHighlighterWithAstro(language, code);
7
7
  return Promise.resolve(
8
- `<pre class="${classLanguage}"><code is:raw class="${classLanguage}">${html}</code></pre>`
8
+ `<pre class="${classLanguage}" data-language="${language}"><code is:raw class="${classLanguage}">${html}</code></pre>`
9
9
  );
10
10
  });
11
11
  };
@@ -2,20 +2,18 @@ import { definitions } from "mdast-util-definitions";
2
2
  import { visit } from "unist-util-visit";
3
3
  function remarkCollectImages() {
4
4
  return function(tree, vfile) {
5
- if (typeof vfile?.path !== "string")
6
- return;
5
+ if (typeof vfile?.path !== "string") return;
7
6
  const definition = definitions(tree);
8
7
  const imagePaths = /* @__PURE__ */ new Set();
9
8
  visit(tree, ["image", "imageReference"], (node) => {
10
9
  if (node.type === "image") {
11
- if (shouldOptimizeImage(node.url))
12
- imagePaths.add(node.url);
10
+ if (shouldOptimizeImage(node.url)) imagePaths.add(decodeURI(node.url));
13
11
  }
14
12
  if (node.type === "imageReference") {
15
13
  const imageDefinition = definition(node.identifier);
16
14
  if (imageDefinition) {
17
15
  if (shouldOptimizeImage(imageDefinition.url))
18
- imagePaths.add(imageDefinition.url);
16
+ imagePaths.add(decodeURI(imageDefinition.url));
19
17
  }
20
18
  }
21
19
  });
package/dist/shiki.js CHANGED
@@ -63,6 +63,7 @@ async function createShikiHighlighter({
63
63
  const classValue = (normalizePropAsString(node.properties.class) ?? "") + (attributesClass ? ` ${attributesClass}` : "");
64
64
  const styleValue = (normalizePropAsString(node.properties.style) ?? "") + (attributesStyle ? `; ${attributesStyle}` : "");
65
65
  node.properties.class = classValue.replace(/shiki/g, "astro-code");
66
+ node.properties.dataLanguage = lang;
66
67
  if (wrap === false) {
67
68
  node.properties.style = styleValue + "; overflow-x: auto;";
68
69
  } else if (wrap === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "5.0.0",
3
+ "version": "5.1.1",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -26,33 +26,31 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@astrojs/prism": "^3.0.0",
30
29
  "github-slugger": "^2.0.0",
31
- "hast-util-from-html": "^2.0.0",
32
- "hast-util-to-text": "^4.0.0",
33
- "import-meta-resolve": "^4.0.0",
30
+ "hast-util-from-html": "^2.0.1",
31
+ "hast-util-to-text": "^4.0.2",
32
+ "import-meta-resolve": "^4.1.0",
34
33
  "mdast-util-definitions": "^6.0.0",
35
34
  "rehype-raw": "^7.0.0",
36
35
  "rehype-stringify": "^10.0.0",
37
36
  "remark-gfm": "^4.0.0",
38
37
  "remark-parse": "^11.0.0",
39
- "remark-rehype": "^11.0.0",
40
- "remark-smartypants": "^2.0.0",
41
- "shiki": "^1.1.2",
42
- "unified": "^11.0.4",
38
+ "remark-rehype": "^11.1.0",
39
+ "remark-smartypants": "^3.0.1",
40
+ "shiki": "^1.9.0",
41
+ "unified": "^11.0.5",
43
42
  "unist-util-remove-position": "^5.0.0",
44
43
  "unist-util-visit": "^5.0.0",
45
- "unist-util-visit-parents": "^6.0.0",
46
- "vfile": "^6.0.1"
44
+ "unist-util-visit-parents": "^6.0.1",
45
+ "vfile": "^6.0.1",
46
+ "@astrojs/prism": "3.1.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/chai": "^4.3.10",
50
49
  "@types/estree": "^1.0.5",
51
- "@types/hast": "^3.0.3",
52
- "@types/mdast": "^4.0.3",
53
- "@types/mocha": "^10.0.4",
50
+ "@types/hast": "^3.0.4",
51
+ "@types/mdast": "^4.0.4",
54
52
  "@types/unist": "^3.0.2",
55
- "esbuild": "^0.19.6",
53
+ "esbuild": "^0.21.5",
56
54
  "mdast-util-mdx-expression": "^2.0.0",
57
55
  "astro-scripts": "0.0.14"
58
56
  },