mirror of
https://github.com/quartz-community/syntax-highlighting.git
synced 2026-07-22 02:50:27 +00:00
fix: pack shiki
This commit is contained in:
parent
a327da5f86
commit
8115b6f11b
6 changed files with 21 additions and 9 deletions
5
dist/index.d.ts
vendored
5
dist/index.d.ts
vendored
|
|
@ -19,8 +19,9 @@ declare const SyntaxHighlighting: QuartzTransformerPlugin<Partial<SyntaxHighligh
|
|||
* Shiki transformer that adds `data-token-type` attributes to token spans
|
||||
* based on TextMate scope classification.
|
||||
*
|
||||
* Requires `includeExplanation: "scopeName"` on the Shiki options to have
|
||||
* access to scope data. When scopes are unavailable, tokens are left untouched.
|
||||
* Automatically enables `includeExplanation: "scopeName"` via the `preprocess`
|
||||
* hook so that scope data is available regardless of how the host plugin
|
||||
* (e.g. rehype-pretty-code) invokes shiki.
|
||||
*
|
||||
* This is purely additive — inline styles are preserved as-is. Downstream
|
||||
* consumers (e.g. Quartz Themes) can target `span[data-token-type="keyword"]`
|
||||
|
|
|
|||
4
dist/index.js
vendored
4
dist/index.js
vendored
|
|
@ -28838,6 +28838,9 @@ function classifyToken(token2) {
|
|||
function tokenClassifierTransformer() {
|
||||
return {
|
||||
name: "token-classifier",
|
||||
preprocess(_code, options) {
|
||||
options.includeExplanation = "scopeName";
|
||||
},
|
||||
span(_hast, _line, _col, _lineElement, token2) {
|
||||
const tokenType = classifyToken(token2);
|
||||
if (tokenType) {
|
||||
|
|
@ -28871,7 +28874,6 @@ var SyntaxHighlighting = (userOpts) => {
|
|||
const { clipboard, tokenClassification, ...codeOpts } = opts;
|
||||
const rehypeOpts = { ...codeOpts };
|
||||
if (tokenClassification) {
|
||||
rehypeOpts.includeExplanation = "scopeName";
|
||||
rehypeOpts.transformers = [...rehypeOpts.transformers ?? [], tokenClassifierTransformer()];
|
||||
}
|
||||
return {
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -44,7 +44,8 @@
|
|||
},
|
||||
"peerDependencies": {
|
||||
"@jackyzha0/quartz": "^4.5.2",
|
||||
"preact": "^10.0.0"
|
||||
"preact": "^10.0.0",
|
||||
"shiki": "^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@jackyzha0/quartz": {
|
||||
|
|
@ -52,6 +53,9 @@
|
|||
},
|
||||
"preact": {
|
||||
"optional": false
|
||||
},
|
||||
"shiki": {
|
||||
"optional": false
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { ShikiTransformer, ThemedToken } from "shiki";
|
||||
import type { CodeToHastOptions, ShikiTransformer, ThemedToken } from "shiki";
|
||||
|
||||
const SCOPE_TO_TOKEN: [prefix: string, tokenType: string][] = [
|
||||
// Invalid / error scopes
|
||||
|
|
@ -142,8 +142,9 @@ function classifyToken(token: ThemedToken): string | undefined {
|
|||
* Shiki transformer that adds `data-token-type` attributes to token spans
|
||||
* based on TextMate scope classification.
|
||||
*
|
||||
* Requires `includeExplanation: "scopeName"` on the Shiki options to have
|
||||
* access to scope data. When scopes are unavailable, tokens are left untouched.
|
||||
* Automatically enables `includeExplanation: "scopeName"` via the `preprocess`
|
||||
* hook so that scope data is available regardless of how the host plugin
|
||||
* (e.g. rehype-pretty-code) invokes shiki.
|
||||
*
|
||||
* This is purely additive — inline styles are preserved as-is. Downstream
|
||||
* consumers (e.g. Quartz Themes) can target `span[data-token-type="keyword"]`
|
||||
|
|
@ -152,6 +153,11 @@ function classifyToken(token: ThemedToken): string | undefined {
|
|||
export function tokenClassifierTransformer(): ShikiTransformer {
|
||||
return {
|
||||
name: "token-classifier",
|
||||
preprocess(_code, options) {
|
||||
// Inject includeExplanation at runtime so scope data is populated on
|
||||
// tokens, even when the calling plugin doesn't expose this option.
|
||||
(options as CodeToHastOptions).includeExplanation = "scopeName";
|
||||
},
|
||||
span(_hast, _line, _col, _lineElement, token) {
|
||||
const tokenType = classifyToken(token);
|
||||
if (tokenType) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ export const SyntaxHighlighting: QuartzTransformerPlugin<Partial<SyntaxHighlight
|
|||
const rehypeOpts: CodeOptions = { ...(codeOpts as CodeOptions) };
|
||||
|
||||
if (tokenClassification) {
|
||||
(rehypeOpts as Record<string, unknown>).includeExplanation = "scopeName";
|
||||
rehypeOpts.transformers = [...(rehypeOpts.transformers ?? []), tokenClassifierTransformer()];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue