@astrojs/markdown-remark 5.1.1 → 6.0.0-alpha.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
@@ -117,7 +117,7 @@ function prefixError(err, prefix) {
117
117
  err.message = `${prefix}:
118
118
  ${err.message}`;
119
119
  return err;
120
- } catch (error) {
120
+ } catch {
121
121
  }
122
122
  }
123
123
  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, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
12
+ export declare function createShikiHighlighter({ langs, theme, themes, defaultColor, wrap, transformers, }?: ShikiConfig): Promise<ShikiHighlighter>;
package/dist/shiki.js CHANGED
@@ -3,21 +3,13 @@ import {
3
3
  getHighlighter,
4
4
  isSpecialLang
5
5
  } from "shiki";
6
- import { visit } from "unist-util-visit";
7
- const ASTRO_COLOR_REPLACEMENTS = {
8
- "--astro-code-foreground": "--astro-code-color-text",
9
- "--astro-code-background": "--astro-code-color-background"
10
- };
11
- const COLOR_REPLACEMENT_REGEX = new RegExp(
12
- `${Object.keys(ASTRO_COLOR_REPLACEMENTS).join("|")}`,
13
- "g"
14
- );
15
6
  let _cssVariablesTheme;
16
7
  const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({ variablePrefix: "--astro-code-" }));
17
8
  async function createShikiHighlighter({
18
9
  langs = [],
19
10
  theme = "github-dark",
20
11
  themes = {},
12
+ defaultColor,
21
13
  wrap = false,
22
14
  transformers = []
23
15
  } = {}) {
@@ -43,6 +35,7 @@ async function createShikiHighlighter({
43
35
  const inline = options?.inline ?? false;
44
36
  return highlighter.codeToHtml(code, {
45
37
  ...themeOptions,
38
+ defaultColor,
46
39
  lang,
47
40
  // NOTE: while we can spread `options.attributes` here so that Shiki can auto-serialize this as rendered
48
41
  // attributes on the top-level tag, it's not clear whether it is fine to pass all attributes as meta, as
@@ -92,19 +85,6 @@ async function createShikiHighlighter({
92
85
  if (inline) {
93
86
  return node.children[0];
94
87
  }
95
- },
96
- root(node) {
97
- if (Object.values(themes).length) {
98
- return;
99
- }
100
- const themeName = typeof theme === "string" ? theme : theme.name;
101
- if (themeName === "css-variables") {
102
- visit(node, "element", (child) => {
103
- if (child.properties?.style) {
104
- child.properties.style = replaceCssVariables(child.properties.style);
105
- }
106
- });
107
- }
108
88
  }
109
89
  },
110
90
  ...transformers
@@ -116,9 +96,6 @@ async function createShikiHighlighter({
116
96
  function normalizePropAsString(value) {
117
97
  return Array.isArray(value) ? value.join(" ") : value;
118
98
  }
119
- function replaceCssVariables(str) {
120
- return str.replace(COLOR_REPLACEMENT_REGEX, (match) => ASTRO_COLOR_REPLACEMENTS[match] || match);
121
- }
122
99
  export {
123
100
  createShikiHighlighter
124
101
  };
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import type * as mdast from 'mdast';
3
3
  import type { Options as RemarkRehypeOptions } from 'remark-rehype';
4
4
  import type { BuiltinTheme, LanguageRegistration, ShikiTransformer, ThemeRegistration, ThemeRegistrationRaw } from 'shiki';
5
5
  import type * as unified from 'unified';
6
- import type { VFile } from 'vfile';
6
+ import type { DataMap, VFile } from 'vfile';
7
7
  export type { Node } from 'unist';
8
8
  export type MarkdownAstroData = {
9
9
  frontmatter: Record<string, any>;
@@ -18,6 +18,7 @@ export interface ShikiConfig {
18
18
  langs?: LanguageRegistration[];
19
19
  theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
20
20
  themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
21
+ defaultColor?: 'light' | 'dark' | string | false;
21
22
  wrap?: boolean | null;
22
23
  transformers?: ShikiTransformer[];
23
24
  }
@@ -51,7 +52,7 @@ export interface MarkdownHeading {
51
52
  text: string;
52
53
  }
53
54
  export interface MarkdownVFile extends VFile {
54
- data: {
55
+ data: Record<string, unknown> & Partial<DataMap> & {
55
56
  __astroHeadings?: MarkdownHeading[];
56
57
  imagePaths?: Set<string>;
57
58
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "5.1.1",
3
+ "version": "6.0.0-alpha.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
@@ -36,20 +36,20 @@
36
36
  "remark-gfm": "^4.0.0",
37
37
  "remark-parse": "^11.0.0",
38
38
  "remark-rehype": "^11.1.0",
39
- "remark-smartypants": "^3.0.1",
40
- "shiki": "^1.9.0",
39
+ "remark-smartypants": "^3.0.2",
40
+ "shiki": "^1.14.1",
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.1",
45
+ "vfile": "^6.0.2",
46
46
  "@astrojs/prism": "3.1.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/estree": "^1.0.5",
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
54
  "mdast-util-mdx-expression": "^2.0.0",
55
55
  "astro-scripts": "0.0.14"