module Asciidoctor::Substitutors

def restore_passthroughs text, outer = true

returns The String text with the passthrough text restored

outer - A Boolean indicating whether we are in the outer call (default: true)
text - The String text into which to restore the passthrough text

Internal: Restore the passthrough text by reinserting into the placeholder positions
def restore_passthroughs text, outer = true
  if outer && (@passthroughs.empty? || !text.include?(PASS_START))
    return text
  end
  text.gsub(PASS_MATCH) {
    # NOTE we can't remove entry from map because placeholder may have been duplicated by other substitutions
    pass = @passthroughs[$~[1].to_i]
    subbed_text = (subs = pass[:subs]) ? apply_subs(pass[:text], subs) : pass[:text]
    if (type = pass[:type])
      subbed_text = Inline.new(self, :quoted, subbed_text, :type => type, :attributes => pass[:attributes]).convert
    end
    subbed_text.include?(PASS_START) ? restore_passthroughs(subbed_text, false) : subbed_text
  }
ensure
  # free memory if in outer call...we don't need these anymore
  @passthroughs.clear if outer
end