Skip to content

Commit a79cdee

Browse files
Modularize package for export
1 parent ddca723 commit a79cdee

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

packages/mdx/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
"files": [
99
"dist"
1010
],
11+
"exports": {
12+
".": {
13+
"import": "./dist/index.js",
14+
"types": "./dist/index.d.ts"
15+
},
16+
"./plugins": {
17+
"import": "./dist/plugins/index.js",
18+
"types": "./dist/plugins/index.d.ts"
19+
}
20+
},
1121
"type": "module",
1222
"publishConfig": {
1323
"access": "public",

packages/mdx/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './client/index.js';
22
export * from './server/index.js';
33
export * from './types/index.js';
4-
export * from './plugins/index.js';

packages/mdx/src/plugins/rehype/rehypeSyntaxHighlighting.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { Element, Root } from 'hast';
22
import { toString } from 'hast-util-to-string';
3-
import {
4-
createHighlighter,
5-
type Highlighter,
6-
type BuiltinTheme,
7-
type BundledTheme,
8-
type BundledLanguage,
9-
} from 'shiki';
3+
import { createHighlighter, type Highlighter, type BuiltinTheme, type BundledTheme } from 'shiki';
104
import type { Plugin } from 'unified';
115
import { visit } from 'unist-util-visit';
126

13-
import { DEFAULT_LANG_ALIASES, UNIQUE_LANGS, type ShikiLang } from './shiki-constants.js';
7+
import {
8+
DEFAULT_LANG_ALIASES,
9+
SHIKI_THEMES,
10+
UNIQUE_LANGS,
11+
type ShikiLang,
12+
type ShikiTheme,
13+
} from './shiki-constants.js';
1414

1515
const shikiColorReplacements: Partial<Record<BundledTheme, string | Record<string, string>>> = {
1616
'dark-plus': {
@@ -94,10 +94,6 @@ export const rehypeSyntaxHighlighting: Plugin<[RehypeSyntaxHighlightingOptions?]
9494
getLanguage(child, DEFAULT_LANG_ALIASES) ??
9595
'text';
9696

97-
if (!UNIQUE_LANGS.includes(lang)) {
98-
highlighter.loadLanguage(lang as BundledLanguage);
99-
}
100-
10197
try {
10298
const code = toString(node);
10399
const lines = code.split('\n');
@@ -214,4 +210,4 @@ function getLinesToHighlight(node: Element, maxLines: number): number[] {
214210
return Array.from(lineNumbers).sort((a, b) => a - b);
215211
}
216212

217-
export { UNIQUE_LANGS, ShikiLang, DEFAULT_LANG_ALIASES };
213+
export { UNIQUE_LANGS, DEFAULT_LANG_ALIASES, SHIKI_THEMES, ShikiLang, ShikiTheme };

packages/mdx/src/plugins/rehype/shiki-constants.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,68 @@ export const DEFAULT_LANG_ALIASES: Record<string, ShikiLang> = {
318318
};
319319

320320
export const UNIQUE_LANGS = Array.from(new Set(Object.values(DEFAULT_LANG_ALIASES)));
321+
322+
export const SHIKI_THEMES = [
323+
'andromeeda',
324+
'aurora-x',
325+
'ayu-dark',
326+
'catppuccin-frappe',
327+
'catppuccin-latte',
328+
'catppuccin-macchiato',
329+
'catppuccin-mocha',
330+
'dark-plus',
331+
'dracula',
332+
'dracula-soft',
333+
'everforest-dark',
334+
'everforest-light',
335+
'github-dark',
336+
'github-dark-default',
337+
'github-dark-dimmed',
338+
'github-dark-high-contrast',
339+
'github-light',
340+
'github-light-default',
341+
'github-light-high-contrast',
342+
'gruvbox-dark-hard',
343+
'gruvbox-dark-medium',
344+
'gruvbox-dark-soft',
345+
'gruvbox-light-hard',
346+
'gruvbox-light-medium',
347+
'gruvbox-light-soft',
348+
'houston',
349+
'kanagawa-dragon',
350+
'kanagawa-lotus',
351+
'kanagawa-wave',
352+
'laserwave',
353+
'light-plus',
354+
'material-theme',
355+
'material-theme-darker',
356+
'material-theme-lighter',
357+
'material-theme-ocean',
358+
'material-theme-palenight',
359+
'min-dark',
360+
'min-light',
361+
'monokai',
362+
'night-owl',
363+
'nord',
364+
'one-dark-pro',
365+
'one-light',
366+
'plastic',
367+
'poimandres',
368+
'red',
369+
'rose-pine',
370+
'rose-pine-dawn',
371+
'rose-pine-moon',
372+
'slack-dark',
373+
'slack-ochin',
374+
'snazzy-light',
375+
'solarized-dark',
376+
'solarized-light',
377+
'synthwave-84',
378+
'tokyo-night',
379+
'vesper',
380+
'vitesse-black',
381+
'vitesse-dark',
382+
'vitesse-light',
383+
] as const;
384+
385+
export type ShikiTheme = (typeof SHIKI_THEMES)[number];

0 commit comments

Comments
 (0)