File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,11 @@ import {
13
13
normalizePosition ,
14
14
restoreNodeLocation ,
15
15
} from './helper'
16
- import { COMMENT_CONTENT_REGEX , isComment } from './regexp'
16
+ import {
17
+ COMMENT_CONTENT_REGEX ,
18
+ COMMENT_CONTENT_REGEX_GLOBAL ,
19
+ isComment ,
20
+ } from './regexp'
17
21
import { traverse } from './traverse'
18
22
import {
19
23
Comment ,
@@ -101,7 +105,7 @@ export class Parser {
101
105
inline : ! ! parent && parent . type !== 'root' ,
102
106
} ,
103
107
value : value . replace (
104
- COMMENT_CONTENT_REGEX ,
108
+ COMMENT_CONTENT_REGEX_GLOBAL ,
105
109
(
106
110
matched : string ,
107
111
$0 : string ,
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ export const selfClosingTag =
26
26
export const comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'
27
27
export const commentOpen = '(<!---*)'
28
28
export const commentClose = '(-*-->)'
29
+ export const commentContent = `${ commentOpen } ([\\s\\S]*?)${ commentClose } `
29
30
30
31
export const OPEN_TAG_REGEX = new RegExp ( `^(?:${ openTag } )$` )
31
32
export const CLOSE_TAG_REGEX = new RegExp ( `^(?:${ closeTag } )$` )
@@ -34,10 +35,8 @@ export const OPEN_CLOSE_TAG_REGEX = new RegExp(
34
35
)
35
36
export const SELF_CLOSING_TAG_REGEX = new RegExp ( `^(?:${ selfClosingTag } )$` )
36
37
export const COMMENT_REGEX = new RegExp ( `^(?:${ comment } )$` )
37
- export const COMMENT_CONTENT_REGEX = new RegExp (
38
- `${ commentOpen } ([\\s\\S]*?)${ commentClose } ` ,
39
- 'g' ,
40
- )
38
+ export const COMMENT_CONTENT_REGEX = new RegExp ( commentContent )
39
+ export const COMMENT_CONTENT_REGEX_GLOBAL = new RegExp ( commentContent , 'g' )
41
40
42
41
export const isOpenTag = ( text : string ) => OPEN_TAG_REGEX . test ( text )
43
42
export const isCloseTag = ( text : string ) => CLOSE_TAG_REGEX . test ( text )
Original file line number Diff line number Diff line change @@ -219,4 +219,12 @@ describe('parser', () => {
219
219
filePath : 'test.md' ,
220
220
} ) ,
221
221
) . not . toThrow ( ) )
222
+
223
+ it ( 'should work with multiple comments' , ( ) =>
224
+ expect ( ( ) =>
225
+ parser . parse ( '<!-- * foo -->\n<!-- * bar -->' , {
226
+ ...parserOptions ,
227
+ filePath : 'test.mdx' ,
228
+ } ) ,
229
+ ) . not . toThrow ( ) )
222
230
} )
You can’t perform that action at this time.
0 commit comments