@astrojs/markdown-remark 6.0.0-beta.2 → 6.0.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/index.js CHANGED
@@ -32,7 +32,8 @@ const markdownConfigDefaults = {
32
32
  theme: "github-dark",
33
33
  themes: {},
34
34
  wrap: false,
35
- transformers: []
35
+ transformers: [],
36
+ langAlias: {}
36
37
  },
37
38
  remarkPlugins: [],
38
39
  rehypePlugins: [],
@@ -6,7 +6,8 @@ const rehypeShiki = (config) => {
6
6
  highlighterAsync ??= createShikiHighlighter({
7
7
  langs: config?.langs,
8
8
  theme: config?.theme,
9
- themes: config?.themes
9
+ themes: config?.themes,
10
+ langAlias: config?.langAlias
10
11
  });
11
12
  const highlighter = await highlighterAsync;
12
13
  await highlightCodeBlocks(tree, (code, language, options) => {
package/dist/shiki.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Root } from 'hast';
2
- import { type LanguageRegistration, type ShikiTransformer, type ThemeRegistration, type ThemeRegistrationRaw } from 'shiki';
2
+ import { type HighlighterCoreOptions, type LanguageRegistration, type ShikiTransformer, type ThemeRegistration, type ThemeRegistrationRaw } from 'shiki';
3
3
  import type { ThemePresets } from './types.js';
4
4
  export interface ShikiHighlighter {
5
5
  codeToHast(code: string, lang?: string, options?: ShikiHighlighterHighlightOptions): Promise<Root>;
@@ -9,6 +9,7 @@ export interface CreateShikiHighlighterOptions {
9
9
  langs?: LanguageRegistration[];
10
10
  theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
11
11
  themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
12
+ langAlias?: HighlighterCoreOptions['langAlias'];
12
13
  }
13
14
  export interface ShikiHighlighterHighlightOptions {
14
15
  /**
@@ -39,4 +40,4 @@ export interface ShikiHighlighterHighlightOptions {
39
40
  */
40
41
  meta?: string;
41
42
  }
42
- export declare function createShikiHighlighter({ langs, theme, themes, }?: CreateShikiHighlighterOptions): Promise<ShikiHighlighter>;
43
+ export declare function createShikiHighlighter({ langs, theme, themes, langAlias, }?: CreateShikiHighlighterOptions): Promise<ShikiHighlighter>;
package/dist/shiki.js CHANGED
@@ -4,24 +4,30 @@ import {
4
4
  isSpecialLang
5
5
  } from "shiki";
6
6
  let _cssVariablesTheme;
7
- const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({ variablePrefix: "--astro-code-" }));
7
+ const cssVariablesTheme = () => _cssVariablesTheme ?? (_cssVariablesTheme = createCssVariablesTheme({
8
+ variablePrefix: "--astro-code-"
9
+ }));
8
10
  async function createShikiHighlighter({
9
11
  langs = [],
10
12
  theme = "github-dark",
11
- themes = {}
13
+ themes = {},
14
+ langAlias = {}
12
15
  } = {}) {
13
16
  theme = theme === "css-variables" ? cssVariablesTheme() : theme;
14
17
  const highlighter = await createHighlighter({
15
18
  langs: ["plaintext", ...langs],
19
+ langAlias,
16
20
  themes: Object.values(themes).length ? Object.values(themes) : [theme]
17
21
  });
18
22
  async function highlight(code, lang = "plaintext", options, to) {
23
+ const resolvedLang = langAlias[lang] ?? lang;
19
24
  const loadedLanguages = highlighter.getLoadedLanguages();
20
- if (!isSpecialLang(lang) && !loadedLanguages.includes(lang)) {
25
+ if (!isSpecialLang(lang) && !loadedLanguages.includes(resolvedLang)) {
21
26
  try {
22
- await highlighter.loadLanguage(lang);
27
+ await highlighter.loadLanguage(resolvedLang);
23
28
  } catch (_err) {
24
- console.warn(`[Shiki] The language "${lang}" doesn't exist, falling back to "plaintext".`);
29
+ const langStr = lang === resolvedLang ? `"${lang}"` : `"${lang}" (aliased to "${resolvedLang}")`;
30
+ console.warn(`[Shiki] The language ${langStr} doesn't exist, falling back to "plaintext".`);
25
31
  lang = "plaintext";
26
32
  }
27
33
  }
@@ -58,7 +64,7 @@ async function createShikiHighlighter({
58
64
  }
59
65
  },
60
66
  line(node) {
61
- if (lang === "diff") {
67
+ if (resolvedLang === "diff") {
62
68
  const innerSpanNode = node.children[0];
63
69
  const innerSpanTextNode = innerSpanNode?.type === "element" && innerSpanNode.children?.[0];
64
70
  if (innerSpanTextNode && innerSpanTextNode.type === "text") {
package/dist/types.d.ts CHANGED
@@ -20,7 +20,7 @@ export type RehypePlugin<PluginParameters extends any[] = any[]> = unified.Plugi
20
20
  export type RehypePlugins = (string | [string, any] | RehypePlugin | [RehypePlugin, any])[];
21
21
  export type RemarkRehype = RemarkRehypeOptions;
22
22
  export type ThemePresets = BuiltinTheme | 'css-variables';
23
- export interface ShikiConfig extends Pick<CreateShikiHighlighterOptions, 'langs' | 'theme' | 'themes'>, Pick<ShikiHighlighterHighlightOptions, 'defaultColor' | 'wrap' | 'transformers'> {
23
+ export interface ShikiConfig extends Pick<CreateShikiHighlighterOptions, 'langs' | 'theme' | 'themes' | 'langAlias'>, Pick<ShikiHighlighterHighlightOptions, 'defaultColor' | 'wrap' | 'transformers'> {
24
24
  }
25
25
  export interface AstroMarkdownOptions {
26
26
  syntaxHighlight?: 'shiki' | 'prism' | false;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@astrojs/markdown-remark",
3
- "version": "6.0.0-beta.2",
3
+ "version": "6.0.0",
4
4
  "type": "module",
5
5
  "author": "withastro",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "https://github.com/withastro/astro.git",
9
+ "url": "git+https://github.com/withastro/astro.git",
10
10
  "directory": "packages/markdown/remark"
11
11
  },
12
12
  "bugs": "https://github.com/withastro/astro/issues",
@@ -37,13 +37,13 @@
37
37
  "remark-parse": "^11.0.0",
38
38
  "remark-rehype": "^11.1.1",
39
39
  "remark-smartypants": "^3.0.2",
40
- "shiki": "^1.21.0",
40
+ "shiki": "^1.23.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
45
  "vfile": "^6.0.3",
46
- "@astrojs/prism": "3.1.0"
46
+ "@astrojs/prism": "3.2.0"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/estree": "^1.0.6",