This repository was archived by the owner on Oct 14, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
src/docs/components/CodeBlock Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 66 interface Props {
77 code: string ;
88 lang: BuiltinLanguage | SpecialLanguage ;
9- highlight ? : number | Array < number >;
9+ mark ? : Array < number | [ number , number ] >;
1010 }
1111
1212 // Props
13- let { code, lang = ' text' , highlight = [] }: Props = $props ();
13+ let { code, lang = ' text' , mark = [] }: Props = $props ();
14+
15+ const highlightedLineNumbers = $derived (
16+ mark
17+ .map ((mark ) => {
18+ if (Array .isArray (mark )) {
19+ const [start, end] = mark ;
20+ return Array .from ({ length: end - start + 1 }, (_ , i ) => start + i );
21+ }
22+ return mark ;
23+ })
24+ .flat (),
25+ );
1426
1527 // Process Language
1628 const renderedCode = $derived (
2941 * This transformer adds the `highlighted` class to lines that are to be highlighted.
3042 */
3143 {
32- line(node , line ) {
33- if (! ( Array . isArray ( highlight ) ? highlight : [ highlight ]). includes (line )) {
44+ line(node , lineNumber ) {
45+ if (! highlightedLineNumbers . includes (lineNumber )) {
3446 return ;
3547 }
3648 this .addClassToHast (node , ' highlighted' );
You can’t perform that action at this time.
0 commit comments