Add Typogrify/SmartyPants dashes config parameter (#2615)

This commit is contained in:
fancsali 2020-04-16 12:32:19 +01:00 committed by GitHub
commit f610801ee8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 0 deletions

View file

@ -0,0 +1,3 @@
Title: One -, two --, three --- dashes!
One: -; Two: --; Three: ---

View file

@ -0,0 +1,4 @@
One -, two --, three --- dashes!
################################
One: -; Two: --; Three: ---

View file

@ -248,6 +248,10 @@ class TestArticlesGenerator(unittest.TestCase):
['Article with template', 'published', 'Default', 'custom'],
['Metadata tags as list!', 'published', 'Default', 'article'],
['Rst with filename metadata', 'published', 'yeah', 'article'],
['One -, two --, three --- dashes!', 'published', 'Default',
'article'],
['One -, two --, three --- dashes!', 'published', 'Default',
'article'],
['Test Markdown extensions', 'published', 'Default', 'article'],
['Test markdown File', 'published', 'test', 'article'],
['Test md File', 'published', 'test', 'article'],
@ -562,6 +566,8 @@ class TestArticlesGenerator(unittest.TestCase):
'Article with markdown containing footnotes',
'Article with template',
'Metadata tags as list!',
'One -, two --, three --- dashes!',
'One -, two --, three --- dashes!',
'Rst with filename metadata',
'Test Markdown extensions',
'Test markdown File',

View file

@ -443,6 +443,40 @@ class RstReaderTest(ReaderTest):
with self.assertRaisesRegex(Exception, "underline too short"):
self.read_file(path='../parse_error/parse_error.rst')
def test_typogrify_dashes_config(self):
# Test default config
page = self.read_file(
path='article_with_typogrify_dashes.rst',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='default')
expected = "<p>One: -; Two: &#8212;; Three:&nbsp;&#8212;-</p>\n"
expected_title = "One -, two &#8212;, three &#8212;-&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
# Test 'oldschool' variant
page = self.read_file(
path='article_with_typogrify_dashes.rst',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='oldschool')
expected = "<p>One: -; Two: &#8211;; Three:&nbsp;&#8212;</p>\n"
expected_title = "One -, two &#8211;, three &#8212;&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
# Test 'oldschool_inverted' variant
page = self.read_file(
path='article_with_typogrify_dashes.rst',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='oldschool_inverted')
expected = "<p>One: -; Two: &#8212;; Three:&nbsp;&#8211;</p>\n"
expected_title = "One -, two &#8212;, three &#8211;&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
@unittest.skipUnless(readers.Markdown, "markdown isn't installed")
class MdReaderTest(ReaderTest):
@ -674,6 +708,40 @@ class MdReaderTest(ReaderTest):
self.assertEqual(metadata, {})
self.assertEqual(content, '')
def test_typogrify_dashes_config(self):
# Test default config
page = self.read_file(
path='article_with_typogrify_dashes.md',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='default')
expected = "<p>One: -; Two: &#8212;; Three:&nbsp;&#8212;-</p>"
expected_title = "One -, two &#8212;, three &#8212;-&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
# Test 'oldschool' variant
page = self.read_file(
path='article_with_typogrify_dashes.md',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='oldschool')
expected = "<p>One: -; Two: &#8211;; Three:&nbsp;&#8212;</p>"
expected_title = "One -, two &#8211;, three &#8212;&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
# Test 'oldschool_inverted' variant
page = self.read_file(
path='article_with_typogrify_dashes.md',
TYPOGRIFY=True,
TYPOGRIFY_DASHES='oldschool_inverted')
expected = "<p>One: -; Two: &#8212;; Three:&nbsp;&#8211;</p>"
expected_title = "One -, two &#8212;, three &#8211;&nbsp;dashes!"
self.assertEqual(page.content, expected)
self.assertEqual(page.title, expected_title)
class HTMLReaderTest(ReaderTest):
def test_article_with_comments(self):