Add Typogrify dash config

This commit is contained in:
Daniel Fancsali 2018-11-05 02:16:03 +01:00
commit fe3fe0126b
3 changed files with 17 additions and 0 deletions

View file

@ -264,6 +264,16 @@ Basic settings
``pre`` and ``code`` tags. This requires that Typogrify version 2.0.4 or ``pre`` and ``code`` tags. This requires that Typogrify version 2.0.4 or
later is installed later is installed
.. data:: TYPOGRIFY_DASHES = 'default'
How should Typogrify set up the smartypants filter to interpret multiple
hyphen-minus characters? A single ASCII hyphen-minus characters is always
rendered as a hyphen. By ``default`` only em-dashes would be generated, by
typing double hyphens. The ``oldschool``-style would cause both en-dashes
and em-dashes to be rendered, by typing 2 and 3 hyphen-minus characters,
respectively. The ``oldschool_inverted`` setting causes them to be
interpreted the other way around.
.. data:: SUMMARY_MAX_LENGTH = 50 .. data:: SUMMARY_MAX_LENGTH = 50
When creating a short summary of an article, this will be the default length When creating a short summary of an article, this will be the default length

View file

@ -604,6 +604,12 @@ class Readers(FileStampDataCacher):
from typogrify.filters import typogrify from typogrify.filters import typogrify
import smartypants import smartypants
typogrify_dashes = self.settings['TYPOGRIFY_DASHES']
if typogrify_dashes == 'oldschool':
smartypants.Attr.default = smartypants.Attr.set2
elif typogrify_dashes == 'oldschool_inverted':
smartypants.Attr.default = smartypants.Attr.set3
# Tell `smartypants` to also replace " HTML entities with # Tell `smartypants` to also replace " HTML entities with
# smart quotes. This is necessary because Docutils has already # smart quotes. This is necessary because Docutils has already
# replaced double quotes with said entities by the time we run # replaced double quotes with said entities by the time we run

View file

@ -142,6 +142,7 @@ DEFAULT_CONFIG = {
'ARTICLE_PERMALINK_STRUCTURE': '', 'ARTICLE_PERMALINK_STRUCTURE': '',
'TYPOGRIFY': False, 'TYPOGRIFY': False,
'TYPOGRIFY_IGNORE_TAGS': [], 'TYPOGRIFY_IGNORE_TAGS': [],
'TYPOGRIFY_DASHES': 'default',
'SUMMARY_MAX_LENGTH': 50, 'SUMMARY_MAX_LENGTH': 50,
'PLUGIN_PATHS': [], 'PLUGIN_PATHS': [],
'PLUGINS': [], 'PLUGINS': [],