Allows Typogrify to ignore user specified tags. Refs #1407

Typogrify interferes with certain sections of the output that it should not touch (see #1407 for more details).
This feature adds a setting called TYPOGRIFY_IGNORE_LIST which is a list of tag for Typogrify to ignore.

The following was updated:

 1. readers.py - if TYPOGRIFY_IGNORE_TAGS is present, then use it
 2. settings.ps - default TYPOGRIFY_IGNORE_TAGS to []
 3. contents/article_with_code_block.rst - an article with a code block for typogrify to ignore
 4. updated tests
 5. updated documentation
This commit is contained in:
Barry Steyn 2014-07-19 15:07:44 -07:00
commit a0ecab901f
6 changed files with 79 additions and 3 deletions

View file

@ -0,0 +1,15 @@
An Article With Code Block To Test Typogrify Ignore
###################################################
An article with some code
.. code-block:: python
x & y
A block quote:
x & y
Normal:
x & y

View file

@ -114,6 +114,8 @@ class TestArticlesGenerator(unittest.TestCase):
'article'],
['This is an article without category !', 'published',
'TestCategory', 'article'],
['An Article With Code Block To Test Typogrify Ignore',
'published', 'Default', 'article'],
['マックOS X 10.8でパイソンとVirtualenvをインストールと設定', 'published',
'指導書', 'article'],
]

View file

@ -153,6 +153,52 @@ class RstReaderTest(ReaderTest):
except ImportError:
return unittest.skip('need the typogrify distribution')
def test_typogrify_ignore_tags(self):
try:
# typogrify should be able to ignore user specified tags,
# but tries to be clever with widont extension
page = self.read_file(path='article.rst', TYPOGRIFY=True,
TYPOGRIFY_IGNORE_TAGS = ['p'])
expected = ('<p>THIS is some content. With some stuff to&nbsp;'
'&quot;typogrify&quot;...</p>\n<p>Now with added '
'support for <abbr title="three letter acronym">'
'TLA</abbr>.</p>\n')
self.assertEqual(page.content, expected)
# typogrify should ignore code blocks by default because
# code blocks are composed inside the pre tag
page = self.read_file(path='article_with_code_block.rst',
TYPOGRIFY=True)
expected = ('<p>An article with some&nbsp;code</p>\n'
'<div class="highlight"><pre><span class="n">x</span>'
' <span class="o">&amp;</span>'
' <span class="n">y</span>\n</pre></div>\n'
'<p>A block&nbsp;quote:</p>\n<blockquote>\nx '
'<span class="amp">&amp;</span> y</blockquote>\n'
'<p>Normal:\nx <span class="amp">&amp;</span>&nbsp;y</p>\n')
self.assertEqual(page.content, expected)
# instruct typogrify to also ignore blockquotes
page = self.read_file(path='article_with_code_block.rst',
TYPOGRIFY=True, TYPOGRIFY_IGNORE_TAGS = ['blockquote'])
expected = ('<p>An article with some&nbsp;code</p>\n'
'<div class="highlight"><pre><span class="n">x</span>'
' <span class="o">&amp;</span>'
' <span class="n">y</span>\n</pre></div>\n'
'<p>A block&nbsp;quote:</p>\n<blockquote>\nx '
'&amp; y</blockquote>\n'
'<p>Normal:\nx <span class="amp">&amp;</span>&nbsp;y</p>\n')
self.assertEqual(page.content, expected)
except ImportError:
return unittest.skip('need the typogrify distribution')
except TypeError:
return unittest.skip('need typogrify version 2.0.4 or later')
def test_article_with_multiple_authors(self):
page = self.read_file(path='article_with_multiple_authors.rst')
expected = {