lang/markup-templating.js
function(env, language) {
          if (env.language !== language || !env.tokenStack) {
            return
          }
          // Switch the grammar back
          env.grammar = Prism.languages[language]
          var j = 0
          var keys = Object.keys(env.tokenStack)
          function walkTokens(tokens) {
            for (var i = 0; i < tokens.length; i++) {
              // all placeholders are replaced already
              if (j >= keys.length) {
                break
              }
              var token = tokens[i]
              if (
                typeof token === 'string' ||
                (token.content && typeof token.content === 'string')
              ) {
                var k = keys[j]
                var t = env.tokenStack[k]
                var s = typeof token === 'string' ? token : token.content
                var placeholder = getPlaceholder(language, k)
                var index = s.indexOf(placeholder)
                if (index > -1) {
                  ++j
                  var before = s.substring(0, index)
                  var middle = new Prism.Token(
                    language,
                    Prism.tokenize(t, env.grammar),
                    'language-' + language,
                    t
                  )
                  var after = s.substring(index + placeholder.length)
                  var replacement = []
                  if (before) {
                    replacement.push.apply(replacement, walkTokens([before]))
                  }
                  replacement.push(middle)
                  if (after) {
                    replacement.push.apply(replacement, walkTokens([after]))
                  }
                  if (typeof token === 'string') {
                    tokens.splice.apply(tokens, [i, 1].concat(replacement))
                  } else {
                    token.content = replacement
                  }
                }
              } else if (
                token.content /* && typeof token.content !== 'string' */
              ) {
                walkTokens(token.content)
              }
            }
            return tokens
          }
          walkTokens(env.tokens)
        }
function(env, language) {
          if (env.language !== language || !env.tokenStack) {
            return
          }
          // Switch the grammar back
          env.grammar = Prism.languages[language]
          var j = 0
          var keys = Object.keys(env.tokenStack)
          function walkTokens(tokens) {
            for (var i = 0; i < tokens.length; i++) {
              // all placeholders are replaced already
              if (j >= keys.length) {
                break
              }
              var token = tokens[i]
              if (
                typeof token === 'string' ||
                (token.content && typeof token.content === 'string')
              ) {
                var k = keys[j]
                var t = env.tokenStack[k]
                var s = typeof token === 'string' ? token : token.content
                var placeholder = getPlaceholder(language, k)
                var index = s.indexOf(placeholder)
                if (index > -1) {
                  ++j
                  var before = s.substring(0, index)
                  var middle = new Prism.Token(
                    language,
                    Prism.tokenize(t, env.grammar),
                    'language-' + language,
                    t
                  )
                  var after = s.substring(index + placeholder.length)
                  var replacement = []
                  if (before) {
                    replacement.push.apply(replacement, walkTokens([before]))
                  }
                  replacement.push(middle)
                  if (after) {
                    replacement.push.apply(replacement, walkTokens([after]))
                  }
                  if (typeof token === 'string') {
                    tokens.splice.apply(tokens, [i, 1].concat(replacement))
                  } else {
                    token.content = replacement
                  }
                }
              } else if (
                token.content /* && typeof token.content !== 'string' */
              ) {
                walkTokens(token.content)
              }
            }
            return tokens
          }
          walkTokens(env.tokens)
        }
function ( env , language ) { if ( env . language !== language || ! env . tokenStack ) { return } // Switch the grammar back env . grammar = Prism . languages [ language ] var j = 0 var keys = Object . keys ( env . tokenStack ) function walkTokens ( tokens ) { for ( var i = 0 ; i < tokens . length ; i ++ ) { // all placeholders are replaced already if ( j >= keys . length ) { break } var token = tokens [ i ] if ( typeof token === 'string' || ( token . content && typeof token . content === 'string' ) ) { var k = keys [ j ] var t = env . tokenStack [ k ] var s = typeof token === 'string' ? token : token . content var placeholder = getPlaceholder ( language , k ) var index = s . indexOf ( placeholder ) if ( index > - 1 ) { ++ j var before = s . substring ( 0 , index ) var middle = new Prism . Token ( language , Prism . tokenize ( t , env . grammar ) , 'language-' + language , t ) var after = s . substring ( index + placeholder . length ) var replacement = [ ] if ( before ) { replacement . push . apply ( replacement , walkTokens ( [ before ] ) ) } replacement . push ( middle ) if ( after ) { replacement . push . apply ( replacement , walkTokens ( [ after ] ) ) } if ( typeof token === 'string' ) { tokens . splice . apply ( tokens , [ i , 1 ] . concat ( replacement ) ) } else { token . content = replacement } } } else if ( token . content /* && typeof token.content !== 'string' */ ) { walkTokens ( token . content ) } } return tokens } walkTokens ( env . tokens ) }
Replace placeholders with proper tokens after tokenizing.

@param {object} env The environment of the `after-tokenize` hook.
@param {string} language The language id.
Replace placeholders with proper tokens after tokenizing .