File tree 3 files changed +29
-1
lines changed 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 13
13
14
14
import { ok as assert } from 'devlop'
15
15
import { toMatters } from 'micromark-extension-frontmatter'
16
+ import escapeStringRegexp from 'escape-string-regexp'
16
17
17
18
/**
18
19
* Create an extension for `mdast-util-from-markdown`.
@@ -108,7 +109,7 @@ export function frontmatterToMarkdown(options) {
108
109
unsafe . push ( {
109
110
atBreak : true ,
110
111
character : open . charAt ( 0 ) ,
111
- after : open . charAt ( 1 )
112
+ after : escapeStringRegexp ( open . charAt ( 1 ) )
112
113
} )
113
114
}
114
115
Original file line number Diff line number Diff line change 37
37
"dependencies" : {
38
38
"@types/mdast" : " ^4.0.0" ,
39
39
"devlop" : " ^1.0.0" ,
40
+ "escape-string-regexp" : " ^5.0.0" ,
40
41
"mdast-util-from-markdown" : " ^2.0.0" ,
41
42
"mdast-util-to-markdown" : " ^2.0.0" ,
42
43
"micromark-extension-frontmatter" : " ^2.0.0"
Original file line number Diff line number Diff line change @@ -340,6 +340,32 @@ test('frontmatterFromMarkdown', async function (t) {
340
340
} )
341
341
}
342
342
)
343
+
344
+ await t . test (
345
+ 'should support regexp special characters as markers' ,
346
+ async function ( ) {
347
+ const funky = { type : 'funky' , marker : '*' }
348
+ const tree = fromMarkdown ( '***\na\n***\n\n*a' , {
349
+ extensions : [ frontmatter ( funky ) ] ,
350
+ mdastExtensions : [ frontmatterFromMarkdown ( funky ) ]
351
+ } )
352
+
353
+ removePosition ( tree , { force : true } )
354
+
355
+ assert . deepEqual ( tree , {
356
+ type : 'root' ,
357
+ children : [
358
+ { type : 'funky' , value : 'a' } ,
359
+ { type : 'paragraph' , children : [ { type : 'text' , value : '*a' } ] }
360
+ ]
361
+ } )
362
+
363
+ assert . deepEqual (
364
+ toMarkdown ( tree , { extensions : [ frontmatterToMarkdown ( funky ) ] } ) ,
365
+ '***\na\n***\n\n\\*a\n'
366
+ )
367
+ }
368
+ )
343
369
} )
344
370
345
371
test ( 'frontmatterToMarkdown' , async function ( t ) {
You can’t perform that action at this time.
0 commit comments