|
From: <mi...@us...> - 2021-04-07 12:09:54
|
Revision: 8671
http://sourceforge.net/p/docutils/code/8671
Author: milde
Date: 2021-04-07 12:09:51 +0000 (Wed, 07 Apr 2021)
Log Message:
-----------
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.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docutils/frontend.py
trunk/docutils/docutils/parsers/__init__.py
trunk/docutils/docutils/parsers/rst/__init__.py
trunk/docutils/docutils/transforms/frontmatter.py
trunk/docutils/docutils/transforms/parts.py
trunk/docutils/docutils/transforms/universal.py
trunk/docutils/docutils/utils/__init__.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/HISTORY.txt 2021-04-07 12:09:51 UTC (rev 8671)
@@ -8,22 +8,23 @@
:Contact: doc...@li...
: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)
=========================
Modified: trunk/docutils/docutils/frontend.py
===================================================================
--- trunk/docutils/docutils/frontend.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/frontend.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -332,6 +332,13 @@
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 @@
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:
Modified: trunk/docutils/docutils/parsers/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/__init__.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/parsers/__init__.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -51,6 +51,10 @@
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)
Modified: trunk/docutils/docutils/parsers/rst/__init__.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/__init__.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/parsers/rst/__init__.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -163,6 +163,9 @@
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,
Modified: trunk/docutils/docutils/transforms/frontmatter.py
===================================================================
--- trunk/docutils/docutils/transforms/frontmatter.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/transforms/frontmatter.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -241,7 +241,7 @@
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 @@
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 @@
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 @@
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*``)
Modified: trunk/docutils/docutils/transforms/parts.py
===================================================================
--- trunk/docutils/docutils/transforms/parts.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/transforms/parts.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -86,10 +86,8 @@
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
Modified: trunk/docutils/docutils/transforms/universal.py
===================================================================
--- trunk/docutils/docutils/transforms/universal.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/transforms/universal.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -260,7 +260,8 @@
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:
Modified: trunk/docutils/docutils/utils/__init__.py
===================================================================
--- trunk/docutils/docutils/utils/__init__.py 2021-04-07 12:04:36 UTC (rev 8670)
+++ trunk/docutils/docutils/utils/__init__.py 2021-04-07 12:09:51 UTC (rev 8671)
@@ -552,9 +552,8 @@
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|