parsed-literal blocks shouldn't be processed by SmartyPants

tpowers avatartpowers created an issue

In writers\html.py the following is done:

    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:

    # 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:

    # 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:

    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 (6)

  1. tpowers

    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

    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

    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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.