From fe3fe0126b39a668149dee820f2f2913392f0f72 Mon Sep 17 00:00:00 2001 From: Daniel Fancsali Date: Mon, 5 Nov 2018 02:16:03 +0100 Subject: [PATCH] Add Typogrify dash config --- docs/settings.rst | 10 ++++++++++ pelican/readers.py | 6 ++++++ pelican/settings.py | 1 + 3 files changed, 17 insertions(+) diff --git a/docs/settings.rst b/docs/settings.rst index 640d0571..e4bbd7cb 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -264,6 +264,16 @@ Basic settings ``pre`` and ``code`` tags. This requires that Typogrify version 2.0.4 or 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 When creating a short summary of an article, this will be the default length diff --git a/pelican/readers.py b/pelican/readers.py index bacb45f8..d21ef388 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -604,6 +604,12 @@ class Readers(FileStampDataCacher): from typogrify.filters import typogrify 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 # smart quotes. This is necessary because Docutils has already # replaced double quotes with said entities by the time we run diff --git a/pelican/settings.py b/pelican/settings.py index b963007a..455e350f 100644 --- a/pelican/settings.py +++ b/pelican/settings.py @@ -142,6 +142,7 @@ DEFAULT_CONFIG = { 'ARTICLE_PERMALINK_STRUCTURE': '', 'TYPOGRIFY': False, 'TYPOGRIFY_IGNORE_TAGS': [], + 'TYPOGRIFY_DASHES': 'default', 'SUMMARY_MAX_LENGTH': 50, 'PLUGIN_PATHS': [], 'PLUGINS': [],