@@ -21,30 +21,40 @@ export function isCommentLike(node: Element, line: Element) {
21
21
export function createCommentNotationTransformer (
22
22
name : string ,
23
23
regex : RegExp ,
24
- onMatch : ( this : ShikijiTransformerContext , match : RegExpMatchArray , line : Element , commentNode : Element ) => boolean ,
24
+ onMatch : (
25
+ this : ShikijiTransformerContext ,
26
+ match : RegExpMatchArray ,
27
+ line : Element ,
28
+ commentNode : Element ,
29
+ lines : Element [ ] ,
30
+ index : number ,
31
+ ) => boolean ,
25
32
) : ShikijiTransformer {
26
33
return {
27
34
name,
28
- line ( line ) {
29
- let nodeToRemove : Element | undefined
30
- for ( const child of line . children ) {
31
- if ( child . type !== 'element' )
32
- continue
33
- if ( ! isCommentLike ( child , line ) )
34
- continue
35
- const text = child . children [ 0 ]
36
- if ( text . type !== 'text' )
37
- continue
38
- const match = text . value . match ( regex )
39
- if ( ! match )
40
- continue
41
- if ( onMatch . call ( this , match , line , child ) ) {
42
- nodeToRemove = child
43
- break
35
+ code ( code ) {
36
+ const lines = code . children . filter ( i => i . type === 'element' ) as Element [ ]
37
+ lines . forEach ( ( line , idx ) => {
38
+ let nodeToRemove : Element | undefined
39
+ for ( const child of line . children ) {
40
+ if ( child . type !== 'element' )
41
+ continue
42
+ if ( ! isCommentLike ( child , line ) )
43
+ continue
44
+ const text = child . children [ 0 ]
45
+ if ( text . type !== 'text' )
46
+ continue
47
+ const match = text . value . match ( regex )
48
+ if ( ! match )
49
+ continue
50
+ if ( onMatch . call ( this , match , line , child , lines , idx ) ) {
51
+ nodeToRemove = child
52
+ break
53
+ }
44
54
}
45
- }
46
- if ( nodeToRemove )
47
- line . children . splice ( line . children . indexOf ( nodeToRemove ) , 1 )
55
+ if ( nodeToRemove )
56
+ line . children . splice ( line . children . indexOf ( nodeToRemove ) , 1 )
57
+ } )
48
58
} ,
49
59
}
50
60
}
0 commit comments