@dr-ishaan/rehype-perfect-code-blocks 2.0.0 → 2.1.0
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/CHANGELOG.md +86 -0
- package/dist/copy-script.d.ts +1 -1
- package/dist/copy-script.d.ts.map +1 -1
- package/dist/copy-script.js +5 -0
- package/dist/copy-script.js.map +1 -1
- package/dist/dev-warnings.d.ts +36 -0
- package/dist/dev-warnings.d.ts.map +1 -0
- package/dist/dev-warnings.js +95 -0
- package/dist/dev-warnings.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/math.d.ts +92 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +229 -0
- package/dist/math.js.map +1 -0
- package/dist/shiki.d.ts.map +1 -1
- package/dist/shiki.js +52 -1
- package/dist/shiki.js.map +1 -1
- package/dist/transformer.d.ts.map +1 -1
- package/dist/transformer.js +2 -0
- package/dist/transformer.js.map +1 -1
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/copy-script.ts +5 -0
- package/src/dev-warnings.ts +125 -0
- package/src/index.ts +9 -1
- package/src/katex.d.ts +16 -0
- package/src/math.ts +268 -0
- package/src/shiki.ts +54 -1
- package/src/transformer.ts +2 -0
- package/src/types.ts +59 -0
package/src/types.ts
CHANGED
|
@@ -122,6 +122,21 @@ export interface PerfectCodeOptions {
|
|
|
122
122
|
transformerOrder?: 'before' | 'after';
|
|
123
123
|
/** Override the highlighter factory (e.g. for custom TextMate grammars). */
|
|
124
124
|
getHighlighter?: (opts: { themes: string[]; langs: string[] }) => Promise<unknown>;
|
|
125
|
+
/**
|
|
126
|
+
* v2.1.0: Lazy initialization — don't load Shiki until the first code block
|
|
127
|
+
* is encountered. On pages with no code blocks, Shiki (and its WASM engine)
|
|
128
|
+
* is never loaded, saving ~1MB of bundle.
|
|
129
|
+
*
|
|
130
|
+
* Default: false (Shiki initializes eagerly, same as v1.x/v2.0)
|
|
131
|
+
*/
|
|
132
|
+
lazy?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* v2.1.0: Languages to preload when lazy is true. Only loaded if the
|
|
135
|
+
* document contains at least one code block.
|
|
136
|
+
*
|
|
137
|
+
* Default: ['typescript', 'bash', 'javascript', 'json', 'html', 'css']
|
|
138
|
+
*/
|
|
139
|
+
preloadLangs?: string[];
|
|
125
140
|
[key: string]: unknown;
|
|
126
141
|
};
|
|
127
142
|
/**
|
|
@@ -491,6 +506,50 @@ export interface PerfectCodeOptions {
|
|
|
491
506
|
*/
|
|
492
507
|
scope?: string;
|
|
493
508
|
|
|
509
|
+
/* ---------- v2.1.0: Math/LaTeX rendering ---------- */
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Math/LaTeX rendering via KaTeX. When enabled, the plugin intercepts:
|
|
513
|
+
* - Inline math: `$...$` in text (when `math.inline` is true)
|
|
514
|
+
* - Block math: `$$...$$` blocks (when `math.block` is true)
|
|
515
|
+
* - Fenced code blocks with language `math`, `latex`, or `tex`
|
|
516
|
+
*
|
|
517
|
+
* KaTeX renders at build time (server-side) — no client-side JS needed.
|
|
518
|
+
* The KaTeX CSS + fonts must be loaded on the client (the plugin injects
|
|
519
|
+
* a `<link>` to KaTeX CSS if `math.injectCss` is true).
|
|
520
|
+
*
|
|
521
|
+
* `katex` must be installed: `npm install katex`
|
|
522
|
+
*
|
|
523
|
+
* Default: `undefined` (no math rendering; `$...$` renders as literal text)
|
|
524
|
+
*/
|
|
525
|
+
math?: {
|
|
526
|
+
/** Math engine. 'katex' renders via KaTeX (must be installed). Default: 'none' */
|
|
527
|
+
engine?: 'katex' | 'none';
|
|
528
|
+
/** Render inline `$...$` math. Default: true */
|
|
529
|
+
inline?: boolean;
|
|
530
|
+
/** Render block `$$...$$` and ```math blocks. Default: true */
|
|
531
|
+
block?: boolean;
|
|
532
|
+
/** Inject KaTeX CSS alongside plugin CSS. Default: true */
|
|
533
|
+
injectCss?: boolean;
|
|
534
|
+
/** Don't crash on invalid LaTeX — render the source as-is. Default: true */
|
|
535
|
+
throwOnError?: boolean;
|
|
536
|
+
/** Allow non-standard LaTeX commands. Default: false */
|
|
537
|
+
strict?: boolean | 'ignore' | 'error' | 'warn';
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
/* ---------- v2.1.0: Development warnings ---------- */
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Emit warnings to the logger during build/dev for common misconfigurations:
|
|
544
|
+
* - Unknown language not loaded in Shiki
|
|
545
|
+
* - Invalid meta syntax (e.g., `{1,a-5}` instead of `{1,3-5}`)
|
|
546
|
+
* - Conflicting options (e.g., `wrap` + `collapseAfter` both enabled)
|
|
547
|
+
* - Code block inside raw HTML detected but rehype-raw not installed
|
|
548
|
+
*
|
|
549
|
+
* Default: true in development (when `NODE_ENV !== 'production'`), false in production.
|
|
550
|
+
*/
|
|
551
|
+
devWarnings?: boolean;
|
|
552
|
+
|
|
494
553
|
/* ---------- Inline code (legacy cosmetic option) ---------- */
|
|
495
554
|
/** Also style inline `code` cosmetically (no tokenization). Default: false */
|
|
496
555
|
inline?: boolean;
|