@@ -60,13 +60,18 @@ export function parseVariablesFromLabel(label) {
6060 "class" : undefined ,
6161 "name" : undefined ,
6262 "marker" : undefined ,
63- "unindent" : undefined
63+ "unindent" : undefined ,
64+ "edit" : undefined ,
65+ "theme" : undefined ,
66+ "check" : undefined ,
67+ "fixlang" : undefined
6468 } ;
6569 Object . keys ( keyvals ) . forEach ( key => {
6670 var keyReg = key ;
6771 if ( key === "marker" ) {
6872 keyReg = "import|include" ;
6973 }
74+
7075 const regStr = "\^.*,?\\s*(" + keyReg + ")\\s*:\\s*[\"']([^'\"]*)[\"'],?.*\$" ;
7176 const reg = new RegExp ( regStr ) ;
7277 const res = label . match ( reg ) ;
@@ -90,6 +95,7 @@ export function embedCode({lang, filePath, originalPath, label, template, uninde
9095 const code = fs . readFileSync ( filePath , "utf-8" ) ;
9196 const fileName = path . basename ( filePath ) ;
9297 const keyValueObject = parseVariablesFromLabel ( label ) ;
98+
9399 var content = code ;
94100 // Slice content via line numbers.
95101 if ( hasSliceRange ( label ) ) {
@@ -102,15 +108,15 @@ export function embedCode({lang, filePath, originalPath, label, template, uninde
102108 content = removeMarkers ( markerSliceCode ( code , marker ) ) ;
103109 }
104110 if ( unindent || keyValueObject . unindent ) {
105- content = strip ( content )
111+ content = strip ( content ) ;
106112 }
107113 return generateEmbedCode ( {
108114 keyValueObject,
109115 lang,
110116 fileName,
111117 originalPath,
112118 content,
113- template
119+ template,
114120 } ) ;
115121}
116122
@@ -137,7 +143,7 @@ export function generateEmbedCode({
137143 fileName,
138144 originalPath,
139145 content,
140- template
146+ template,
141147} ) {
142148 const count = hasTitle ( keyValueObject ) ? codeCounter ( ) : - 1 ;
143149 // merge objects
@@ -150,11 +156,19 @@ export function generateEmbedCode({
150156 return handlebars ( context ) ;
151157}
152158
159+ const templatePath = {
160+ default : path . join ( __dirname , ".." , "templates" , "default-template.hbs" ) ,
161+ full : path . join ( __dirname , ".." , "templates" , "full-template.hbs" ) ,
162+ ace : path . join ( __dirname , ".." , "templates" , "ace-template.hbs" ) ,
163+ acefull : path . join ( __dirname , ".." , "templates" , "acefull-template.hbs" )
164+ } ;
153165
154166const defaultOptions = {
155- template : fs . readFileSync ( path . join ( __dirname , ".." , "template" , "default-template.hbs" ) , "utf-8" ) ,
156- unindent : false
167+ template : "default" ,
168+ unindent : false ,
169+ fixlang : false
157170} ;
171+
158172/**
159173 * generate code with options
160174 * @param {string } content
@@ -164,14 +178,31 @@ const defaultOptions = {
164178 */
165179export function parse ( content , baseDir , options = { } ) {
166180 const results = [ ] ;
167- const template = options . template || defaultOptions . template ;
181+ const isTemplateDefault = ( options . template == undefined ) ;
182+ const isTemplatePath = ( templatePath [ options . template ] == undefined ) ;
183+ let tPath ;
184+ // No template option.
185+ if ( isTemplateDefault ) {
186+ tPath = templatePath [ defaultOptions . template ] ;
187+ }
188+ // Template option is a path.
189+ else if ( isTemplatePath && fs . existsSync ( options . template ) ) {
190+ tPath = options . template ;
191+ }
192+ // Template option one of template/ directory.
193+ else {
194+ tPath = templatePath [ options . template ] || templatePath [ defaultOptions . template ] ;
195+ }
196+ const template = fs . readFileSync ( tPath , "utf-8" ) ;
168197 const unindent = options . unindent || defaultOptions . unindent ;
198+ const fixlang = ( options . fixlang != undefined ) ? options . fixlang : defaultOptions . fixlang ;
199+
169200 let res ;
170201 while ( res = markdownLinkFormatRegExp . exec ( content ) ) {
171202 const [ all , label , originalPath ] = res ;
172203 const commands = splitLabelToCommands ( label ) ;
173204 if ( containIncludeCommand ( commands ) ) {
174- const lang = getLang ( commands , originalPath ) ;
205+ const lang = getLang ( commands , originalPath , fixlang ) ;
175206 const absolutePath = path . resolve ( baseDir , originalPath ) ;
176207 const replacedContent = embedCode ( {
177208 lang,
0 commit comments