parameters: (match)
return_statement: return text_start + text_content + text_end
docstring: Do \\text{} replacements inside of javascript
  
          This takes a \\\\text{} string from some javascript and does the proper
          i18nization of its inner contents. Sometimes, if javascript variables
          are inside the contents, it will pull them out and do a string
          interpolation using $._.
  
          Note that this doesn't currently handle pure string concatenation very
          well, so something like \\\\text{" + "hello " + ", " + "world" + "}
          will produce something weird, and needs to be fixed manually.
  
          Some examples of replacements:
  
          \\\\text{Hello, world}  =>  \\\\text{" + $._("Hello, world") + "}
  
          \\\\text{' + BLAH + ' is happy}  =>
              \\\\text{' + $._("%(BLAH)s is happy", {BLAH: BLAH}) + '}
docstring_summary: Do \\text{} replacements inside of javascript
docstring_tokens: Do \\ text {} replacements inside of javascript
function: def _do_javascript_text_replace(match):
          """Do \\text{} replacements inside of javascript
  
          This takes a \\\\text{} string from some javascript and does the proper
          i18nization of its inner contents. Sometimes, if javascript variables
          are inside the contents, it will pull them out and do a string
          interpolation using $._.
  
          Note that this doesn't currently handle pure string concatenation very
          well, so something like \\\\text{" + "hello " + ", " + "world" + "}
          will produce something weird, and needs to be fixed manually.
  
          Some examples of replacements:
  
          \\\\text{Hello, world}  =>  \\\\text{" + $._("Hello, world") + "}
  
          \\\\text{' + BLAH + ' is happy}  =>
              \\\\text{' + $._("%(BLAH)s is happy", {BLAH: BLAH}) + '}
          """
          # Pull out the parts from the match
          # Note that the searching regex is kinda strange, so the string:
          #       '\\text{  hello" + world + "   }'
          # will get split into the parts:
          #    '\\text{  '   'hello" + world + "'    '   }'
          # which has semi-strange quoting in the content string
          (text_start, text_content, text_end) = match.groups()
  
          # If the match doesn't have any natural-language text in it,
          # make no changes.
          if MathJaxTextFilter._nonalpha_re.match(text_content):
              return match.group(0)
  
          # The main regex
          search_re = re.compile(
              r"""["']\s*\+\s*(.*?)\s*\+\s*["']""",
              re.DOTALL)
  
          #TODO(emily): We should probably use a real javascript parser for this
          # at some point instead of this hacky regex system, so that we can do
          # more complex parsing and won't get as many strange bugs (for example,
          # there's a weird bug when you just have a bunch of string literals
          # concatenated together, or when you put single quotes inside of double
          # quotes, etc. The jslexer from third_party.babel might be able to help
          # with this (if we can handle whitespace more robustly)
  
          # Check if we have to do anything, or if the inner string has
          # already been fixed.
  
          # If there aren't quotes right at the beginning
          if (not re.match(r"""["']\s*\+""", text_content) or
                  # or if there aren't quotes right at the end
                  not re.search(r"""\+\s*["']$""", text_content) or
                  # or if there is a place inside where string concatenation with
                  # a variable is done
                  len(search_re.findall(text_content)) != 1):
              # If there are string concatenations, we need to do interpolation
              if search_re.search(text_content):
                  # Figure out the quoting style of the beginning and end, so we
                  # can replace it correctly
                  start_quote = re.search(r"""^[^'"]*(['"])""", text_content)
                  end_quote = re.search(r"""(['"])[^'"]*$""", text_content)
  
                  # Store of our variable values
                  var_dict = collections.OrderedDict()
  
                  # Do the replacements
                  interp_string = search_re.sub(
                          MathJaxTextFilter.var_replace_builder(var_dict),
                          text_content)
  
                  # Re-build our string with the replacements
                  text_content = '%s + $._("%s", %s) + %s' % (
                          start_quote.group(1),
                          interp_string,
                          MathJaxTextFilter._javascript_dumps(var_dict),
                          end_quote.group(1))
              else:
                  # Otherwise, just wrap in $._
                  text_content = '" + $._("%s") + "' % text_content
  
          # Finally, re-assemble the entire thing
          return text_start + text_content + text_end
function_tokens: def _do_javascript_text_replace ( match ) : # Pull out the parts from the match # Note that the searching regex is kinda strange, so the string: #       '\\text{  hello" + world + "   }' # will get split into the parts: #    '\\text{  '   'hello" + world + "'    '   }' # which has semi-strange quoting in the content string ( text_start , text_content , text_end ) = match . groups ( ) # If the match doesn't have any natural-language text in it, # make no changes. if MathJaxTextFilter . _nonalpha_re . match ( text_content ) : return match . group ( 0 ) # The main regex search_re = re . compile ( r"""["']\s*\+\s*(.*?)\s*\+\s*["']""" , re . DOTALL ) #TODO(emily): We should probably use a real javascript parser for this # at some point instead of this hacky regex system, so that we can do # more complex parsing and won't get as many strange bugs (for example, # there's a weird bug when you just have a bunch of string literals # concatenated together, or when you put single quotes inside of double # quotes, etc. The jslexer from third_party.babel might be able to help # with this (if we can handle whitespace more robustly) # Check if we have to do anything, or if the inner string has # already been fixed. # If there aren't quotes right at the beginning if ( not re . match ( r"""["']\s*\+""" , text_content ) or # or if there aren't quotes right at the end not re . search ( r"""\+\s*["']$""" , text_content ) or # or if there is a place inside where string concatenation with # a variable is done len ( search_re . findall ( text_content ) ) != 1 ) : # If there are string concatenations, we need to do interpolation if search_re . search ( text_content ) : # Figure out the quoting style of the beginning and end, so we # can replace it correctly start_quote = re . search ( r"""^[^'"]*(['"])""" , text_content ) end_quote = re . search ( r"""(['"])[^'"]*$""" , text_content ) # Store of our variable values var_dict = collections . OrderedDict ( ) # Do the replacements interp_string = search_re . sub ( MathJaxTextFilter . var_replace_builder ( var_dict ) , text_content ) # Re-build our string with the replacements text_content = '%s + $._("%s", %s) + %s' % ( start_quote . group ( 1 ) , interp_string , MathJaxTextFilter . _javascript_dumps ( var_dict ) , end_quote . group ( 1 ) ) else : # Otherwise, just wrap in $._ text_content = '" + $._("%s") + "' % text_content # Finally, re-assemble the entire thing return text_start + text_content + text_end