@@ -74,13 +74,14 @@ function resolveBackReference(choiceResultMap, backReference) {
7474 *
7575 * @returns {String } the rendered text.
7676 */
77- function renderText ( string , startIndex , evalBlock ,
78- modes , renderDefaultSettings , isTopLevel ) {
77+ function renderText ( string , startIndex , evalBlock , modes , activeMode ,
78+ renderDefaultSettings , choiceResultMap , isTopLevel ) {
7979 // TODO this function is way too complex and badly needs refactor
80- let activeMode = null ;
80+ // TODO replace isTopLevel with incrementing depth tracker
81+ choiceResultMap = choiceResultMap || new Map ( ) ;
82+ activeMode = activeMode || null ;
8183 let isEscaped = false ;
8284 let inLiteralBlock = false ;
83- let choiceResultMap = new Map ( ) ;
8485 let out = '' ;
8586 let index = startIndex ;
8687 let currentRule = null ;
@@ -151,7 +152,7 @@ function renderText(string, startIndex, evalBlock,
151152 // To handle nested choices and to run rules over chosen text,
152153 // we recursively render the chosen text.
153154 renderedReplacement = renderText (
154- replacement , 0 , null , modes , activeMode , settings , false ) ;
155+ replacement , 0 , null , modes , activeMode , settings , choiceResultMap , false ) ;
155156 }
156157 if ( ! ( replacer && replacer . isSilent ) ) {
157158 out += renderedReplacement ;
@@ -196,7 +197,7 @@ function renderText(string, startIndex, evalBlock,
196197 // To handle nested choices and to run rules over replaced text,
197198 // we recursively render the chosen text.
198199 let renderedReplacement = renderText (
199- replacement , 0 , null , modes , activeMode , settings , false ) ;
200+ replacement , 0 , null , modes , activeMode , settings , choiceResultMap , false ) ;
200201 out += renderedReplacement ;
201202 }
202203 index += currentMatch [ 0 ] . length ;
@@ -260,7 +261,7 @@ function render(bmlDocumentString, renderSettings, defaultDocumentSettings) {
260261 evalBlock = null ;
261262 }
262263 return renderText (
263- bmlDocumentString , preludeEndIndex , evalBlock , modes , defaultDocumentSettings , true ) ;
264+ bmlDocumentString , preludeEndIndex , evalBlock , modes , null , defaultDocumentSettings , null , true ) ;
264265}
265266
266267exports . renderText = renderText ;
0 commit comments