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 6
6
interface Props {
7
7
code: string ;
8
8
lang: BuiltinLanguage | SpecialLanguage ;
9
- highlight ? : number | Array < number >;
9
+ mark ? : Array < number | [ number , number ] >;
10
10
}
11
11
12
12
// 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
+ );
14
26
15
27
// Process Language
16
28
const renderedCode = $derived (
29
41
* This transformer adds the `highlighted` class to lines that are to be highlighted.
30
42
*/
31
43
{
32
- line(node , line ) {
33
- if (! ( Array . isArray ( highlight ) ? highlight : [ highlight ]). includes (line )) {
44
+ line(node , lineNumber ) {
45
+ if (! highlightedLineNumbers . includes (lineNumber )) {
34
46
return ;
35
47
}
36
48
this .addClassToHast (node , ' highlighted' );
You can’t perform that action at this time.
0 commit comments