@dr-ishaan/rehype-perfect-code-blocks 2.0.0 → 2.2.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 +162 -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 +11 -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/meta.d.ts.map +1 -1
- package/dist/meta.js +18 -2
- package/dist/meta.js.map +1 -1
- package/dist/shiki.d.ts.map +1 -1
- package/dist/shiki.js +52 -1
- package/dist/shiki.js.map +1 -1
- package/dist/styles.css +68 -0
- package/dist/transformer.d.ts.map +1 -1
- package/dist/transformer.js +66 -2
- package/dist/transformer.js.map +1 -1
- package/dist/types.d.ts +106 -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 +13 -1
- package/src/katex.d.ts +16 -0
- package/src/math.ts +268 -0
- package/src/meta.ts +19 -2
- package/src/shiki.ts +54 -1
- package/src/styles.css +68 -0
- package/src/transformer.ts +69 -2
- package/src/types.ts +122 -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,109 @@ 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
|
+
|
|
553
|
+
/* ---------- v2.2.0: Diff & Comparison ---------- */
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Side-by-side diff view. When enabled, adjacent `+`/`-` diff line pairs
|
|
557
|
+
* are rendered in a two-column layout (Before | After) with synchronized
|
|
558
|
+
* scrolling, instead of the default unified diff view.
|
|
559
|
+
*
|
|
560
|
+
* On mobile (viewport < 768px), the columns stack vertically.
|
|
561
|
+
*
|
|
562
|
+
* Default: `'unified'` (backward-compatible with v1.x/v2.0/v2.1)
|
|
563
|
+
*/
|
|
564
|
+
diffMode?: 'unified' | 'split';
|
|
565
|
+
|
|
566
|
+
/* ---------- v2.2.0: Annotations ---------- */
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Line annotations — margin notes attached to specific code lines.
|
|
570
|
+
*
|
|
571
|
+
* Use `// [!ann: "explanation"]` notation inside code to annotate a line.
|
|
572
|
+
* The annotation appears on the right side of the code block, connected
|
|
573
|
+
* to the annotated line with a subtle connector line. On mobile,
|
|
574
|
+
* annotations appear inline below the annotated line.
|
|
575
|
+
*
|
|
576
|
+
* Example:
|
|
577
|
+
* ```ts
|
|
578
|
+
* const attention = Q.dot(K.T) / Math.sqrt(d) // [!ann: "Scaled dot-product"]
|
|
579
|
+
* const weights = softmax(attention) // [!ann: "Normalized weights"]
|
|
580
|
+
* ```
|
|
581
|
+
*
|
|
582
|
+
* Default: `false` (opt-in)
|
|
583
|
+
*/
|
|
584
|
+
annotations?: boolean;
|
|
585
|
+
|
|
586
|
+
/* ---------- v2.2.0: Attribution ---------- */
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Code attribution — structured metadata for code blocks.
|
|
590
|
+
*
|
|
591
|
+
* When enabled, the plugin parses `author`, `year`, and `source` attributes
|
|
592
|
+
* from the fence meta string and renders them as a footer below the code block:
|
|
593
|
+
*
|
|
594
|
+
* ````markdown
|
|
595
|
+
* ```ts title="perceptron.ts" author="Rosenblatt" year="1958" source="Principles of Neurodynamics"
|
|
596
|
+
* const output = stepFunction(inputs.dot(weights))
|
|
597
|
+
* ```
|
|
598
|
+
* ````
|
|
599
|
+
*
|
|
600
|
+
* Renders:
|
|
601
|
+
* ```
|
|
602
|
+
* ┌─ perceptron.ts ──────────────────┐
|
|
603
|
+
* │ const output = stepFunction(...) │
|
|
604
|
+
* └───────────────────────────────────┘
|
|
605
|
+
* Rosenblatt (1958). Principles of Neurodynamics.
|
|
606
|
+
* ```
|
|
607
|
+
*
|
|
608
|
+
* Default: `false` (opt-in; when disabled, author/year/source meta is silently ignored)
|
|
609
|
+
*/
|
|
610
|
+
attribution?: boolean;
|
|
611
|
+
|
|
494
612
|
/* ---------- Inline code (legacy cosmetic option) ---------- */
|
|
495
613
|
/** Also style inline `code` cosmetically (no tokenization). Default: false */
|
|
496
614
|
inline?: boolean;
|
|
@@ -515,6 +633,10 @@ export interface ParsedMeta {
|
|
|
515
633
|
wordHighlights: { text: string; range?: [number, number]; id?: string }[];
|
|
516
634
|
lineNumbersStart: number | null; // from ln{N} or showLineNumbers{N}
|
|
517
635
|
collapseRanges: { from: number; to: number }[]; // from collapse="5-12,20-30"
|
|
636
|
+
// v2.2.0: Attribution metadata
|
|
637
|
+
author: string | null; // from author="..."
|
|
638
|
+
year: string | null; // from year="..."
|
|
639
|
+
source: string | null; // from source="..."
|
|
518
640
|
flags: {
|
|
519
641
|
wrap: boolean | null;
|
|
520
642
|
lineNumbers: boolean | null;
|