Issues

Issue #647 resolved

parsed-literal blocks shouldn't be processed by SmartyPants

tpowers
created an issue

In writers\html.py the following is done: {{{

!python

def visit_literal_block(self, node):
    if node.rawsource != node.astext():
        # most probably a parsed-literal block -- don't highlight
        return BaseTranslator.visit_literal_block(self, node)

}}} therefore I'm pretty sure that: {{{

!python

# overwritten
def visit_Text(self, node):

    ...

    else:
        if self.in_mailto and self.settings.cloak_email_addresses:
            encoded = self.cloak_email(encoded)
        else:
            encoded = self.bulk_text_processor(encoded)
        self.body.append(encoded)

}}} should be changed to: {{{

!python

# overwritten
def visit_Text(self, node):

    ...

    else:
        if self.in_mailto and self.settings.cloak_email_addresses:
            encoded = self.cloak_email(encoded)
        elif node.rawsource == text:
            encoded = self.bulk_text_processor(encoded)
        self.body.append(encoded)

}}} given that: {{{

!python

def bulk_text_processor(self, text):
    if self.no_smarty <= 0:
        return sphinx_smarty_pants(text)
    return text

}}} or something similar to prevent SmartyPants processing from being done on parsed-literal blocks.

Otherwise "normal" quote characters get converted to smart quotes which, for example, doesn't work when documenting command lines that need to be copied & pasted.

Comments (8)

  1. tpowers reporter

    Ooops. Above suggestion doesn't work since it also blocks smartypants processing on other nodes that happen to do substitutions.

    Instead you might have to add an self.in_literalblock flag to keep track of when you are processing a literal block?

  2. tpowers reporter

    Here's a fix that seems to work:

    in writers\html.py:

    class HTMLTranslator(BaseTranslator):
    
        def __init__(self, builder, *args, **kwds):
            ...
            self.protect_literal_text = 0
            self.protect_literal_block = 0
            ...
    
        def visit_literal_block(self, node):
            self.protect_literal_block += 1
            ...
    
        def depart_literal_block(self, node):
            BaseTranslator.depart_literal_block(self, node)
            self.protect_literal_block -= 1
    
        def visit_Text(self, node):
            ...
                elif self.protect_literal_block <= 0:
                    encoded = self.bulk_text_processor(encoded)
    
  3. tpowers reporter

    Hmmm. Looks like that last "fix" also doesn't work correctly. It turns off SmartyPants processing for more than just literal_blocks for some reason. Some number of paragraphs after the parsed-literal are also not processed by SmartyPants?

  4. Log in to comment