File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1313
1414import { ok as assert } from 'devlop'
1515import { toMatters } from 'micromark-extension-frontmatter'
16+ import escapeStringRegexp from 'escape-string-regexp'
1617
1718/**
1819 * Create an extension for `mdast-util-from-markdown`.
@@ -108,7 +109,7 @@ export function frontmatterToMarkdown(options) {
108109 unsafe . push ( {
109110 atBreak : true ,
110111 character : open . charAt ( 0 ) ,
111- after : open . charAt ( 1 )
112+ after : escapeStringRegexp ( open . charAt ( 1 ) )
112113 } )
113114 }
114115
Original file line number Diff line number Diff line change 3737 "dependencies" : {
3838 "@types/mdast" : " ^4.0.0" ,
3939 "devlop" : " ^1.0.0" ,
40+ "escape-string-regexp" : " ^5.0.0" ,
4041 "mdast-util-from-markdown" : " ^2.0.0" ,
4142 "mdast-util-to-markdown" : " ^2.0.0" ,
4243 "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) {
340340 } )
341341 }
342342 )
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+ )
343369} )
344370
345371test ( 'frontmatterToMarkdown' , async function ( t ) {
You can’t perform that action at this time.
0 commit comments