@expressive-code/plugin-shiki
Advanced tools
Comparing version 0.38.2 to 0.38.3
import { ExpressiveCodeTheme, ExpressiveCodePlugin } from '@expressive-code/core'; | ||
import { MaybeGetter, MaybeArray, LanguageRegistration as LanguageRegistration$1, ShikiTransformer, bundledThemes } from 'shiki'; | ||
type IRawRepository = LanguageRegistration$1['repository']; | ||
type IShikiRawRepository = LanguageRegistration$1['repository']; | ||
type IShikiRawRule = IShikiRawRepository[keyof IShikiRawRepository]; | ||
type ILocation = IShikiRawRepository['$vscodeTextmateLocation']; | ||
interface ILocatable { | ||
readonly $vscodeTextmateLocation?: ILocation | undefined; | ||
} | ||
interface IRawRepositoryMap { | ||
[name: string]: IRawRule; | ||
} | ||
type IRawRepository = IRawRepositoryMap & ILocatable; | ||
interface IRawCapturesMap { | ||
[captureId: string]: IRawRule; | ||
} | ||
type IRawCaptures = IRawCapturesMap & ILocatable; | ||
interface IRawRule extends Omit<IShikiRawRule, 'applyEndPatternLast' | 'captures' | 'patterns'> { | ||
readonly applyEndPatternLast?: boolean | number | undefined; | ||
readonly captures?: IRawCaptures | undefined; | ||
readonly comment?: string | undefined; | ||
readonly patterns?: IRawRule[] | undefined; | ||
} | ||
/** | ||
* A less strict version of Shiki's `LanguageRegistration` interface that aligns better with | ||
* actual grammars found in the wild. This version attempts to reduce the amount | ||
* of type errors that would occur when importing and adding external grammars, | ||
* while still being supported by the language processing code. | ||
*/ | ||
interface LanguageRegistration extends Omit<LanguageRegistration$1, 'repository'> { | ||
@@ -6,0 +31,0 @@ repository?: IRawRepository | undefined; |
// src/index.ts | ||
import { ExpressiveCodeTheme as ExpressiveCodeTheme2, InlineStyleAnnotation } from "@expressive-code/core"; | ||
import { bundledThemes } from "shiki"; | ||
// src/highlighter.ts | ||
import { getStableObjectHash } from "@expressive-code/core"; | ||
import { bundledLanguages, createHighlighter, isSpecialLang } from "shiki"; | ||
import { getStableObjectHash } from "@expressive-code/core"; | ||
// src/languages.ts | ||
function getNestedCodeBlockInjectionLangs(lang) { | ||
const injectionLangs = []; | ||
const langNameKey = lang.name.replace(/[^a-zA-Z0-9]/g, "_"); | ||
const langNameAndAliases = [lang.name, ...lang.aliases ?? []]; | ||
injectionLangs.push({ | ||
name: `${lang.name}-fenced-md`, | ||
scopeName: `source.${lang.name}.fenced_code_block`, | ||
injectTo: ["text.html.markdown"], | ||
injectionSelector: "L:text.html.markdown", | ||
patterns: [ | ||
{ | ||
include: `#fenced_code_block_${langNameKey}` | ||
} | ||
], | ||
repository: { | ||
[`fenced_code_block_${langNameKey}`]: { | ||
begin: `(^|\\G)(\\s*)(\`{3,}|~{3,})\\s*(?i:(${langNameAndAliases.join("|")})((\\s+|:|,|\\{|\\?)[^\`]*)?$)`, | ||
beginCaptures: { | ||
3: { | ||
name: "punctuation.definition.markdown" | ||
}, | ||
4: { | ||
name: "fenced_code.block.language.markdown" | ||
}, | ||
5: { | ||
name: "fenced_code.block.language.attributes.markdown" | ||
} | ||
}, | ||
end: "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$", | ||
endCaptures: { | ||
3: { | ||
name: "punctuation.definition.markdown" | ||
} | ||
}, | ||
name: "markup.fenced_code.block.markdown", | ||
patterns: [ | ||
{ | ||
begin: "(^|\\G)(\\s*)(.*)", | ||
while: "(^|\\G)(?!\\s*([`~]{3,})\\s*$)", | ||
contentName: `meta.embedded.block.${lang.name}`, | ||
patterns: [ | ||
{ | ||
include: lang.scopeName | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
injectionLangs.push({ | ||
name: `${lang.name}-fenced-mdx`, | ||
scopeName: `source.${lang.name}.fenced_code_block`, | ||
injectTo: ["source.mdx"], | ||
injectionSelector: "L:source.mdx", | ||
patterns: [ | ||
{ | ||
include: `#fenced_code_block_${langNameKey}` | ||
} | ||
], | ||
repository: { | ||
[`fenced_code_block_${langNameKey}`]: { | ||
begin: `(?:^|\\G)[\\t ]*(\`{3,})(?:[\\t ]*((?i:(?:.*\\.)?${langNameAndAliases.join("|")}))(?:[\\t ]+((?:[^\\n\\r\`])+))?)(?:[\\t ]*$)`, | ||
beginCaptures: { | ||
1: { | ||
name: "string.other.begin.code.fenced.mdx" | ||
}, | ||
2: { | ||
name: "entity.name.function.mdx", | ||
patterns: [ | ||
{ | ||
include: "#markdown-string" | ||
} | ||
] | ||
}, | ||
3: { | ||
patterns: [ | ||
{ | ||
include: "#markdown-string" | ||
} | ||
] | ||
} | ||
}, | ||
end: "(?:^|\\G)[\\t ]*(\\1)(?:[\\t ]*$)", | ||
endCaptures: { | ||
1: { | ||
name: "string.other.end.code.fenced.mdx" | ||
} | ||
}, | ||
name: `markup.code.${lang.name}.mdx`, | ||
patterns: [ | ||
{ | ||
begin: "(^|\\G)(\\s*)(.*)", | ||
contentName: `meta.embedded.${lang.name}`, | ||
patterns: [ | ||
{ | ||
include: lang.scopeName | ||
} | ||
], | ||
while: "(^|\\G)(?![\\t ]*([`~]{3,})[\\t ]*$)" | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
return injectionLangs; | ||
} | ||
// src/highlighter.ts | ||
var highlighterPromiseByConfig = /* @__PURE__ */ new Map(); | ||
@@ -87,3 +199,3 @@ var themeCacheKeysByStyleVariants = /* @__PURE__ */ new WeakMap(); | ||
if (registrations.size) | ||
await highlighter.loadLanguage(...registrations.values()); | ||
await highlighter.loadLanguage(...[...registrations.values()]); | ||
}); | ||
@@ -124,109 +236,2 @@ return errors; | ||
} | ||
function getNestedCodeBlockInjectionLangs(lang) { | ||
const injectionLangs = []; | ||
const langNameKey = lang.name.replace(/[^a-zA-Z0-9]/g, "_"); | ||
const langNameAndAliases = [lang.name, ...lang.aliases ?? []]; | ||
injectionLangs.push({ | ||
name: `${lang.name}-fenced-md`, | ||
scopeName: `source.${lang.name}.fenced_code_block`, | ||
injectTo: ["text.html.markdown"], | ||
injectionSelector: "L:text.html.markdown", | ||
patterns: [ | ||
{ | ||
include: `#fenced_code_block_${langNameKey}` | ||
} | ||
], | ||
repository: { | ||
[`fenced_code_block_${langNameKey}`]: { | ||
begin: `(^|\\G)(\\s*)(\`{3,}|~{3,})\\s*(?i:(${langNameAndAliases.join("|")})((\\s+|:|,|\\{|\\?)[^\`]*)?$)`, | ||
beginCaptures: { | ||
3: { | ||
name: "punctuation.definition.markdown" | ||
}, | ||
4: { | ||
name: "fenced_code.block.language.markdown" | ||
}, | ||
5: { | ||
name: "fenced_code.block.language.attributes.markdown" | ||
} | ||
}, | ||
end: "(^|\\G)(\\2|\\s{0,3})(\\3)\\s*$", | ||
endCaptures: { | ||
3: { | ||
name: "punctuation.definition.markdown" | ||
} | ||
}, | ||
name: "markup.fenced_code.block.markdown", | ||
patterns: [ | ||
{ | ||
begin: "(^|\\G)(\\s*)(.*)", | ||
while: "(^|\\G)(?!\\s*([`~]{3,})\\s*$)", | ||
contentName: `meta.embedded.block.${lang.name}`, | ||
patterns: [ | ||
{ | ||
include: lang.scopeName | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
injectionLangs.push({ | ||
name: `${lang.name}-fenced-mdx`, | ||
scopeName: `source.${lang.name}.fenced_code_block`, | ||
injectTo: ["source.mdx"], | ||
injectionSelector: "L:source.mdx", | ||
patterns: [ | ||
{ | ||
include: `#fenced_code_block_${langNameKey}` | ||
} | ||
], | ||
repository: { | ||
[`fenced_code_block_${langNameKey}`]: { | ||
begin: `(?:^|\\G)[\\t ]*(\`{3,})(?:[\\t ]*((?i:(?:.*\\.)?${langNameAndAliases.join("|")}))(?:[\\t ]+((?:[^\\n\\r\`])+))?)(?:[\\t ]*$)`, | ||
beginCaptures: { | ||
1: { | ||
name: "string.other.begin.code.fenced.mdx" | ||
}, | ||
2: { | ||
name: "entity.name.function.mdx", | ||
patterns: [ | ||
{ | ||
include: "#markdown-string" | ||
} | ||
] | ||
}, | ||
3: { | ||
patterns: [ | ||
{ | ||
include: "#markdown-string" | ||
} | ||
] | ||
} | ||
}, | ||
end: "(?:^|\\G)[\\t ]*(\\1)(?:[\\t ]*$)", | ||
endCaptures: { | ||
1: { | ||
name: "string.other.end.code.fenced.mdx" | ||
} | ||
}, | ||
name: `markup.code.${lang.name}.mdx`, | ||
patterns: [ | ||
{ | ||
begin: "(^|\\G)(\\s*)(.*)", | ||
contentName: `meta.embedded.${lang.name}`, | ||
patterns: [ | ||
{ | ||
include: lang.scopeName | ||
} | ||
], | ||
while: "(^|\\G)(?![\\t ]*([`~]{3,})[\\t ]*$)" | ||
} | ||
] | ||
} | ||
} | ||
}); | ||
return injectionLangs; | ||
} | ||
@@ -325,3 +330,2 @@ // src/transformers.ts | ||
// src/index.ts | ||
import { bundledThemes } from "shiki"; | ||
async function loadShikiTheme(bundledThemeName) { | ||
@@ -328,0 +332,0 @@ const shikiTheme = (await bundledThemes[bundledThemeName]()).default; |
{ | ||
"name": "@expressive-code/plugin-shiki", | ||
"version": "0.38.2", | ||
"version": "0.38.3", | ||
"description": "Shiki syntax highlighting plugin for Expressive Code, a text marking & annotation engine for presenting source code on the web.", | ||
@@ -25,3 +25,3 @@ "keywords": [], | ||
"dependencies": { | ||
"@expressive-code/core": "^0.38.2", | ||
"@expressive-code/core": "^0.38.3", | ||
"shiki": "^1.22.2" | ||
@@ -28,0 +28,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62976
537
5
33
+ Added@shikijs/vscode-textmate@9.3.0(transitive)
+ Addedhast-util-to-html@9.0.3(transitive)
- Removed@shikijs/vscode-textmate@9.3.1(transitive)
- Removedhast-util-to-html@9.0.4(transitive)