@astrojs/markdown-remark 5.2.0 → 5.3.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/highlight.js CHANGED
@@ -16,13 +16,13 @@ async function highlightCodeBlocks(tree, highlighter) {
16
16
  let languageMatch;
17
17
  let { className } = node.properties;
18
18
  if (typeof className === "string") {
19
- languageMatch = className.match(languagePattern);
19
+ languageMatch = languagePattern.exec(className);
20
20
  } else if (Array.isArray(className)) {
21
21
  for (const cls of className) {
22
22
  if (typeof cls !== "string") {
23
23
  continue;
24
24
  }
25
- languageMatch = cls.match(languagePattern);
25
+ languageMatch = languagePattern.exec(cls);
26
26
  if (languageMatch) {
27
27
  break;
28
28
  }
package/dist/index.js CHANGED
@@ -31,7 +31,8 @@ const markdownConfigDefaults = {
31
31
  theme: "github-dark",
32
32
  themes: {},
33
33
  wrap: false,
34
- transformers: []
34
+ transformers: [],
35
+ langAlias: {}
35
36
  },
36
37
  remarkPlugins: [],
37
38
  rehypePlugins: [],
@@ -117,7 +118,7 @@ function prefixError(err, prefix) {
117
118
  err.message = `${prefix}:
118
119
  ${err.message}`;
119
120
  return err;
120
- } catch (error) {
121
+ } catch {
121
122
  }
122
123
  }
123
124
  const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ""}`);
@@ -13,7 +13,7 @@ function rehypeHeadingIds() {
13
13
  if (node.type !== "element") return;
14
14
  const { tagName } = node;
15
15
  if (tagName[0] !== "h") return;
16
- const [, level] = tagName.match(/h([0-6])/) ?? [];
16
+ const [, level] = /h([0-6])/.exec(tagName) ?? [];
17
17
  if (!level) return;
18
18
  const depth = Number.parseInt(level);
19
19
  let text = "";
@@ -22,7 +22,7 @@ function rehypeHeadingIds() {
22
22
  return;
23
23
  }
24
24
  if (child.type === "raw") {
25
- if (child.value.match(/^\n?<.*>\n?$/)) {
25
+ if (/^\n?<.*>\n?$/.test(child.value)) {
26
26
  return;
27
27
  }
28
28
  }
package/dist/shiki.d.ts CHANGED
@@ -9,4 +9,4 @@ export interface ShikiHighlighter {
9
9
  meta?: string;
10
10
  }): Promise<string>;
11
11
  }
12
- export declare function createShikiHighlighter({ langs, theme, themes, defaultColor, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
12
+ export declare function createShikiHighlighter({ langs, theme, themes, defaultColor, wrap, transformers, langAlias, }?: ShikiConfig): Promise<ShikiHighlighter>;
package/dist/shiki.js CHANGED
@@ -20,22 +20,26 @@ async function createShikiHighlighter({
20
20
  themes = {},
21
21
  defaultColor,
22
22
  wrap = false,
23
- transformers = []
23
+ transformers = [],
24
+ langAlias = {}
24
25
  } = {}) {
25
26
  theme = theme === "css-variables" ? cssVariablesTheme() : theme;
26
27
  const highlighter = await getHighlighter({
27
28
  langs: ["plaintext", ...langs],
29
+ langAlias,
28
30
  themes: Object.values(themes).length ? Object.values(themes) : [theme]
29
31
  });
30
32
  return {
31
33
  async highlight(code, lang = "plaintext", options) {
34
+ const resolvedLang = langAlias[lang] ?? lang;
32
35
  const loadedLanguages = highlighter.getLoadedLanguages();
33
- if (!isSpecialLang(lang) && !loadedLanguages.includes(lang)) {
36
+ if (!isSpecialLang(lang) && !loadedLanguages.includes(resolvedLang)) {
34
37
  try {
35
- await highlighter.loadLanguage(lang);
38
+ await highlighter.loadLanguage(resolvedLang);
36
39
  } catch (_err) {
40
+ const langStr = lang === resolvedLang ? `"${lang}"` : `"${lang}" (aliased to "${resolvedLang}")`;
37
41
  console.warn(
38
- `[Shiki] The language "${lang}" doesn't exist, falling back to "plaintext".`
42
+ `[Shiki] The language ${langStr} doesn't exist, falling back to "plaintext".`
39
43
  );
