'Do \text{} replacements inside of html nodes
This takes a \text{} string from a <code> tag and does the proper
i18nization of the contents. Sometimes, if there are javascript
expressions (in the form of <var> tags) inside of the \text{}, it has
to use the string interpolation of i18n._ to appropriately translate.
For example:
\text{Hello, world}  =>  \text{<var>i18n._("Hello, world"}
\text{<var>BLAH</var> is happy}  =>
\text{<var>i18n._("%(BLAH)s is happy", {BLAH: BLAH})</var>}'

@staticmethod
def _do_html_text_replace(match):

    (text_start, text_content, text_end) = match.groups()
    text_content_no_var = re.sub('<var>.*?</var>', '', text_content)
    if MathJaxTextFilter._nonalpha_re.match(text_content_no_var):
        return match.group(0)
    search_re = re.compile('<var>(.*?)</var>', re.DOTALL)
    if ((not re.match('<var>', text_content)) or (not re.search('</var>$', text_content)) or (len(search_re.findall(text_content)) != 1)):
        if search_re.search(text_content):
            var_dict = collections.OrderedDict()
            interp_string = search_re.sub(MathJaxTextFilter.var_replace_builder(var_dict), text_content)
            text_content = ('<var>i18n._("%s",    %s)</var>' % (interp_string, MathJaxTextFilter._javascript_dumps(var_dict)))
        else:
            text_content = ('<var>i18n._("%s")</var>' % text_content)
    return ((text_start + text_content) + text_end)
