File tree Expand file tree Collapse file tree
packages/cli/src/cli/loaders/mdx2 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " lingo.dev " : patch
3+ ---
4+
5+ extra slash n for code fences
Original file line number Diff line number Diff line change @@ -3,24 +3,30 @@ import { createLoader } from "../_utils";
33import { md5 } from "../../utils/md5" ;
44import _ from "lodash" ;
55
6- const unindentedFenceRegex = / (?< ! \n \n ) ` ` ` ( [ \s \S ] * ?) ` ` ` (? ! \n \n ) / g;
7- const indentedFenceRegex = / ` ` ` ( [ \s \S ] * ?) ` ` ` / g;
6+ const fenceRegex = / ` ` ` ( [ \s \S ] * ?) ` ` ` / g;
87
98function ensureTrailingFenceNewline ( _content : string ) {
109 let found = false ;
1110 let content = _content ;
11+ let workingContent = content ;
1212
1313 do {
1414 found = false ;
15- const matches = content . match ( unindentedFenceRegex ) ;
15+ const matches = workingContent . match ( fenceRegex ) ;
1616 if ( matches ) {
1717 const match = matches [ 0 ] ;
1818 content = content . replace ( match , `\n\n${ match } \n\n` ) ;
19+ workingContent = workingContent . replace ( match , "" ) ;
1920 found = true ;
2021 }
2122 } while ( found ) ;
2223
23- content = _ . chain ( content ) . split ( "\n\n" ) . filter ( Boolean ) . join ( "\n\n" ) . value ( ) ;
24+ content = _ . chain ( content )
25+ . split ( "\n\n" )
26+ . map ( ( section ) => section . trim ( ) )
27+ . filter ( Boolean )
28+ . join ( "\n\n" )
29+ . value ( ) ;
2430
2531 return content ;
2632}
@@ -38,7 +44,7 @@ function extractCodePlaceholders(content: string): {
3844
3945 const codePlaceholders : Record < string , string > = { } ;
4046
41- const codeBlockMatches = finalContent . matchAll ( indentedFenceRegex ) ;
47+ const codeBlockMatches = finalContent . matchAll ( fenceRegex ) ;
4248
4349 for ( const match of codeBlockMatches ) {
4450 const codeBlock = match [ 0 ] ;
You can’t perform that action at this time.
0 commit comments