Skip to content

Commit b1e201d

Browse files
committed
fixup!
1 parent e982a2f commit b1e201d

4 files changed

Lines changed: 16 additions & 15 deletions

File tree

packages/rehype-shiki/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"devDependencies": {
3434
"cross-env": "catalog:"
3535
}
36-
}
36+
}

packages/rehype-shiki/src/highlighter.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ const DEFAULT_THEME = {
99
...shikiNordTheme,
1010
};
1111

12-
export const getLanguageByName = (language, langs) =>
13-
langs.find(
12+
export const getLanguageByName = (language, langs) => {
13+
const normalized = language.toLowerCase();
14+
15+
return langs.find(
1416
({ name, aliases }) =>
15-
name.toLowerCase() === language.toLowerCase() ||
16-
(aliases !== undefined && aliases.includes(language.toLowerCase()))
17+
name.toLowerCase() === normalized || aliases?.includes(normalized)
1718
);
19+
};
1820

1921
/**
2022
* Factory function to create a syntax highlighter instance with utility methods.

packages/rehype-shiki/src/index.mjs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import createHighlighter, { getLanguageByName } from './highlighter.mjs';
1818

1919
/**
2020
* @typedef {Object} HighlighterOptions
21-
* @property {boolean|Object} [wasm=false] - WebAssembly options for the regex engine
22-
* @property {boolean|import('@shikijs/twoslash').TransformerTwoslashIndexOptions} [twoslash=false] - Twoslash configuration options
21+
* @property {boolean} [wasm=false] - Enable WebAssembly for the regex engine
22+
* @property {boolean} [twoslash=false] - Enable twoslash
23+
* @property {import('@shikijs/twoslash').TransformerTwoslashIndexOptions} [twoslashOptions] - Twoslash configuration options
2324
* @param {import('@shikijs/core').HighlighterCoreOptions} [coreOptions] - Core options for the highlighter.
2425
* @param {import('@shikijs/core').CodeToHastOptions} [highlighterOptions] - Additional options for highlighting.
2526
*/
@@ -31,9 +32,7 @@ import createHighlighter, { getLanguageByName } from './highlighter.mjs';
3132
async function getEngine({ wasm = false }) {
3233
if (wasm) {
3334
const { createOnigurumaEngine } = await import('@shikijs/engine-oniguruma');
34-
return createOnigurumaEngine(
35-
typeof wasm === 'boolean' ? await import('shiki/wasm') : wasm
36-
);
35+
return createOnigurumaEngine(await import('shiki/wasm'));
3736
}
3837

3938
const { createJavaScriptRegexEngine } = await import(
@@ -46,12 +45,12 @@ async function getEngine({ wasm = false }) {
4645
* Configures and returns transformers based on options
4746
* @param {HighlighterOptions} options - Configuration options
4847
*/
49-
async function getTransformers({ twoslash: options = false }) {
48+
async function getTransformers({ twoslash = false, twoslashOptions }) {
5049
const transformers = [];
5150

52-
if (options) {
51+
if (twoslash) {
5352
const { twoslash } = await import('./transformers/twoslash/index.mjs');
54-
transformers.push(twoslash(options));
53+
transformers.push(twoslash(twoslashOptions));
5554
}
5655

5756
return transformers;

packages/rehype-shiki/src/transformers/twoslash/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const compose = ({ token, cursor, popup }) => [
1010
popup,
1111
];
1212

13-
export const twoslash = options =>
13+
export const twoslash = (options = {}) =>
1414
transformerTwoslash({
1515
langs: ['ts', 'js', 'cjs', 'mjs'],
1616
rendererRich: {
@@ -44,5 +44,5 @@ export const twoslash = options =>
4444
},
4545
},
4646
throws: false,
47-
...(typeof options === 'object' ? options : {}),
47+
...options,
4848
});

0 commit comments

Comments
 (0)