summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2021-04-07 12:09:51 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2021-04-07 12:09:51 +0000
commitc03e76a5eda8518a9dd7355ab483f4cf5153422c (patch)
treebc7bd630a823840386e784a5c73c79442fb9a111 /docutils
parent881989f11b0c2e1498c7ebbbb5476c24b21bc69e (diff)
downloaddocutils-c03e76a5eda8518a9dd7355ab483f4cf5153422c.tar.gz
Provide fallbacks for parser config settings.
Some 3rd party applications fail with AttributeError due to missing values in the document.settings object. a) because they don't follow the requirement documented in utils.new_document: If you will use the document object with any Docutils components, you must provide their default settings as well. b) because they may provide a hard-coded set missing new settings. This should fix bug #415 and https://github.com/readthedocs/recommonmark/issues/220. See also the sphinx issue with Docutils 0.13.1 https://github.com/sphinx-doc/sphinx/issues/3951. git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@8671 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/HISTORY.txt13
-rw-r--r--docutils/docutils/frontend.py9
-rw-r--r--docutils/docutils/parsers/__init__.py4
-rw-r--r--docutils/docutils/parsers/rst/__init__.py3
-rw-r--r--docutils/docutils/transforms/frontmatter.py8
-rw-r--r--docutils/docutils/transforms/parts.py6
-rw-r--r--docutils/docutils/transforms/universal.py3
-rw-r--r--docutils/docutils/utils/__init__.py5
8 files changed, 32 insertions, 19 deletions
diff --git a/docutils/HISTORY.txt b/docutils/HISTORY.txt
index 5f43669f1..d949170c4 100644
--- a/docutils/HISTORY.txt
+++ b/docutils/HISTORY.txt
@@ -8,22 +8,23 @@
:Contact: docutils-develop@lists.sourceforge.net
:Date: $Date$
:Revision: $Revision$
-:Web site: http://docutils.sourceforge.net/
+:Web site: https://docutils.sourceforge.io/
:Copyright: This document has been placed in the public domain.
.. contents::
-
Changes Since 0.17
==================
-* latex docutils.sty
+* manpage writer
- - replace unicode copyright by ``(c)``.
+ - Apply patch #160: move macro defs above ``.TH``
+ (thanks Willie and sorry for the delay).
-* manpage writer
+* docutils/parsers/*.py, docutils/transforms/*.py
- - Apply patch #160: move macro defs above .TH (thanks Willie and sorry for the delay).
+ - Provide fallbacks for parser config settings
+ to facilitate programmatic use.
Release 0.17 (2021-04-03)
=========================
diff --git a/docutils/docutils/frontend.py b/docutils/docutils/frontend.py
index c9f981887..db8025d17 100644
--- a/docutils/docutils/frontend.py
+++ b/docutils/docutils/frontend.py
@@ -332,6 +332,13 @@ class Values(optparse.Values):
def copy(self):
"""Return a shallow copy of `self`."""
return self.__class__(defaults=self.__dict__)
+
+ def setdefault(self, name, default):
+ """V.setdefault(n[,d]) -> getattr(V,n,d), also set D.n=d if n not in D or None.
+ """
+ if getattr(self, name, None) is None:
+ setattr(self, name, default)
+ return getattr(self, name)
class Option(optparse.Option):
@@ -637,7 +644,7 @@ class OptionParser(optparse.OptionParser, docutils.SettingsSpec):
option = group.add_option(help=help_text, *option_strings,
**kwargs)
if kwargs.get('action') == 'append':
- self.lists[option.dest] = 1
+ self.lists[option.dest] = True
if component.settings_defaults:
self.defaults.update(component.settings_defaults)
for component in components:
diff --git a/docutils/docutils/parsers/__init__.py b/docutils/docutils/parsers/__init__.py
index bf614ef55..7ee59cb82 100644
--- a/docutils/docutils/parsers/__init__.py
+++ b/docutils/docutils/parsers/__init__.py
@@ -51,6 +51,10 @@ class Parser(Component):
def setup_parse(self, inputstring, document):
"""Initial parse setup. Call at start of `self.parse()`."""
self.inputstring = inputstring
+ # provide fallbacks in case the document has only generic settings
+ document.settings.setdefault('file_insertion_enabled', False)
+ document.settings.setdefault('raw_enabled', False)
+ document.settings.setdefault('line_length_limit', 10000)
self.document = document
document.reporter.attach_observer(document.note_parse_message)
diff --git a/docutils/docutils/parsers/rst/__init__.py b/docutils/docutils/parsers/rst/__init__.py
index 921977e25..0ca7b34a9 100644
--- a/docutils/docutils/parsers/rst/__init__.py
+++ b/docutils/docutils/parsers/rst/__init__.py
@@ -163,6 +163,9 @@ class Parser(docutils.parsers.Parser):
def parse(self, inputstring, document):
"""Parse `inputstring` and populate `document`, a document tree."""
self.setup_parse(inputstring, document)
+ # provide fallbacks in case the document has only generic settings
+ self.document.settings.setdefault('tab_width', 8)
+ self.document.settings.setdefault('syntax_highlight', 'long')
self.statemachine = states.RSTStateMachine(
state_classes=self.state_classes,
initial_state=self.initial_state,
diff --git a/docutils/docutils/transforms/frontmatter.py b/docutils/docutils/transforms/frontmatter.py
index 602dea7b5..add5390f0 100644
--- a/docutils/docutils/transforms/frontmatter.py
+++ b/docutils/docutils/transforms/frontmatter.py
@@ -241,7 +241,7 @@ class DocTitle(TitlePromoter):
self.document['title'] = self.document[0].astext()
def apply(self):
- if getattr(self.document.settings, 'doctitle_xform', 1):
+ if self.document.settings.setdefault('doctitle_xform', True):
# promote_(sub)title defined in TitlePromoter base class.
if self.promote_title(self.document):
# If a title has been promoted, also try to promote a
@@ -279,7 +279,7 @@ class SectionSubTitle(TitlePromoter):
default_priority = 350
def apply(self):
- if not getattr(self.document.settings, 'sectsubtitle_xform', 1):
+ if not self.document.settings.setdefault('sectsubtitle_xform', True):
return
for section in self.document._traverse(nodes.section):
# On our way through the node tree, we are modifying it
@@ -383,7 +383,7 @@ class DocInfo(Transform):
bibliographic fields (field_list)."""
def apply(self):
- if not getattr(self.document.settings, 'docinfo_xform', 1):
+ if not self.document.settings.setdefault('docinfo_xform', True):
return
document = self.document
index = document.first_child_not_matching_class(
@@ -508,7 +508,7 @@ class DocInfo(Transform):
def authors_from_one_paragraph(self, field):
"""Return list of Text nodes for authornames.
-
+
The set of separators is locale dependent (default: ";"- or ",").
"""
# @@ keep original formatting? (e.g. ``:authors: A. Test, *et-al*``)
diff --git a/docutils/docutils/transforms/parts.py b/docutils/docutils/transforms/parts.py
index 42e7bab30..c077becaf 100644
--- a/docutils/docutils/transforms/parts.py
+++ b/docutils/docutils/transforms/parts.py
@@ -86,10 +86,8 @@ class Contents(Transform):
default_priority = 720
def apply(self):
- try: # let the writer (or output software) build the contents list?
- toc_by_writer = self.document.settings.use_latex_toc
- except AttributeError:
- toc_by_writer = False
+ # let the writer (or output software) build the contents list?
+ toc_by_writer = getattr(self.document.settings, 'use_latex_toc', False)
details = self.startnode.details
if 'local' in details:
startnode = self.startnode.parent.parent
diff --git a/docutils/docutils/transforms/universal.py b/docutils/docutils/transforms/universal.py
index e0d1c32ff..a4d948fd5 100644
--- a/docutils/docutils/transforms/universal.py
+++ b/docutils/docutils/transforms/universal.py
@@ -260,7 +260,8 @@ class SmartQuotes(Transform):
yield ('plain', txt)
def apply(self):
- smart_quotes = self.document.settings.smart_quotes
+ smart_quotes = self.document.settings.setdefault('smart_quotes',
+ False)
if not smart_quotes:
return
try:
diff --git a/docutils/docutils/utils/__init__.py b/docutils/docutils/utils/__init__.py
index 425eb29e7..5bb0b501c 100644
--- a/docutils/docutils/utils/__init__.py
+++ b/docutils/docutils/utils/__init__.py
@@ -552,9 +552,8 @@ def get_trim_footnote_ref_space(settings):
If trim_footnote_reference_space is None, return False unless the
footnote reference style is 'superscript'.
"""
- if settings.trim_footnote_reference_space is None:
- return hasattr(settings, 'footnote_references') and \
- settings.footnote_references == 'superscript'
+ if settings.setdefault('trim_footnote_reference_space', None) is None:
+ return getattr(settings, 'footnote_references', None) == 'superscript'
else:
return settings.trim_footnote_reference_space