@dr-ishaan/rehype-perfect-code-blocks 1.1.6 → 1.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/src/types.ts CHANGED
@@ -59,6 +59,16 @@ export interface PerfectCodeOptions {
59
59
  wrap?: boolean;
60
60
  /** Auto-collapse blocks longer than N lines. null = never. Default: null */
61
61
  collapseAfter?: number | null;
62
+ /**
63
+ * Per-line collapsible sections.
64
+ * Pass a meta string like `collapse="5-12,20-30"` to wrap matching line ranges
65
+ * in `<details><summary>N collapsed lines</summary>...</details>`.
66
+ * Style options: 'github' (default), 'collapsible-start', 'collapsible-end', 'collapsible-auto'.
67
+ * Default: null (disabled).
68
+ */
69
+ collapseRanges?: string | null;
70
+ /** Style for collapsible sections. Default: 'github'. */
71
+ collapseStyle?: 'github' | 'collapsible-start' | 'collapsible-end' | 'collapsible-auto';
62
72
  /** Show visible whitespace (tabs/spaces). Default: false */
63
73
  showWhitespace?: false | 'all' | 'boundary' | 'trailing' | 'leading';
64
74
  /** Render vertical indent guides. false | true (default 2) | number (indent width). Default: false */
@@ -76,8 +86,12 @@ export interface PerfectCodeOptions {
76
86
  engine?: 'auto' | 'shiki' | 'passthrough';
77
87
  /** Shiki options passed through when the plugin calls Shiki itself. */
78
88
  shiki?: {
79
- /** Theme — string for single theme, { light, dark } for dual-theme via CSS vars. */
80
- theme?: string | { light: string; dark: string };
89
+ /**
90
+ * Theme — string for single theme, { light, dark } for dual-theme via CSS vars,
91
+ * or a Record<string, string> for multi-theme (3+ themes) support.
92
+ * Multi-theme example: `{ light: 'github-light', dark: 'github-dark', dim: 'github-dark-dimmed' }`.
93
+ */
94
+ theme?: string | { light: string; dark: string } | Record<string, string>;
81
95
  /** Pre-loaded languages. Defaults to a sensible set; missing langs are lazy-loaded. */
82
96
  langs?: string[];
83
97
  /**
@@ -88,6 +102,12 @@ export interface PerfectCodeOptions {
88
102
  regexEngine?: 'oniguruma' | 'javascript';
89
103
  /** Additional Shiki transformers to apply (see @shikijs/transformers). */
90
104
  transformers?: ShikiTransformer[];
105
+ /**
106
+ * Controls whether user-provided transformers run 'before' or 'after' the
107
+ * auto-registered ones (default: 'after'). Use 'before' to give user
108
+ * transformers first access to the code text.
109
+ */
110
+ transformerOrder?: 'before' | 'after';
91
111
  /** Override the highlighter factory (e.g. for custom TextMate grammars). */
92
112
  getHighlighter?: (opts: { themes: string[]; langs: string[] }) => Promise<unknown>;
93
113
  [key: string]: unknown;
@@ -108,6 +128,34 @@ export interface PerfectCodeOptions {
108
128
  * round-trip. Faster + safer. Default: true.
109
129
  */
110
130
  useHastApi?: boolean;
131
+ /**
132
+ * Disable auto-registration of @shikijs/transformers. When true, ONLY the
133
+ * transformers in `shiki.transformers` are applied. Default: false.
134
+ * Useful for advanced users who want full manual control.
135
+ */
136
+ disableAutoTransformers?: boolean;
137
+ /**
138
+ * Strip all comments from the rendered code (// ..., # ..., /* ... *\/, <!-- ... -->).
139
+ * Powered by @shikijs/transformers `transformerRemoveComments`. Default: false.
140
+ */
141
+ removeComments?: boolean;
142
+ /**
143
+ * Remove line breaks from the rendered code (joins all lines into one).
144
+ * Powered by @shikijs/transformers `transformerRemoveLineBreaks`. Default: false.
145
+ * Useful for compact inline-style code blocks.
146
+ */
147
+ removeLineBreaks?: boolean;
148
+ /**
149
+ * When `true`, treat {1,3-5} meta ranges as zero-indexed (line 0 is the first
150
+ * line). When `false` (default), line numbers start at 1.
151
+ */
152
+ zeroIndexed?: boolean;
153
+ /**
154
+ * Programmatic per-line class assignment (Shiki's `transformerCompactLineOptions`).
155
+ * Example: `[{ line: 1, classes: ['highlight'] }, { line: 3, classes: ['add'] }]`.
156
+ * Default: [] (disabled).
157
+ */
158
+ lineOptions?: { line: number; classes?: string[]; attrs?: Record<string, string> }[];
111
159
 
112
160
  /* ---------- Inline comment notations (VitePress-style) ---------- */
113
161
  /**
@@ -141,7 +189,7 @@ export interface PerfectCodeOptions {
141
189
  /* ---------- Auto frame detection (Expressive Code style) ---------- */
142
190
  /**
143
191
  * Auto-switch to terminal preset for these languages. Default:
144
- * ['sh', 'bash', 'zsh', 'shell', 'console', 'powershell', 'bat', 'cmd', 'fish']
192
+ * ['sh', 'bash', 'zsh', 'shell', 'console', 'powershell', 'bat', 'cmd', 'fish', 'ansi']
145
193
  */
146
194
  terminalLangs?: string[];
147
195
  /**
@@ -172,10 +220,22 @@ export interface PerfectCodeOptions {
172
220
  * (Renamed from `inlineDefaultLang` for clarity; old name still works.)
173
221
  */
174
222
  defaultInlineLang?: string;
223
+ /**
224
+ * Replace tabs with N spaces before tokenization. 0 disables (default).
225
+ * Useful for languages where Shiki's tab rendering doesn't match the
226
+ * surrounding code style.
227
+ */
228
+ tabWidth?: number;
229
+ /**
230
+ * Strip leading `#` comment lines from terminal code when copying to clipboard.
231
+ * Default: true (only effective when preset === 'terminal').
232
+ */
233
+ copyStripComments?: boolean;
175
234
 
176
235
  /* ---------- Accessibility ---------- */
177
236
  /**
178
- * Add `role="region"` and `aria-label` to scrollable code blocks (WCAG 4.1.2).
237
+ * Add `role="region"`, `aria-label`, and `tabindex="0"` to scrollable code
238
+ * blocks (WCAG 2.1.1 keyboard accessible, 4.1.2 name-role-value).
179
239
  * Default: true.
180
240
  */
181
241
  accessibleScroll?: boolean;
@@ -190,8 +250,13 @@ export interface PerfectCodeOptions {
190
250
  * Default: true.
191
251
  */
192
252
  hideCopyWithoutJs?: boolean;
253
+ /**
254
+ * Add a screen-reader-only `<span class="pcb__sr-only">Terminal window</span>`
255
+ * to terminal-preset blocks that have no title. Improves screen reader context.
256
+ * Default: true.
257
+ */
258
+ terminalSrOnlyTitle?: boolean;
193
259
 
194
- /* ---------- Pipeline ---------- */
195
260
  /**
196
261
  * Additional rehype plugins to run BEFORE rehype-perfect-code-blocks.
197
262
  * Pass `rehypeRaw` here if your markdown contains raw HTML (`<details>`,
@@ -215,6 +280,40 @@ export interface PerfectCodeOptions {
215
280
  /** Called for the caption element (if present). */
216
281
  onVisitCaption?: (element: unknown) => void;
217
282
 
283
+ /* ---------- i18n (internationalization) ---------- */
284
+ /**
285
+ * Localized UI strings. Defaults are English. Override per-locale by
286
+ * passing a different `texts` object based on the current language.
287
+ */
288
+ texts?: {
289
+ /** Copy button label (default: 'copy'). */
290
+ copyLabel?: string;
291
+ /** Label shown after successful copy (default: 'copied!'). */
292
+ doneLabel?: string;
293
+ /** Aria-label for the copy button (default: 'Copy code'). */
294
+ copyAriaLabel?: string;
295
+ /** Screen-reader-only title for terminal-preset blocks (default: 'Terminal window'). */
296
+ terminalSrOnlyTitle?: string;
297
+ /** aria-label prefix for scrollable body (default: 'Code block'). */
298
+ codeBlockAriaPrefix?: string;
299
+ /** Summary text for collapsed sections, with `{n}` placeholder (default: '{n} collapsed lines'). */
300
+ collapsedLinesLabel?: (n: number) => string;
301
+ };
302
+
303
+ /* ---------- Logging ---------- */
304
+ /**
305
+ * Custom logger. Defaults to `console`. Useful for silencing warnings in
306
+ * production or routing them to a structured logger.
307
+ */
308
+ logger?: { warn: (msg: string) => void; error: (msg: string) => void };
309
+
310
+ /* ---------- CSP (Content Security Policy) ---------- */
311
+ /**
312
+ * Nonce to add to injected `<script>` and `<style>` tags. Enables strict CSP
313
+ * (`script-src 'self' 'nonce-...'`). Default: undefined (no nonce).
314
+ */
315
+ cspNonce?: string;
316
+
218
317
  /* ---------- Styling ---------- */
219
318
  /** Visual preset. Default: 'default' */
220
319
  preset?: 'default' | 'terminal' | 'minimal';
@@ -246,6 +345,7 @@ export interface ParsedMeta {
246
345
  highlightGroups: { lines: number[]; id?: string }[]; // {1,2}#a {3,4}#b
247
346
  wordHighlights: { text: string; range?: [number, number]; id?: string }[];
248
347
  lineNumbersStart: number | null; // from ln{N} or showLineNumbers{N}
348
+ collapseRanges: { from: number; to: number }[]; // from collapse="5-12,20-30"
249
349
  flags: {
250
350
  wrap: boolean | null;
251
351
  lineNumbers: boolean | null;