@shikijs/core 2.4.0 → 2.4.1
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.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.mjs +17 -1
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -283,6 +283,12 @@ declare function createPositionConverter(code: string): {
|
|
|
283
283
|
indexToPos: (index: number) => Position;
|
|
284
284
|
posToIndex: (line: number, character: number) => number;
|
|
285
285
|
};
|
|
286
|
+
/**
|
|
287
|
+
* Guess embedded languages from given code and highlighter.
|
|
288
|
+
*
|
|
289
|
+
* When highlighter is provided, only bundled languages will be included.
|
|
290
|
+
*/
|
|
291
|
+
declare function guessEmbeddedLanguages(code: string, _lang: string | undefined, highlighter?: HighlighterGeneric<any, any>): string[];
|
|
286
292
|
|
|
287
293
|
type DeprecationTarget = 3;
|
|
288
294
|
/**
|
|
@@ -298,4 +304,4 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
|
|
|
298
304
|
*/
|
|
299
305
|
declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
|
|
300
306
|
|
|
301
|
-
export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
|
307
|
+
export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
package/dist/index.d.ts
CHANGED
|
@@ -283,6 +283,12 @@ declare function createPositionConverter(code: string): {
|
|
|
283
283
|
indexToPos: (index: number) => Position;
|
|
284
284
|
posToIndex: (line: number, character: number) => number;
|
|
285
285
|
};
|
|
286
|
+
/**
|
|
287
|
+
* Guess embedded languages from given code and highlighter.
|
|
288
|
+
*
|
|
289
|
+
* When highlighter is provided, only bundled languages will be included.
|
|
290
|
+
*/
|
|
291
|
+
declare function guessEmbeddedLanguages(code: string, _lang: string | undefined, highlighter?: HighlighterGeneric<any, any>): string[];
|
|
286
292
|
|
|
287
293
|
type DeprecationTarget = 3;
|
|
288
294
|
/**
|
|
@@ -298,4 +304,4 @@ declare function enableDeprecationWarnings(emitDeprecation?: DeprecationTarget |
|
|
|
298
304
|
*/
|
|
299
305
|
declare function warnDeprecated(message: string, version?: DeprecationTarget): void;
|
|
300
306
|
|
|
301
|
-
export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
|
307
|
+
export { type CreateSingletonShorthandsOptions, type CssVariablesThemeOptions, type ShorthandsBundle, addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, enableDeprecationWarnings, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
package/dist/index.mjs
CHANGED
|
@@ -172,6 +172,22 @@ function createPositionConverter(code) {
|
|
|
172
172
|
posToIndex
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
+
function guessEmbeddedLanguages(code, _lang, highlighter) {
|
|
176
|
+
const langs = /* @__PURE__ */ new Set();
|
|
177
|
+
for (const match of code.matchAll(/lang=["']([\w-]+)["']/g)) {
|
|
178
|
+
langs.add(match[1]);
|
|
179
|
+
}
|
|
180
|
+
for (const match of code.matchAll(/(?:```|~~~)([\w-]+)/g)) {
|
|
181
|
+
langs.add(match[1]);
|
|
182
|
+
}
|
|
183
|
+
for (const match of code.matchAll(/\\begin\{([\w-]+)\}/g)) {
|
|
184
|
+
langs.add(match[1]);
|
|
185
|
+
}
|
|
186
|
+
if (!highlighter)
|
|
187
|
+
return Array.from(langs);
|
|
188
|
+
const bundle = highlighter.getBundledLanguages();
|
|
189
|
+
return Array.from(langs).filter((l) => l && bundle[l]);
|
|
190
|
+
}
|
|
175
191
|
|
|
176
192
|
class ShikiError extends Error {
|
|
177
193
|
constructor(message) {
|
|
@@ -2246,4 +2262,4 @@ function createCssVariablesTheme(options = {}) {
|
|
|
2246
2262
|
return theme;
|
|
2247
2263
|
}
|
|
2248
2264
|
|
|
2249
|
-
export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
|
2265
|
+
export { addClassToHast, applyColorReplacements, codeToHast, codeToHtml, codeToTokens, codeToTokensBase, codeToTokensWithThemes, createCssVariablesTheme, createHighlighterCore, createHighlighterCoreSync, createJavaScriptRegexEngine, createOnigurumaEngine, createPositionConverter, createShikiInternal, createShikiInternalSync, createSingletonShorthands, createWasmOnigEngine, createdBundledHighlighter, defaultJavaScriptRegexConstructor, getHighlighterCore, getShikiInternal, getSingletonHighlighterCore, getTokenStyleObject, guessEmbeddedLanguages, isNoneTheme, isPlainLang, isSpecialLang, isSpecialTheme, loadWasm, makeSingletonHighlighter, makeSingletonHighlighterCore, normalizeGetter, normalizeTheme, resolveColorReplacements, splitLines, splitToken, splitTokens, stringifyTokenStyle, toArray, tokenizeAnsiWithTheme, tokenizeWithTheme, tokensToHast, transformerDecorations, warnDeprecated };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.4.
|
|
4
|
+
"version": "2.4.1",
|
|
5
5
|
"description": "Core of Shiki",
|
|
6
6
|
"author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"@shikijs/vscode-textmate": "^10.0.2",
|
|
64
64
|
"@types/hast": "^3.0.4",
|
|
65
65
|
"hast-util-to-html": "^9.0.4",
|
|
66
|
-
"@shikijs/engine-javascript": "2.4.
|
|
67
|
-
"@shikijs/
|
|
68
|
-
"@shikijs/
|
|
66
|
+
"@shikijs/engine-javascript": "2.4.1",
|
|
67
|
+
"@shikijs/engine-oniguruma": "2.4.1",
|
|
68
|
+
"@shikijs/types": "2.4.1"
|
|
69
69
|
},
|
|
70
70
|
"scripts": {
|
|
71
71
|
"build": "unbuild",
|