-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shortcuts): guess embedded language and auto load in shortcuts
- Loading branch information
Showing
12 changed files
with
138 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { HighlighterGeneric } from '@shikijs/types' | ||
|
||
export function guessEmbeddedLanguages( | ||
code: string, | ||
_lang: string | undefined, | ||
shiki: HighlighterGeneric<any, any>, | ||
): string[] { | ||
const langs = new Set<string>() | ||
// For HTML code blocks like Vue SFC | ||
for (const match of code.matchAll(/lang=["']([\w-]+)["']/g)) { | ||
langs.add(match[1]) | ||
} | ||
// For markdown code blocks | ||
for (const match of code.matchAll(/(?:```|~~~)([\w-]+)/g)) { | ||
langs.add(match[1]) | ||
} | ||
// For latex | ||
for (const match of code.matchAll(/\\begin\{([\w-]+)\}/g)) { | ||
langs.add(match[1]) | ||
} | ||
|
||
// Only include known languages | ||
const bundle = shiki.getBundledLanguages() | ||
return Array.from(langs) | ||
.filter(l => l && bundle[l]) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.