@mistweaverco/mdsvex-shiki 1.0.15 → 1.0.17
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/README.md +25 -3
- package/index.cjs +64 -136
- package/index.d.ts +7 -1
- package/index.js +64 -136
- package/package.json +1 -1
- package/styles.css +5 -2
package/README.md
CHANGED
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
# mdsvex-shiki
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A highlighter for mdsvex using Shiki with
|
|
4
|
+
support for most [common transformers][shiki-transformers] out of the box.
|
|
5
|
+
|
|
6
|
+
Why? Because mdsvex's built-in Prism highlighter is
|
|
7
|
+
limited in features and customization options.
|
|
8
|
+
|
|
9
|
+
We needed a better solution for our SvelteKit projects,
|
|
10
|
+
so we created this package to fill the gap.
|
|
11
|
+
|
|
12
|
+
<img width="945" height="874" alt="Screenshot" src="https://github.com/user-attachments/assets/c717f559-ae96-4372-a1ac-3eba3d4db340" />
|
|
4
13
|
|
|
5
14
|
## Installation
|
|
6
15
|
|
|
7
|
-
Using
|
|
16
|
+
Using your package manager of choice, run:
|
|
8
17
|
|
|
9
18
|
```bash
|
|
10
|
-
|
|
19
|
+
# npm
|
|
20
|
+
npm install @mistweaverco/mdsvex-shiki@v1.0.16
|
|
21
|
+
|
|
22
|
+
# yarn
|
|
23
|
+
yarn add @mistweaverco/mdsvex-shiki@v1.0.
|
|
24
|
+
|
|
25
|
+
# bun
|
|
26
|
+
bun add @mistweaverco/mdsvex-shiki@v1.0.16
|
|
27
|
+
|
|
28
|
+
# pnpm
|
|
29
|
+
pnpm add @mistweaverco/mdsvex-shiki@v1.0.16
|
|
30
|
+
|
|
31
|
+
# deno
|
|
32
|
+
deno add npm:@mistweaverco/mdsvex-shiki@v1.0.16
|
|
11
33
|
```
|
|
12
34
|
|
|
13
35
|
## Configuration
|
package/index.cjs
CHANGED
|
@@ -4837,20 +4837,20 @@ var mdsvexWrapItUpTransformer = (lang, codeText, disableCopyButton) => {
|
|
|
4837
4837
|
tabindex: "0"
|
|
4838
4838
|
},
|
|
4839
4839
|
children: [
|
|
4840
|
-
...children.
|
|
4840
|
+
...children.flatMap((child) => {
|
|
4841
4841
|
if (child.type === "element" && child.tagName === "pre") {
|
|
4842
|
-
return
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4842
|
+
return [
|
|
4843
|
+
{
|
|
4844
|
+
type: "element",
|
|
4845
|
+
tagName: "div",
|
|
4846
|
+
properties: { class: "header" },
|
|
4847
|
+
children: headerChildren
|
|
4848
|
+
},
|
|
4849
|
+
{
|
|
4850
|
+
...child,
|
|
4851
|
+
children: child.children
|
|
4852
|
+
}
|
|
4853
|
+
];
|
|
4854
4854
|
}
|
|
4855
4855
|
return child;
|
|
4856
4856
|
})
|
|
@@ -4878,7 +4878,7 @@ var mdsvexWrapItUpTransformer = (lang, codeText, disableCopyButton) => {
|
|
|
4878
4878
|
};
|
|
4879
4879
|
};
|
|
4880
4880
|
|
|
4881
|
-
// node_modules
|
|
4881
|
+
// node_modules/@shikijs/types/dist/index.mjs
|
|
4882
4882
|
class ShikiError extends Error {
|
|
4883
4883
|
constructor(message) {
|
|
4884
4884
|
super(message);
|
|
@@ -9629,7 +9629,7 @@ function all(parent) {
|
|
|
9629
9629
|
}
|
|
9630
9630
|
return results.join("");
|
|
9631
9631
|
}
|
|
9632
|
-
// node_modules
|
|
9632
|
+
// node_modules/@shikijs/core/dist/index.mjs
|
|
9633
9633
|
function resolveColorReplacements(theme, options) {
|
|
9634
9634
|
const replacements = typeof theme === "string" ? {} : { ...theme.colorReplacements };
|
|
9635
9635
|
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
@@ -9727,34 +9727,6 @@ function createPositionConverter(code) {
|
|
|
9727
9727
|
posToIndex
|
|
9728
9728
|
};
|
|
9729
9729
|
}
|
|
9730
|
-
function guessEmbeddedLanguages(code, _lang, highlighter) {
|
|
9731
|
-
const langs = /* @__PURE__ */ new Set;
|
|
9732
|
-
for (const match of code.matchAll(/:?lang=["']([^"']+)["']/g)) {
|
|
9733
|
-
const lang = match[1].toLowerCase().trim();
|
|
9734
|
-
if (lang)
|
|
9735
|
-
langs.add(lang);
|
|
9736
|
-
}
|
|
9737
|
-
for (const match of code.matchAll(/(?:```|~~~)([\w-]+)/g)) {
|
|
9738
|
-
const lang = match[1].toLowerCase().trim();
|
|
9739
|
-
if (lang)
|
|
9740
|
-
langs.add(lang);
|
|
9741
|
-
}
|
|
9742
|
-
for (const match of code.matchAll(/\\begin\{([\w-]+)\}/g)) {
|
|
9743
|
-
const lang = match[1].toLowerCase().trim();
|
|
9744
|
-
if (lang)
|
|
9745
|
-
langs.add(lang);
|
|
9746
|
-
}
|
|
9747
|
-
for (const match of code.matchAll(/<script\s+(?:type|lang)=["']([^"']+)["']/gi)) {
|
|
9748
|
-
const fullType = match[1].toLowerCase().trim();
|
|
9749
|
-
const lang = fullType.includes("/") ? fullType.split("/").pop() : fullType;
|
|
9750
|
-
if (lang)
|
|
9751
|
-
langs.add(lang);
|
|
9752
|
-
}
|
|
9753
|
-
if (!highlighter)
|
|
9754
|
-
return Array.from(langs);
|
|
9755
|
-
const bundle = highlighter.getBundledLanguages();
|
|
9756
|
-
return Array.from(langs).filter((l) => l && bundle[l]);
|
|
9757
|
-
}
|
|
9758
9730
|
var DEFAULT_COLOR_LIGHT_DARK = "light-dark()";
|
|
9759
9731
|
var COLOR_KEYS = ["color", "background-color"];
|
|
9760
9732
|
function splitToken(token, offsets) {
|
|
@@ -11612,78 +11584,6 @@ function createBundledHighlighter(options) {
|
|
|
11612
11584
|
}
|
|
11613
11585
|
return createHighlighter;
|
|
11614
11586
|
}
|
|
11615
|
-
function makeSingletonHighlighter(createHighlighter) {
|
|
11616
|
-
let _shiki;
|
|
11617
|
-
async function getSingletonHighlighter(options = {}) {
|
|
11618
|
-
if (!_shiki) {
|
|
11619
|
-
_shiki = createHighlighter({
|
|
11620
|
-
...options,
|
|
11621
|
-
themes: [],
|
|
11622
|
-
langs: []
|
|
11623
|
-
});
|
|
11624
|
-
const s = await _shiki;
|
|
11625
|
-
await Promise.all([
|
|
11626
|
-
s.loadTheme(...options.themes || []),
|
|
11627
|
-
s.loadLanguage(...options.langs || [])
|
|
11628
|
-
]);
|
|
11629
|
-
return s;
|
|
11630
|
-
} else {
|
|
11631
|
-
const s = await _shiki;
|
|
11632
|
-
await Promise.all([
|
|
11633
|
-
s.loadTheme(...options.themes || []),
|
|
11634
|
-
s.loadLanguage(...options.langs || [])
|
|
11635
|
-
]);
|
|
11636
|
-
return s;
|
|
11637
|
-
}
|
|
11638
|
-
}
|
|
11639
|
-
return getSingletonHighlighter;
|
|
11640
|
-
}
|
|
11641
|
-
function createSingletonShorthands(createHighlighter, config) {
|
|
11642
|
-
const getSingletonHighlighter = makeSingletonHighlighter(createHighlighter);
|
|
11643
|
-
async function get(code, options) {
|
|
11644
|
-
const shiki = await getSingletonHighlighter({
|
|
11645
|
-
langs: [options.lang],
|
|
11646
|
-
themes: "theme" in options ? [options.theme] : Object.values(options.themes)
|
|
11647
|
-
});
|
|
11648
|
-
const langs = await config?.guessEmbeddedLanguages?.(code, options.lang, shiki);
|
|
11649
|
-
if (langs) {
|
|
11650
|
-
await shiki.loadLanguage(...langs);
|
|
11651
|
-
}
|
|
11652
|
-
return shiki;
|
|
11653
|
-
}
|
|
11654
|
-
return {
|
|
11655
|
-
getSingletonHighlighter(options) {
|
|
11656
|
-
return getSingletonHighlighter(options);
|
|
11657
|
-
},
|
|
11658
|
-
async codeToHtml(code, options) {
|
|
11659
|
-
const shiki = await get(code, options);
|
|
11660
|
-
return shiki.codeToHtml(code, options);
|
|
11661
|
-
},
|
|
11662
|
-
async codeToHast(code, options) {
|
|
11663
|
-
const shiki = await get(code, options);
|
|
11664
|
-
return shiki.codeToHast(code, options);
|
|
11665
|
-
},
|
|
11666
|
-
async codeToTokens(code, options) {
|
|
11667
|
-
const shiki = await get(code, options);
|
|
11668
|
-
return shiki.codeToTokens(code, options);
|
|
11669
|
-
},
|
|
11670
|
-
async codeToTokensBase(code, options) {
|
|
11671
|
-
const shiki = await get(code, options);
|
|
11672
|
-
return shiki.codeToTokensBase(code, options);
|
|
11673
|
-
},
|
|
11674
|
-
async codeToTokensWithThemes(code, options) {
|
|
11675
|
-
const shiki = await get(code, options);
|
|
11676
|
-
return shiki.codeToTokensWithThemes(code, options);
|
|
11677
|
-
},
|
|
11678
|
-
async getLastGrammarState(code, options) {
|
|
11679
|
-
const shiki = await getSingletonHighlighter({
|
|
11680
|
-
langs: [options.lang],
|
|
11681
|
-
themes: [options.theme]
|
|
11682
|
-
});
|
|
11683
|
-
return shiki.getLastGrammarState(code, options);
|
|
11684
|
-
}
|
|
11685
|
-
};
|
|
11686
|
-
}
|
|
11687
11587
|
// node_modules/shiki/dist/langs.mjs
|
|
11688
11588
|
var bundledLanguagesInfo = [
|
|
11689
11589
|
{
|
|
@@ -13862,21 +13762,8 @@ var createHighlighter = /* @__PURE__ */ createBundledHighlighter({
|
|
|
13862
13762
|
themes: bundledThemes,
|
|
13863
13763
|
engine: () => createOnigurumaEngine(Promise.resolve().then(() => (init_wasm2(), exports_wasm2)))
|
|
13864
13764
|
});
|
|
13865
|
-
var {
|
|
13866
|
-
codeToHtml: codeToHtml2,
|
|
13867
|
-
codeToHast: codeToHast2,
|
|
13868
|
-
codeToTokens: codeToTokens2,
|
|
13869
|
-
codeToTokensBase: codeToTokensBase2,
|
|
13870
|
-
codeToTokensWithThemes: codeToTokensWithThemes2,
|
|
13871
|
-
getSingletonHighlighter,
|
|
13872
|
-
getLastGrammarState: getLastGrammarState2
|
|
13873
|
-
} = /* @__PURE__ */ createSingletonShorthands(createHighlighter, { guessEmbeddedLanguages });
|
|
13874
13765
|
// src/index.ts
|
|
13875
13766
|
var defaultShikiOptions = {
|
|
13876
|
-
themes: {
|
|
13877
|
-
dark: "catppuccin-mocha",
|
|
13878
|
-
light: "catppuccin-mocha"
|
|
13879
|
-
},
|
|
13880
13767
|
cssVariablePrefix: "--shiki-",
|
|
13881
13768
|
transformers: [
|
|
13882
13769
|
transformerMetaHighlight(),
|
|
@@ -13887,22 +13774,63 @@ var defaultShikiOptions = {
|
|
|
13887
13774
|
transformerNotationErrorLevel()
|
|
13888
13775
|
]
|
|
13889
13776
|
};
|
|
13777
|
+
var defaultThemes = {
|
|
13778
|
+
dark: "catppuccin-mocha",
|
|
13779
|
+
light: "catppuccin-mocha"
|
|
13780
|
+
};
|
|
13781
|
+
var highlighterInstance = null;
|
|
13782
|
+
var highlighterPromise = null;
|
|
13783
|
+
var getHighlighterInstance = async (themes, langs = "all") => {
|
|
13784
|
+
if (highlighterInstance) {
|
|
13785
|
+
return highlighterInstance;
|
|
13786
|
+
}
|
|
13787
|
+
if (highlighterPromise) {
|
|
13788
|
+
return highlighterPromise;
|
|
13789
|
+
}
|
|
13790
|
+
const langsArray = langs === "all" ? Object.keys(bundledLanguages) : langs;
|
|
13791
|
+
let themesArray;
|
|
13792
|
+
if (Array.isArray(themes)) {
|
|
13793
|
+
themesArray = themes;
|
|
13794
|
+
} else if (typeof themes === "object" && "light" in themes && "dark" in themes) {
|
|
13795
|
+
themesArray = [themes.light, themes.dark];
|
|
13796
|
+
} else {
|
|
13797
|
+
themesArray = [themes];
|
|
13798
|
+
}
|
|
13799
|
+
const highlighterOptions = {
|
|
13800
|
+
themes: themesArray,
|
|
13801
|
+
langs: langsArray
|
|
13802
|
+
};
|
|
13803
|
+
highlighterPromise = createHighlighter(highlighterOptions);
|
|
13804
|
+
highlighterInstance = await highlighterPromise;
|
|
13805
|
+
return highlighterInstance;
|
|
13806
|
+
};
|
|
13890
13807
|
var mdsvexShiki = async (config) => {
|
|
13808
|
+
const themes = config.shikiOptions?.themes || defaultThemes;
|
|
13809
|
+
const langs = config.shikiOptions?.langs || "all";
|
|
13891
13810
|
const shikiOptions = {
|
|
13892
13811
|
...defaultShikiOptions,
|
|
13893
13812
|
...config.shikiOptions
|
|
13894
13813
|
};
|
|
13814
|
+
delete shikiOptions.themes;
|
|
13815
|
+
delete shikiOptions.langs;
|
|
13816
|
+
await getHighlighterInstance(themes, langs);
|
|
13895
13817
|
return async (code, lang245) => {
|
|
13896
13818
|
lang245 = lang245 ?? "text";
|
|
13897
|
-
|
|
13898
|
-
|
|
13899
|
-
...defaultShikiOptions.transformers,
|
|
13900
|
-
...shikiOptions.transformers
|
|
13819
|
+
const highlighter = await getHighlighterInstance(themes, langs);
|
|
13820
|
+
const transformers = [
|
|
13821
|
+
...defaultShikiOptions.transformers || [],
|
|
13822
|
+
...shikiOptions.transformers || []
|
|
13901
13823
|
];
|
|
13902
|
-
if (
|
|
13903
|
-
|
|
13904
|
-
}
|
|
13905
|
-
|
|
13824
|
+
if (!transformers.find((t) => t.name === "transformerMdsvexWrapItUp")) {
|
|
13825
|
+
transformers.push(mdsvexWrapItUpTransformer(lang245, code, config.disableCopyButton));
|
|
13826
|
+
}
|
|
13827
|
+
const html5 = highlighter.codeToHtml(code, {
|
|
13828
|
+
...shikiOptions,
|
|
13829
|
+
lang: lang245,
|
|
13830
|
+
transformers,
|
|
13831
|
+
themes: typeof themes === "object" && !Array.isArray(themes) ? themes : undefined
|
|
13832
|
+
});
|
|
13833
|
+
return escapeHTML(html5);
|
|
13906
13834
|
};
|
|
13907
13835
|
};
|
|
13908
13836
|
var src_default = mdsvexShiki;
|
package/index.d.ts
CHANGED
|
@@ -19,7 +19,13 @@ export type HighlighterOptions = {
|
|
|
19
19
|
displayTitle?: boolean;
|
|
20
20
|
displayLanguage?: boolean;
|
|
21
21
|
disableCopyButton?: boolean;
|
|
22
|
-
shikiOptions?: Partial<CodeToHastOptions<BundledLanguage, BundledTheme
|
|
22
|
+
shikiOptions?: Partial<CodeToHastOptions<BundledLanguage, BundledTheme>> & {
|
|
23
|
+
themes?: BundledTheme[] | {
|
|
24
|
+
light: BundledTheme;
|
|
25
|
+
dark: BundledTheme;
|
|
26
|
+
} | BundledTheme;
|
|
27
|
+
langs?: BundledLanguage[] | "all";
|
|
28
|
+
};
|
|
23
29
|
};
|
|
24
30
|
export declare const defaultShikiOptions: Partial<CodeToHastOptions<BundledLanguage, BundledTheme>>;
|
|
25
31
|
export declare const mdsvexShiki: (config: HighlighterOptions) => Promise<(code: string, lang: string) => Promise<string>>;
|
package/index.js
CHANGED
|
@@ -4810,20 +4810,20 @@ var mdsvexWrapItUpTransformer = (lang, codeText, disableCopyButton) => {
|
|
|
4810
4810
|
tabindex: "0"
|
|
4811
4811
|
},
|
|
4812
4812
|
children: [
|
|
4813
|
-
...children.
|
|
4813
|
+
...children.flatMap((child) => {
|
|
4814
4814
|
if (child.type === "element" && child.tagName === "pre") {
|
|
4815
|
-
return
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4815
|
+
return [
|
|
4816
|
+
{
|
|
4817
|
+
type: "element",
|
|
4818
|
+
tagName: "div",
|
|
4819
|
+
properties: { class: "header" },
|
|
4820
|
+
children: headerChildren
|
|
4821
|
+
},
|
|
4822
|
+
{
|
|
4823
|
+
...child,
|
|
4824
|
+
children: child.children
|
|
4825
|
+
}
|
|
4826
|
+
];
|
|
4827
4827
|
}
|
|
4828
4828
|
return child;
|
|
4829
4829
|
})
|
|
@@ -4851,7 +4851,7 @@ var mdsvexWrapItUpTransformer = (lang, codeText, disableCopyButton) => {
|
|
|
4851
4851
|
};
|
|
4852
4852
|
};
|
|
4853
4853
|
|
|
4854
|
-
// node_modules
|
|
4854
|
+
// node_modules/@shikijs/types/dist/index.mjs
|
|
4855
4855
|
class ShikiError extends Error {
|
|
4856
4856
|
constructor(message) {
|
|
4857
4857
|
super(message);
|
|
@@ -9602,7 +9602,7 @@ function all(parent) {
|
|
|
9602
9602
|
}
|
|
9603
9603
|
return results.join("");
|
|
9604
9604
|
}
|
|
9605
|
-
// node_modules
|
|
9605
|
+
// node_modules/@shikijs/core/dist/index.mjs
|
|
9606
9606
|
function resolveColorReplacements(theme, options) {
|
|
9607
9607
|
const replacements = typeof theme === "string" ? {} : { ...theme.colorReplacements };
|
|
9608
9608
|
const themeName = typeof theme === "string" ? theme : theme.name;
|
|
@@ -9700,34 +9700,6 @@ function createPositionConverter(code) {
|
|
|
9700
9700
|
posToIndex
|
|
9701
9701
|
};
|
|
9702
9702
|
}
|
|
9703
|
-
function guessEmbeddedLanguages(code, _lang, highlighter) {
|
|
9704
|
-
const langs = /* @__PURE__ */ new Set;
|
|
9705
|
-
for (const match of code.matchAll(/:?lang=["']([^"']+)["']/g)) {
|
|
9706
|
-
const lang = match[1].toLowerCase().trim();
|
|
9707
|
-
if (lang)
|
|
9708
|
-
langs.add(lang);
|
|
9709
|
-
}
|
|
9710
|
-
for (const match of code.matchAll(/(?:```|~~~)([\w-]+)/g)) {
|
|
9711
|
-
const lang = match[1].toLowerCase().trim();
|
|
9712
|
-
if (lang)
|
|
9713
|
-
langs.add(lang);
|
|
9714
|
-
}
|
|
9715
|
-
for (const match of code.matchAll(/\\begin\{([\w-]+)\}/g)) {
|
|
9716
|
-
const lang = match[1].toLowerCase().trim();
|
|
9717
|
-
if (lang)
|
|
9718
|
-
langs.add(lang);
|
|
9719
|
-
}
|
|
9720
|
-
for (const match of code.matchAll(/<script\s+(?:type|lang)=["']([^"']+)["']/gi)) {
|
|
9721
|
-
const fullType = match[1].toLowerCase().trim();
|
|
9722
|
-
const lang = fullType.includes("/") ? fullType.split("/").pop() : fullType;
|
|
9723
|
-
if (lang)
|
|
9724
|
-
langs.add(lang);
|
|
9725
|
-
}
|
|
9726
|
-
if (!highlighter)
|
|
9727
|
-
return Array.from(langs);
|
|
9728
|
-
const bundle = highlighter.getBundledLanguages();
|
|
9729
|
-
return Array.from(langs).filter((l) => l && bundle[l]);
|
|
9730
|
-
}
|
|
9731
9703
|
var DEFAULT_COLOR_LIGHT_DARK = "light-dark()";
|
|
9732
9704
|
var COLOR_KEYS = ["color", "background-color"];
|
|
9733
9705
|
function splitToken(token, offsets) {
|
|
@@ -11585,78 +11557,6 @@ function createBundledHighlighter(options) {
|
|
|
11585
11557
|
}
|
|
11586
11558
|
return createHighlighter;
|
|
11587
11559
|
}
|
|
11588
|
-
function makeSingletonHighlighter(createHighlighter) {
|
|
11589
|
-
let _shiki;
|
|
11590
|
-
async function getSingletonHighlighter(options = {}) {
|
|
11591
|
-
if (!_shiki) {
|
|
11592
|
-
_shiki = createHighlighter({
|
|
11593
|
-
...options,
|
|
11594
|
-
themes: [],
|
|
11595
|
-
langs: []
|
|
11596
|
-
});
|
|
11597
|
-
const s = await _shiki;
|
|
11598
|
-
await Promise.all([
|
|
11599
|
-
s.loadTheme(...options.themes || []),
|
|
11600
|
-
s.loadLanguage(...options.langs || [])
|
|
11601
|
-
]);
|
|
11602
|
-
return s;
|
|
11603
|
-
} else {
|
|
11604
|
-
const s = await _shiki;
|
|
11605
|
-
await Promise.all([
|
|
11606
|
-
s.loadTheme(...options.themes || []),
|
|
11607
|
-
s.loadLanguage(...options.langs || [])
|
|
11608
|
-
]);
|
|
11609
|
-
return s;
|
|
11610
|
-
}
|
|
11611
|
-
}
|
|
11612
|
-
return getSingletonHighlighter;
|
|
11613
|
-
}
|
|
11614
|
-
function createSingletonShorthands(createHighlighter, config) {
|
|
11615
|
-
const getSingletonHighlighter = makeSingletonHighlighter(createHighlighter);
|
|
11616
|
-
async function get(code, options) {
|
|
11617
|
-
const shiki = await getSingletonHighlighter({
|
|
11618
|
-
langs: [options.lang],
|
|
11619
|
-
themes: "theme" in options ? [options.theme] : Object.values(options.themes)
|
|
11620
|
-
});
|
|
11621
|
-
const langs = await config?.guessEmbeddedLanguages?.(code, options.lang, shiki);
|
|
11622
|
-
if (langs) {
|
|
11623
|
-
await shiki.loadLanguage(...langs);
|
|
11624
|
-
}
|
|
11625
|
-
return shiki;
|
|
11626
|
-
}
|
|
11627
|
-
return {
|
|
11628
|
-
getSingletonHighlighter(options) {
|
|
11629
|
-
return getSingletonHighlighter(options);
|
|
11630
|
-
},
|
|
11631
|
-
async codeToHtml(code, options) {
|
|
11632
|
-
const shiki = await get(code, options);
|
|
11633
|
-
return shiki.codeToHtml(code, options);
|
|
11634
|
-
},
|
|
11635
|
-
async codeToHast(code, options) {
|
|
11636
|
-
const shiki = await get(code, options);
|
|
11637
|
-
return shiki.codeToHast(code, options);
|
|
11638
|
-
},
|
|
11639
|
-
async codeToTokens(code, options) {
|
|
11640
|
-
const shiki = await get(code, options);
|
|
11641
|
-
return shiki.codeToTokens(code, options);
|
|
11642
|
-
},
|
|
11643
|
-
async codeToTokensBase(code, options) {
|
|
11644
|
-
const shiki = await get(code, options);
|
|
11645
|
-
return shiki.codeToTokensBase(code, options);
|
|
11646
|
-
},
|
|
11647
|
-
async codeToTokensWithThemes(code, options) {
|
|
11648
|
-
const shiki = await get(code, options);
|
|
11649
|
-
return shiki.codeToTokensWithThemes(code, options);
|
|
11650
|
-
},
|
|
11651
|
-
async getLastGrammarState(code, options) {
|
|
11652
|
-
const shiki = await getSingletonHighlighter({
|
|
11653
|
-
langs: [options.lang],
|
|
11654
|
-
themes: [options.theme]
|
|
11655
|
-
});
|
|
11656
|
-
return shiki.getLastGrammarState(code, options);
|
|
11657
|
-
}
|
|
11658
|
-
};
|
|
11659
|
-
}
|
|
11660
11560
|
// node_modules/shiki/dist/langs.mjs
|
|
11661
11561
|
var bundledLanguagesInfo = [
|
|
11662
11562
|
{
|
|
@@ -13835,21 +13735,8 @@ var createHighlighter = /* @__PURE__ */ createBundledHighlighter({
|
|
|
13835
13735
|
themes: bundledThemes,
|
|
13836
13736
|
engine: () => createOnigurumaEngine(Promise.resolve().then(() => (init_wasm2(), exports_wasm2)))
|
|
13837
13737
|
});
|
|
13838
|
-
var {
|
|
13839
|
-
codeToHtml: codeToHtml2,
|
|
13840
|
-
codeToHast: codeToHast2,
|
|
13841
|
-
codeToTokens: codeToTokens2,
|
|
13842
|
-
codeToTokensBase: codeToTokensBase2,
|
|
13843
|
-
codeToTokensWithThemes: codeToTokensWithThemes2,
|
|
13844
|
-
getSingletonHighlighter,
|
|
13845
|
-
getLastGrammarState: getLastGrammarState2
|
|
13846
|
-
} = /* @__PURE__ */ createSingletonShorthands(createHighlighter, { guessEmbeddedLanguages });
|
|
13847
13738
|
// src/index.ts
|
|
13848
13739
|
var defaultShikiOptions = {
|
|
13849
|
-
themes: {
|
|
13850
|
-
dark: "catppuccin-mocha",
|
|
13851
|
-
light: "catppuccin-mocha"
|
|
13852
|
-
},
|
|
13853
13740
|
cssVariablePrefix: "--shiki-",
|
|
13854
13741
|
transformers: [
|
|
13855
13742
|
transformerMetaHighlight(),
|
|
@@ -13860,22 +13747,63 @@ var defaultShikiOptions = {
|
|
|
13860
13747
|
transformerNotationErrorLevel()
|
|
13861
13748
|
]
|
|
13862
13749
|
};
|
|
13750
|
+
var defaultThemes = {
|
|
13751
|
+
dark: "catppuccin-mocha",
|
|
13752
|
+
light: "catppuccin-mocha"
|
|
13753
|
+
};
|
|
13754
|
+
var highlighterInstance = null;
|
|
13755
|
+
var highlighterPromise = null;
|
|
13756
|
+
var getHighlighterInstance = async (themes, langs = "all") => {
|
|
13757
|
+
if (highlighterInstance) {
|
|
13758
|
+
return highlighterInstance;
|
|
13759
|
+
}
|
|
13760
|
+
if (highlighterPromise) {
|
|
13761
|
+
return highlighterPromise;
|
|
13762
|
+
}
|
|
13763
|
+
const langsArray = langs === "all" ? Object.keys(bundledLanguages) : langs;
|
|
13764
|
+
let themesArray;
|
|
13765
|
+
if (Array.isArray(themes)) {
|
|
13766
|
+
themesArray = themes;
|
|
13767
|
+
} else if (typeof themes === "object" && "light" in themes && "dark" in themes) {
|
|
13768
|
+
themesArray = [themes.light, themes.dark];
|
|
13769
|
+
} else {
|
|
13770
|
+
themesArray = [themes];
|
|
13771
|
+
}
|
|
13772
|
+
const highlighterOptions = {
|
|
13773
|
+
themes: themesArray,
|
|
13774
|
+
langs: langsArray
|
|
13775
|
+
};
|
|
13776
|
+
highlighterPromise = createHighlighter(highlighterOptions);
|
|
13777
|
+
highlighterInstance = await highlighterPromise;
|
|
13778
|
+
return highlighterInstance;
|
|
13779
|
+
};
|
|
13863
13780
|
var mdsvexShiki = async (config) => {
|
|
13781
|
+
const themes = config.shikiOptions?.themes || defaultThemes;
|
|
13782
|
+
const langs = config.shikiOptions?.langs || "all";
|
|
13864
13783
|
const shikiOptions = {
|
|
13865
13784
|
...defaultShikiOptions,
|
|
13866
13785
|
...config.shikiOptions
|
|
13867
13786
|
};
|
|
13787
|
+
delete shikiOptions.themes;
|
|
13788
|
+
delete shikiOptions.langs;
|
|
13789
|
+
await getHighlighterInstance(themes, langs);
|
|
13868
13790
|
return async (code, lang245) => {
|
|
13869
13791
|
lang245 = lang245 ?? "text";
|
|
13870
|
-
|
|
13871
|
-
|
|
13872
|
-
...defaultShikiOptions.transformers,
|
|
13873
|
-
...shikiOptions.transformers
|
|
13792
|
+
const highlighter = await getHighlighterInstance(themes, langs);
|
|
13793
|
+
const transformers = [
|
|
13794
|
+
...defaultShikiOptions.transformers || [],
|
|
13795
|
+
...shikiOptions.transformers || []
|
|
13874
13796
|
];
|
|
13875
|
-
if (
|
|
13876
|
-
|
|
13877
|
-
}
|
|
13878
|
-
|
|
13797
|
+
if (!transformers.find((t) => t.name === "transformerMdsvexWrapItUp")) {
|
|
13798
|
+
transformers.push(mdsvexWrapItUpTransformer(lang245, code, config.disableCopyButton));
|
|
13799
|
+
}
|
|
13800
|
+
const html5 = highlighter.codeToHtml(code, {
|
|
13801
|
+
...shikiOptions,
|
|
13802
|
+
lang: lang245,
|
|
13803
|
+
transformers,
|
|
13804
|
+
themes: typeof themes === "object" && !Array.isArray(themes) ? themes : undefined
|
|
13805
|
+
});
|
|
13806
|
+
return escapeHTML(html5);
|
|
13879
13807
|
};
|
|
13880
13808
|
};
|
|
13881
13809
|
var src_default = mdsvexShiki;
|
package/package.json
CHANGED
package/styles.css
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
.mdsvex-shiki {
|
|
28
|
-
padding:
|
|
28
|
+
padding: 12px 20px;
|
|
29
29
|
background-color: var(--shiki-dark-bg);
|
|
30
30
|
position: relative;
|
|
31
31
|
border: 1px solid var(--shiki-dark-border);
|
|
@@ -56,6 +56,8 @@
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
.mdsvex-shiki .header .language {
|
|
59
|
+
right: 12px;
|
|
60
|
+
top: 8px;
|
|
59
61
|
color: var(--shiki-dark);
|
|
60
62
|
font-size: 0.875em;
|
|
61
63
|
opacity: 0.7;
|
|
@@ -79,7 +81,8 @@
|
|
|
79
81
|
color: var(--shiki-dark);
|
|
80
82
|
background-color: transparent;
|
|
81
83
|
border: none;
|
|
82
|
-
|
|
84
|
+
right: 6px;
|
|
85
|
+
top: 8px;
|
|
83
86
|
cursor: pointer;
|
|
84
87
|
opacity: 0;
|
|
85
88
|
display: flex;
|