Skip to content

Commit

Permalink
Add :confval:smartquotes_excludes
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Dec 30, 2017
1 parent d17b898 commit 88a6e24
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
19 changes: 18 additions & 1 deletion doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ General configuration

.. versionadded:: 1.6.6
It replaces deprecated :confval:`html_use_smartypants`.
It applies to all builders.
It applies by default to all builders except ``man`` and ``text``
(see :confval:`smartquotes_excludes`.)

A `docutils.conf`__ file located in the configuration directory (or a
global :file:`~/.docutils` file) will be obeyed if it deactivates smart
Expand All @@ -386,6 +387,22 @@ General configuration

__ https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/

.. confval:: smartquotes_excludes

This is a ``set`` whose default is::

{'language': ['ja'], 'builder': ['man', 'text']}

It gives sufficient condition to ignore the :confval:`smart_quotes` setting
and deactivate the Smart Quotes transform. The keys must be ``'builder'``
or names of configuration settings. The values are lists. Please note
that in case of invocation of ``make`` with multiple builder names, the
first one counts. Also, when using ``sphinx-build`` in succession for
different builders, one needs to use ``-E`` option (e.g. in case of an
``html`` build followed by a ``man`` build, or conversely.)

.. versionadded:: 1.6.6

.. confval:: tls_verify

If true, Sphinx verifies server certifications. Default is ``True``.
Expand Down
3 changes: 3 additions & 0 deletions sphinx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class Config(object):
tls_cacerts = (None, 'env'),
smart_quotes = (True, 'env'),
smartquotes_action = ('qDe', 'env'),
smartquotes_excludes = ({'language': ['ja'],
'builder': ['man', 'text']},
'env'),
) # type: Dict[unicode, Tuple]

def __init__(self, dirname, filename, overrides, tags):
Expand Down
18 changes: 17 additions & 1 deletion sphinx/environment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from copy import copy
from collections import defaultdict

from six import BytesIO, itervalues, class_types, next
from six import BytesIO, itervalues, class_types, next, iteritems
from six.moves import cPickle as pickle

from docutils.io import NullOutput
Expand Down Expand Up @@ -685,6 +685,22 @@ def read_doc(self, docname, app=None):
RemovedInSphinx17Warning)
self.settings['smart_quotes'] = self.config.html_use_smartypants

# some conditions exclude smart quotes, overriding smart_quotes
for valname, vallist in iteritems(self.config.smartquotes_excludes):
if valname == 'builder':
# this will work only for checking first build target
if self.app.builder.name in vallist:
self.settings['smart_quotes'] = False
break
else:
try:
attr = getattr(self.config, valname)
if attr in vallist:
self.settings['smart_quotes'] = False
break
except AttributeError:
pass

# confirm selected language supports smart_quotes or not
for tag in normalize_language_tag(language):
if tag in smartchars.quotes:
Expand Down

0 comments on commit 88a6e24

Please sign in to comment.