Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parsed-literal blocks shouldn't be processed by SmartyPants #647

Closed
shimizukawa opened this issue Jan 2, 2015 · 7 comments
Closed

parsed-literal blocks shouldn't be processed by SmartyPants #647

shimizukawa opened this issue Jan 2, 2015 · 7 comments

Comments

@shimizukawa
Copy link
Member

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.


@shimizukawa
Copy link
Member Author

From tpowers on 2011-02-24 23:38:08+00:00

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?

@shimizukawa
Copy link
Member Author

From tpowers on 2011-02-25 00:08:44+00:00

Here's a fix that seems to work:

in writers\html.py:
{{{
#!python
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)

}}}

@shimizukawa
Copy link
Member Author

From tpowers on 2011-03-02 16:38:17+00:00

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?

@shimizukawa
Copy link
Member Author

From Daniele Varrazzo on 2011-05-07 13:14:18+00:00

Bugged by the bug too.

The attached patch (against 1.0.7) works for me.

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2011-05-15 11:52:58+00:00

Closes #647: Do not apply SmartyPants in parsed-literal blocks.

→ <>

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2011-09-22 10:14:48+00:00

Removing milestone: 1.0 (automated comment)

@shimizukawa
Copy link
Member Author

From Georg Brandl on 2014-10-18 07:32:19+00:00

Removing version: 1.0.7 (automated comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant