@astrojs/markdown-remark 2.2.1 → 3.0.0-rc.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
  }
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) {
@@ -69,9 +68,7 @@ async function renderMarkdown(content, opts) {
69
68
  } else if (syntaxHighlight === "prism") {
70
69
  parser.use([remarkPrism(scopedClassName)]);
71
70
  }
72
- if (opts.experimentalAssets) {
73
- parser.use([remarkCollectImages]);
74
- }
71
+ parser.use([remarkCollectImages]);
75
72
  }
76
73
  parser.use([
77
74
  [
@@ -86,9 +83,7 @@ async function renderMarkdown(content, opts) {
86
83
  loadedRehypePlugins.forEach(([plugin, pluginOpts]) => {
87
84
  parser.use([[plugin, pluginOpts]]);
88
85
  });
89
- if (opts.experimentalAssets) {
90
- parser.use(rehypeImages());
91
- }
86
+ parser.use(rehypeImages());
92
87
  if (!isPerformanceBenchmark) {
93
88
  parser.use([rehypeHeadingIds]);
94
89
  }
@@ -101,7 +96,7 @@ async function renderMarkdown(content, opts) {
101
96
  console.error(err);
102
97
  throw err;
103
98
  }
104
- const headings = (vfile == null ? void 0 : vfile.data.__astroHeadings) || [];
99
+ const headings = vfile?.data.__astroHeadings || [];
105
100
  return {
106
101
  metadata: { headings, source: content, html: String(vfile.value) },
107
102
  code: String(vfile.value),
@@ -109,7 +104,7 @@ async function renderMarkdown(content, opts) {
109
104
  };
110
105
  }
111
106
  function prefixError(err, prefix) {
112
- if (err && err.message) {
107
+ if (err?.message) {
113
108
  try {
114
109
  err.message = `${prefix}:
115
110
  ${err.message}`;
@@ -121,7 +116,7 @@ ${err.message}`;
121
116
  try {
122
117
  wrappedError.stack = err.stack;
123
118
  wrappedError.cause = err;
124
- } catch (error) {
119
+ } catch {
125
120
  }
126
121
  return wrappedError;
127
122
  }
@@ -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();
@@ -1,24 +1,7 @@
1
1
  import { getHighlighter } from "shiki";
2
2
  import { visit } from "unist-util-visit";
3
3
  const highlighterCacheAsync = /* @__PURE__ */ new Map();
4
- const compatThemes = {
5
- "material-darker": "material-theme-darker",
6
- "material-default": "material-theme",
7
- "material-lighter": "material-theme-lighter",
8
- "material-ocean": "material-theme-ocean",
9
- "material-palenight": "material-theme-palenight"
10
- };
11
- const normalizeTheme = (theme) => {
12
- if (typeof theme === "string") {
13
- return compatThemes[theme] || theme;
14
- } else if (compatThemes[theme.name]) {
15
- return { ...theme, name: compatThemes[theme.name] };
16
- } else {
17
- return theme;
18
- }
19
- };
20
4
  const remarkShiki = async ({ langs = [], theme = "github-dark", wrap = false }, scopedClassName) => {
21
- theme = normalizeTheme(theme);
22
5
  const cacheID = typeof theme === "string" ? theme : theme.name;
23
6
  let highlighterAsync = highlighterCacheAsync.get(cacheID);
24
7
  if (!highlighterAsync) {
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';
@@ -46,7 +46,6 @@ export interface MarkdownRenderingOptions extends AstroMarkdownOptions {
46
46
  };
47
47
  /** Used for frontmatter injection plugins */
48
48
  frontmatter?: Record<string, any>;
49
- experimentalAssets?: boolean;
50
49
  }
51
50
  export interface MarkdownHeading {
52
51
  depth: number;
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-rc.1",
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-rc.5"
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-rc.1",
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
  },