@@ -127,6 +127,7 @@ const Plugin = () => {
127127		// with parsing 
128128		content  =  content . replace (  / < \/ s c r i p t > / g,  SCRIPT_END_PLACEHOLDER  ) ; 
129129
130+ 		// render the template with the content only if there is metadata 
130131		if  ( options . metadata ) { 
131132			content  =  renderTemplate ( content ,  options ) 
132133		} 
@@ -153,6 +154,7 @@ const Plugin = () => {
153154			content , 
154155			sectionStack  =  [ ] ; 
155156
157+ 		// separates default metadata from the markdown file 
156158		[  markdown ,  options  ]  =  parseFrontMatter ( markdown ,  options ) 
157159
158160		// iterate until all blocks between separators are stacked up 
@@ -190,22 +192,23 @@ const Plugin = () => {
190192
191193		// flatten the hierarchical stack, and insert <section data-markdown> tags 
192194		for (  let  i  =  0 ,  len  =  sectionStack . length ;  i  <  len ;  i ++  )  { 
193- 			let  newOptions  =  { ...options } 
195+ 			// slideOptions is created to avoid mutating the original options object with default metadata 
196+ 			let  slideOptions  =  { ...options } 
194197
195198			// vertical 
196199			if (  sectionStack [ i ]  instanceof  Array  )  { 
197- 				markdownSections  +=  '<section '  +  newOptions . attributes  +  '>' ; 
200+ 				markdownSections  +=  '<section '  +  slideOptions . attributes  +  '>' ; 
198201
199202				sectionStack [ i ] . forEach (  function (  child  )  { 
200- 					[ content ,  newOptions ]  =  parseMarkdown ( child ,  newOptions ) 
201- 					markdownSections  +=  '<section '  +  newOptions . attributes  +  ' data-markdown>'  +  createMarkdownSlide (  content ,  newOptions  )  +  '</section>' ; 
203+ 					[ content ,  slideOptions ]  =  separateInlineMetadataAndMarkdown ( child ,  slideOptions ) 
204+ 					markdownSections  +=  '<section '  +  slideOptions . attributes  +  ' data-markdown>'  +  createMarkdownSlide (  content ,  slideOptions  )  +  '</section>' ; 
202205				}  ) ; 
203206
204207				markdownSections  +=  '</section>' ; 
205208			} 
206209			else  { 
207- 				[ content ,  newOptions ]  =  parseMarkdown ( sectionStack [ i ] ,  newOptions ) 
208- 				markdownSections  +=  '<section '  +  newOptions . attributes  +  ' data-markdown>'  +  createMarkdownSlide (  content ,  newOptions  )  +  '</section>' ; 
210+ 				[ content ,  slideOptions ]  =  separateInlineMetadataAndMarkdown ( sectionStack [ i ] ,  slideOptions ) 
211+ 				markdownSections  +=  '<section '  +  slideOptions . attributes  +  ' data-markdown>'  +  createMarkdownSlide (  content ,  slideOptions  )  +  '</section>' ; 
209212			} 
210213		} 
211214
@@ -428,6 +431,12 @@ const Plugin = () => {
428431
429432	} 
430433
434+ 	/** 
435+ 	 * Parse the front matter from the Markdown document 
436+ 	 * 
437+ 	 * Returns updated options with the default metadata 
438+ 	 * and updated content without the front matter 
439+ 	 */ 
431440	function  parseFrontMatter ( content ,  options )  { 
432441		options  =  getSlidifyOptions (  options ) 
433442
@@ -445,7 +454,13 @@ const Plugin = () => {
445454		return  [ content ,  options ] ; 
446455	} 
447456
448- 	function  parseMarkdown ( markdown ,  options )  { 
457+ 	/** 
458+ 	 * Separates the inline metadata and content for each slide 
459+ 	 * 
460+ 	 * Returns updated options with the inline metadata and 
461+ 	 * updated markdown without the inline metadata for each slide 
462+ 	 */ 
463+ 	function  separateInlineMetadataAndMarkdown ( markdown ,  options )  { 
449464		const  yamlRegex  =   / ` ` ` ( y a m l | y m l ) \n ( [ \s \S ] * ?) ` ` ` ( \n [ \s \S ] * ) ? / g; 
450465		if  ( yamlRegex . test ( markdown ) ) { 
451466			yamlRegex . lastIndex  =  0 ; 
@@ -473,6 +488,11 @@ const Plugin = () => {
473488		return  [ markdown ,  options ] 
474489	} 
475490
491+ 	/** 
492+ 	 * Renders the template for each slide 
493+ 	 * 
494+ 	 * Returns the rendered template with the content 
495+ 	 */ 
476496	function  renderTemplate ( content ,  options )  { 
477497		try  { 
478498			options  =  getSlidifyOptions ( options ) 
0 commit comments