40
44
  lang = "plaintext";
41
45
  }
@@ -73,7 +77,7 @@ async function createShikiHighlighter({
73
77
  }
74
78
  },
75
79
  line(node) {
76
- if (lang === "diff") {
80
+ if (resolvedLang === "diff") {
77
81
  const innerSpanNode = node.children[0];
78
82
  const innerSpanTextNode = innerSpanNode?.type === "element" && innerSpanNode.children?.[0];
79
83
  if (innerSpanTextNode && innerSpanTextNode.type === "text") {
package/dist/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type * as hast from 'hast';
2
2
  import type * as mdast from 'mdast';
3
3
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
4
- import type { BuiltinTheme, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
4
+ import type { BuiltinTheme, HighlighterCoreOptions, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
5
5
  import type * as unified from 'unified';
6
6
  import type { DataMap, VFile } from 'vfile';
7
7
  export type { Node } from 'unist';
@@ -16,6 +16,7 @@ export type RemarkRehype = RemarkRehypeOptions;
16
16
  export type ThemePresets = BuiltinTheme | 'css-variables';
17
17
  export interface ShikiConfig {
18
18
  langs?: LanguageRegistration[];
19
+ langAlias?: HighlighterCoreOptions['langAlias'];
19
20
  theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
20
21
  themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
21
22
  defaultColor?: 'light' | 'dark' | string | false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "5.2.0",
3
+ "version": "5.3.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -27,31 +27,31 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "github-slugger": "^2.0.0",
30
- "hast-util-from-html": "^2.0.1",
30
+ "hast-util-from-html": "^2.0.3",
31
31
  "hast-util-to-text": "^4.0.2",
32
32
  "import-meta-resolve": "^4.1.0",
33
33
  "mdast-util-definitions": "^6.0.0",
34
34
  "rehype-raw": "^7.0.0",
35
- "rehype-stringify": "^10.0.0",
35
+ "rehype-stringify": "^10.0.1",
36
36
  "remark-gfm": "^4.0.0",
37
37
  "remark-parse": "^11.0.0",
38
- "remark-rehype": "^11.1.0",
38
+ "remark-rehype": "^11.1.1",
39
39
  "remark-smartypants": "^3.0.2",
40
- "shiki": "^1.10.3",
40
+ "shiki": "^1.22.0",
41
41
  "unified": "^11.0.5",
42
42
  "unist-util-remove-position": "^5.0.0",
43
43
  "unist-util-visit": "^5.0.0",
44
44
  "unist-util-visit-parents": "^6.0.1",
45
- "vfile": "^6.0.2",
45
+ "vfile": "^6.0.3",
46
46
  "@astrojs/prism": "3.1.0"
47
47
  },
48
48
  "devDependencies": {
49
- "@types/estree": "^1.0.5",
49
+ "@types/estree": "^1.0.6",
50
50
  "@types/hast": "^3.0.4",
51
51
  "@types/mdast": "^4.0.4",
52
- "@types/unist": "^3.0.2",
52
+ "@types/unist": "^3.0.3",
53
53
  "esbuild": "^0.21.5",
54
- "mdast-util-mdx-expression": "^2.0.0",
54
+ "mdast-util-mdx-expression": "^2.0.1",
55
55
  "astro-scripts": "0.0.14"
56
56
  },
57
57
  "publishConfig": {
@@ -61,7 +61,6 @@
61
61
  "prepublish": "pnpm build",
62
62
  "build": "astro-scripts build \"src/**/*.ts\" && tsc -p tsconfig.json",
63
63
  "build:ci": "astro-scripts build \"src/**/*.ts\"",
64
- "postbuild": "astro-scripts copy \"src/**/*.js\"",
65
64
  "dev": "astro-scripts dev \"src/**/*.ts\"",
66
65
  "test": "astro-scripts test \"test/**/*.test.js\""
67
66
  }