@@ -10,6 +10,8 @@ import { getMarker, hasMarker, markerSliceCode, removeMarkers } from "./marker";
1010import { sliceCode , hasSliceRange , getSliceRange } from "./slicer" ;
1111import { hasTitle } from "./title" ;
1212import { getTemplateContent , readFileFromPath } from "./template" ;
13+ import { codeBlockBacktick } from "./backtick-maker" ;
14+
1315const markdownLinkFormatRegExp = / \[ ( (?: [ ^ \] ] | \\ .) * ?) \] \( ( (?: [ ^ \) ] | \\ .) * ?) \) / gm;
1416
1517const keyEx = "\\w+" ;
@@ -63,7 +65,11 @@ export function strip(s) {
6365 if ( s === undefined || s === "" ) {
6466 return s ;
6567 }
66- const indents = s . split ( / \n / ) . map ( s => s . match ( / ^ [ \t ] * (? = \S ) / ) ) . filter ( m => m ) . map ( m => m [ 0 ] ) ;
68+ const indents = s
69+ . split ( / \n / )
70+ . map ( s => s . match ( / ^ [ \t ] * (? = \S ) / ) )
71+ . filter ( m => m )
72+ . map ( m => m [ 0 ] ) ;
6773 const smallestIndent = indents . sort ( ( a , b ) => a . length - b . length ) [ 0 ] ;
6874 return s . replace ( new RegExp ( `^${ smallestIndent } ` , "gm" ) , "" ) ;
6975}
@@ -163,9 +169,10 @@ export function parseVariablesFromLabel(kvMap, label) {
163169 * @param {string } fileName
164170 * @param {string } originalPath
165171 * @param {string } content
172+ * @param {string } backtick
166173 * @return {string }
167174 */
168- export function generateEmbedCode ( kvMap , { fileName, originalPath, content } ) {
175+ export function generateEmbedCode ( kvMap , { fileName, originalPath, content, backtick } ) {
169176 const tContent = getTemplateContent ( kvMap ) ;
170177 const kv = Object . assign ( { } , kvMap ) ;
171178 const count = hasTitle ( kv ) ? codeCounter ( ) : - 1 ;
@@ -174,7 +181,8 @@ export function generateEmbedCode(kvMap, { fileName, originalPath, content }) {
174181 content : content ,
175182 count : count ,
176183 fileName : fileName ,
177- originalPath : originalPath
184+ originalPath : originalPath ,
185+ backtick
178186 } ) ;
179187 // compile template
180188 const handlebars = Handlebars . compile ( tContent ) ;
@@ -206,7 +214,7 @@ export function embedCode(kvMap, { filePath, originalPath, label }) {
206214 const kvm = getLang ( kvmparsed , originalPath ) ;
207215 const unindent = kvm . unindent ;
208216
209- var content = code ;
217+ let content = code ;
210218 // Slice content via line numbers.
211219 if ( hasSliceRange ( label ) ) {
212220 const [ start , end ] = getSliceRange ( label ) ;
@@ -219,7 +227,9 @@ export function embedCode(kvMap, { filePath, originalPath, label }) {
219227 if ( unindent === true ) {
220228 content = strip ( content ) ;
221229 }
222- return generateEmbedCode ( kvm , { fileName, originalPath, content } ) ;
230+
231+ const backtick = codeBlockBacktick ( content ) ;
232+ return generateEmbedCode ( kvm , { fileName, originalPath, content, backtick } ) ;
223233}
224234
225235/**
0 commit comments