@astrojs/markdown-remark 2.2.1 → 3.0.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.
@@ -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
  }
package/dist/index.js CHANGED
@@ -32,7 +32,6 @@ const markdownConfigDefaults = {
32
32
  };
33
33
  const isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
34
34
  async function renderMarkdown(content, opts) {
35
- var _a;
36
35
  let {
37
36
  fileURL,
38
37
  syntaxHighlight = markdownConfigDefaults.syntaxHighlight,
@@ -45,7 +44,7 @@ async function renderMarkdown(content, opts) {
45
44
  frontmatter: userFrontmatter = {}
46
45
  } = opts;
47
46
  const input = new VFile({ value: content, path: fileURL });
48
- const scopedClassName = (_a = opts.$) == null ? void 0 : _a.scopedClassName;
47
+ const scopedClassName = opts.$?.scopedClassName;
49
48
  let parser = unified().use(markdown).use(toRemarkInitializeAstroData({ userFrontmatter })).use([]);
50
49
  if (!isPerformanceBenchmark && gfm) {
51
50
  if (gfm) {
@@ -101,7 +100,7 @@ async function renderMarkdown(content, opts) {
101
100
  console.error(err);
102
101
  throw err;
103
102
  }
104
- const headings = (vfile == null ? void 0 : vfile.data.__astroHeadings) || [];
103
+ const headings = vfile?.data.__astroHeadings || [];
105
104
  return {
106
105
  metadata: { headings, source: content, html: String(vfile.value) },
107
106
  code: String(vfile.value),
@@ -109,7 +108,7 @@ async function renderMarkdown(content, opts) {
109
108
  };
110
109
  }
111
110
  function prefixError(err, prefix) {
112
- if (err && err.message) {
111
+ if (err?.message) {
113
112
  try {
114
113
  err.message = `${prefix}:
115
114
  ${err.message}`;
@@ -121,7 +120,7 @@ ${err.message}`;
121
120
  try {
122
121
  wrappedError.stack = err.stack;
123
122
  wrappedError.cause = err;
124
- } catch (error) {
123
+ } catch {
125
124
  }
126
125
  return wrappedError;
127
126
  }
@@ -1,6 +1,6 @@
1
1
  import { resolve as importMetaResolve } from "import-meta-resolve";
2
- import path from "path";
3
- import { pathToFileURL } from "url";
2
+ import path from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
4
  const cwdUrlStr = pathToFileURL(path.join(process.cwd(), "package.json")).toString();
5
5
  async function importPlugin(p) {
6
6
  if (typeof p === "string") {
@@ -15,7 +15,7 @@ function rehypeHeadingIds() {
15
15
  const { tagName } = node;
16
16
  if (tagName[0] !== "h")
17
17
  return;
18
- const [_, level] = tagName.match(/h([0-6])/) ?? [];
18
+ const [, level] = tagName.match(/h([0-6])/) ?? [];
19
19
  if (!level)
20
20
  return;
21
21
  const depth = Number.parseInt(level);
@@ -60,15 +60,13 @@ function rehypeHeadingIds() {
60
60
  };
61
61
  }
62
62
  function isMDXFile(file) {
63
- var _a;
64
- return Boolean((_a = file.history[0]) == null ? void 0 : _a.endsWith(".mdx"));
63
+ return Boolean(file.history[0]?.endsWith(".mdx"));
65
64
  }
66
65
  function getMdxFrontmatterVariablePath(node) {
67
- var _a;
68
- if (!((_a = node.data) == null ? void 0 : _a.estree) || node.data.estree.body.length !== 1)
66
+ if (!node.data?.estree || node.data.estree.body.length !== 1)
69
67
  return new Error();
70
68
  const statement = node.data.estree.body[0];
71
- if ((statement == null ? void 0 : statement.type) !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
69
+ if (statement?.type !== "ExpressionStatement" || statement.expression.type !== "MemberExpression")
72
70
  return new Error();
73
71
  let expression = statement.expression;
74
72
  const expressionPath = [];
@@ -2,13 +2,12 @@ import { visit } from "unist-util-visit";
2
2
  function rehypeImages() {
3
3
  return () => function(tree, file) {
4
4
  visit(tree, (node) => {
5
- var _a, _b;
6
5
  if (node.type !== "element")
7
6
  return;
8
7
  if (node.tagName !== "img")
9
8
  return;
10
- if ((_a = node.properties) == null ? void 0 : _a.src) {
11
- if ((_b = file.data.imagePaths) == null ? void 0 : _b.has(node.properties.src)) {
9
+ if (node.properties?.src) {
10
+ if (file.data.imagePaths?.has(node.properties.src)) {
12
11
  node.properties["__ASTRO_IMAGE_"] = node.properties.src;
13
12
  delete node.properties.src;
14
13
  }
@@ -1,7 +1,7 @@
1
1
  import { visit } from "unist-util-visit";
2
2
  function remarkCollectImages() {
3
3
  return function(tree, vfile) {
4
- if (typeof (vfile == null ? void 0 : vfile.path) !== "string")
4
+ if (typeof vfile?.path !== "string")
5
5
  return;
6
6
  const imagePaths = /* @__PURE__ */ new Set();
7
7
  visit(tree, "image", (node) => {
@@ -1,6 +1,5 @@
1
1
  import { runHighlighterWithAstro } from "@astrojs/prism/dist/highlighter";
2
2
  import { visit } from "unist-util-visit";
3
- const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
4
3
  function transformer(className) {
5
4
  return function(tree) {
6
5
  const visitor = (node) => {
@@ -2,11 +2,10 @@ import { visit } from "unist-util-visit";
2
2
  const noVisit = /* @__PURE__ */ new Set(["root", "html", "text"]);
3
3
  function scopedStyles(className) {
4
4
  const visitor = (node) => {
5
- var _a;
6
5
  if (noVisit.has(node.type))
7
6
  return;
8
7
  const { data } = node;
9
- let currentClassName = ((_a = data == null ? void 0 : data.hProperties) == null ? void 0 : _a.class) ?? "";
8
+ let currentClassName = data?.hProperties?.class ?? "";
10
9
  node.data = node.data || {};
11
10
  node.data.hProperties = node.data.hProperties || {};
12
11
  node.data.hProperties.class = `${className} ${currentClassName}`.trim();
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type * as hast from 'hast';
2
2
  import type * as mdast from 'mdast';
3
- import type { all as Handlers, one as Handler, Options as RemarkRehypeOptions } from 'remark-rehype';
3
+ import type { one as Handler, all as Handlers, Options as RemarkRehypeOptions } from 'remark-rehype';
4
4
  import type { ILanguageRegistration, IThemeRegistration, Theme } from 'shiki';
5
5
  import type * as unified from 'unified';
6
6
  import type { VFile } from 'vfile';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "2.2.1",
3
+ "version": "3.0.0-beta.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -20,33 +20,33 @@
20
20
  "dist"
21
21
  ],
22
22
  "peerDependencies": {
23
- "astro": "^2.5.0"
23
+ "astro": "^3.0.0-beta.0"
24
24
  },
25
25
  "dependencies": {
26
- "@astrojs/prism": "^2.1.2",
27
- "github-slugger": "^1.4.0",
28
- "import-meta-resolve": "^2.1.0",
26
+ "@astrojs/prism": "^3.0.0-beta.0",
27
+ "github-slugger": "^1.5.0",
28
+ "import-meta-resolve": "^2.2.2",
29
29
  "rehype-raw": "^6.1.1",
30
30
  "rehype-stringify": "^9.0.3",
31
31
  "remark-gfm": "^3.0.1",
32
- "remark-parse": "^10.0.1",
32
+ "remark-parse": "^10.0.2",
33
33
  "remark-rehype": "^10.1.0",
34
34
  "remark-smartypants": "^2.0.0",
35
35
  "shiki": "^0.14.1",
36
36
  "unified": "^10.1.2",
37
- "unist-util-visit": "^4.1.0",
38
- "vfile": "^5.3.2"
37
+ "unist-util-visit": "^4.1.2",
38
+ "vfile": "^5.3.7"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/chai": "^4.3.1",
42
- "@types/estree": "^1.0.0",
41
+ "@types/chai": "^4.3.5",
42
+ "@types/estree": "^1.0.1",
43
43
  "@types/github-slugger": "^1.3.0",
44
44
  "@types/hast": "^2.3.4",
45
- "@types/mdast": "^3.0.10",
45
+ "@types/mdast": "^3.0.11",
46
46
  "@types/mocha": "^9.1.1",
47
47
  "@types/unist": "^2.0.6",
48
- "chai": "^4.3.6",
49
- "mdast-util-mdx-expression": "^1.3.1",
48
+ "chai": "^4.3.7",
49
+ "mdast-util-mdx-expression": "^1.3.2",
50
50
  "mocha": "^9.2.2",
51
51
  "astro-scripts": "0.0.14"
52
52
  },