forked from github/pelican
Add a way to use Typogrify to enhance the generated HTML.
This commit is contained in:
parent
fbf89687cc
commit
d43bd1dcb8
5 changed files with 41 additions and 2 deletions
|
|
@ -69,6 +69,11 @@ Setting name (default value) What does it do?
|
|||
`TIMEZONE` The timezone used in the date information, to
|
||||
generate Atom and RSS feeds. See the "timezone"
|
||||
section below for more info.
|
||||
`TYPOGRIFY` (``False``) If set to true, some
|
||||
additional transformations will be done on the
|
||||
generated HTML, using the `Typogrify
|
||||
<http://static.mintchaos.com/projects/typogrify/>`_
|
||||
library
|
||||
================================================ =====================================================
|
||||
|
||||
.. [#] Default is the system locale.
|
||||
|
|
|
|||
|
|
@ -143,12 +143,24 @@ def read_file(filename, fmt=None, settings=None):
|
|||
"""Return a reader object using the given format."""
|
||||
if not fmt:
|
||||
fmt = filename.split('.')[-1]
|
||||
|
||||
if fmt not in _EXTENSIONS.keys():
|
||||
raise TypeError('Pelican does not know how to parse %s' % filename)
|
||||
|
||||
reader = _EXTENSIONS[fmt](settings)
|
||||
settings_key = '%s_EXTENSIONS' % fmt.upper()
|
||||
|
||||
if settings and settings_key in settings:
|
||||
reader.extensions = settings[settings_key]
|
||||
|
||||
if not reader.enabled:
|
||||
raise ValueError("Missing dependencies for %s" % fmt)
|
||||
return reader.read(filename)
|
||||
|
||||
content, metadata = reader.read(filename)
|
||||
|
||||
# eventually filter the content with typogrify if asked so
|
||||
if settings and settings['TYPOGRIFY']:
|
||||
from typogrify import Typogrify
|
||||
content = Typogrify.typogrify(content)
|
||||
|
||||
return content, metadata
|
||||
|
|
|
|||
|
|
@ -57,7 +57,8 @@ _DEFAULT_CONFIG = {'PATH': None,
|
|||
'DEFAULT_METADATA': (),
|
||||
'FILES_TO_COPY': (),
|
||||
'DEFAULT_STATUS': 'published',
|
||||
'ARTICLE_PERMALINK_STRUCTURE': ''
|
||||
'ARTICLE_PERMALINK_STRUCTURE': '',
|
||||
'TYPOGRIFY': False,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
4
tests/content/article.rst
Normal file
4
tests/content/article.rst
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Article title
|
||||
#############
|
||||
|
||||
This is some content. With some stuff to "typogrify".
|
||||
|
|
@ -33,3 +33,20 @@ class RstReaderTest(unittest.TestCase):
|
|||
|
||||
for key, value in expected.items():
|
||||
self.assertEquals(value, metadata[key], key)
|
||||
|
||||
def test_typogrify(self):
|
||||
# if nothing is specified in the settings, the content should be
|
||||
# unmodified
|
||||
content, _ = readers.read_file(_filename('article.rst'))
|
||||
expected = "<p>This is some content. With some stuff to "\
|
||||
""typogrify".</p>\n"
|
||||
|
||||
self.assertEqual(content, expected)
|
||||
|
||||
# otherwise, typogrify should be applied
|
||||
content, _ = readers.read_file(_filename('article.rst'),
|
||||
settings={'TYPOGRIFY': True})
|
||||
expected = "<p>This is some content. With some stuff to "\
|
||||
"“typogrify”.</p>\n"
|
||||
|
||||
self.assertEqual(content, expected)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue