SF.net SVN: docutils:[9719 ] trunk/docutils
milde--- via Docutils-checkins <[email protected]>
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 9719
http://sourceforge.net/p/docutils/code/9719
Author: milde
Date: 2024-05-21 21:09:47 +0000 (Tue, 21 May 2024)
Log Message:
-----------
Stop generating invalid doctree if "use_latex_toc" setting is True.
The "use_latex_toc" setting tells Docutils to leave the ToC generation
LaTeX (to get a ToC with page numbers).
The "contents" directive generates a `<topic>` node with a nested
`<pending>` node. By default, the `parts.Contents` transform replaces
the `<pending>` node with a generated ToC in a `<bullet_list>`.
Keep the `<pending>` node if "use_latex_toc" is True to avoid an
empty (and hence invalid) `<topic>`.
Change the LaTeX writer to extract the value of the "content"
directive's options from the `<pending>` node.
This allows to drop "local" and "depth" from the attribute list of
`<topic>`, the "attributes reference" section in doctree.txt, and
the valid attributes in nodes.py.
Modified Paths:
--------------
trunk/docutils/docs/ref/doctree.txt
trunk/docutils/docs/ref/docutils.dtd
trunk/docutils/docutils/nodes.py
trunk/docutils/docutils/transforms/parts.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/test_writers/test_latex2e_misc.py
Modified: trunk/docutils/docs/ref/doctree.txt
===================================================================
--- trunk/docutils/docs/ref/doctree.txt 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/docs/ref/doctree.txt 2024-05-21 21:09:47 UTC (rev 9719)
@@ -3763,8 +3763,7 @@
(title?, (%body.elements;)+)
-:Attributes: The <topic> element accepts the `common attributes`_ plus
- depth_ and local_.
+:Attributes: The <topic> element accepts the `common attributes`_.
:Parameter Entities: The `%structure.model`_ parameter entity
directly includes <topic>.
@@ -4322,15 +4321,7 @@
separating it from the `\<option_string>`_ (typically either "=" or " ")
or the text between option arguments (typically either "," or " ").
-``depth``
-=========
-Attribute type: `%number`_. Default value: none.
-
-The ``depth`` attribute may be used in a `\<topic>`_ element generated by
-the `"contents" directive`_ to hold the value of the "depth" option.
-
-
``dupnames``
============
@@ -4426,15 +4417,6 @@
The ``line`` attribute is used in the `\<system_message>`_ element.
-``local``
-=========
-
-Attribute type: `%yesorno`_. Default value: none.
-
-The ``local`` attribute may be used in a `\<topic>` element generated by
-the `"contents" directive`_ to hold the value of the "local" option.
-
-
``ltrim``
=========
Modified: trunk/docutils/docs/ref/docutils.dtd
===================================================================
--- trunk/docutils/docs/ref/docutils.dtd 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/docs/ref/docutils.dtd 2024-05-21 21:09:47 UTC (rev 9719)
@@ -224,7 +224,7 @@
<!-- These parameter entities customize the table model DTD. -->
<!-- table element TODO: use %tbl.table.att. Keep or drop pgwide? -->
-<!ENTITY % bodyatt
+<!ENTITY % bodyatt
" %basic.atts;
%align-h.att;
width %measure; #IMPLIED ">
@@ -355,10 +355,7 @@
<!ATTLIST section %basic.atts;>
<!ELEMENT topic (title?, (%body.elements;)+)>
-<!ATTLIST topic
- %basic.atts;
- depth %number; #IMPLIED
- local %yesorno; #IMPLIED>
+<!ATTLIST topic %basic.atts;>
<!ELEMENT sidebar ((title, subtitle?)?, (%body.elements; | topic)+)>
<!ATTLIST sidebar %basic.atts;>
Modified: trunk/docutils/docutils/nodes.py
===================================================================
--- trunk/docutils/docutils/nodes.py 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/docutils/nodes.py 2024-05-21 21:09:47 UTC (rev 9719)
@@ -1817,8 +1817,6 @@
Topics cannot nest inside topics, or body elements; you can't have
a topic inside a table, list, block quote, etc.
"""
- # "depth" and "local" attributes may be added by the "Contents" transform:
- valid_attributes = Element.valid_attributes + ('depth', 'local')
valid_children = (title, Body) # (title?, (%body.elements;)+)
@@ -2886,7 +2884,6 @@
'colwidth': int, # sic! CALS: CDATA (measure or number+'*')
'content': str, # <meta>
'delimiter': str,
- 'depth': int,
'dir': validate_enumerated_type('ltr', 'rtl', 'auto'), # <meta>
'dupnames': validate_refname_list,
'enumtype': validate_enumerated_type('arabic', 'loweralpha', 'lowerroman',
@@ -2900,7 +2897,6 @@
'lang': str, # <meta>
'level': int,
'line': int,
- 'local': validate_yesorno,
'ltrim': validate_yesorno,
'loading': validate_enumerated_type('embed', 'link', 'lazy'),
'media': str, # <meta>
Modified: trunk/docutils/docutils/transforms/parts.py
===================================================================
--- trunk/docutils/docutils/transforms/parts.py 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/docutils/transforms/parts.py 2024-05-21 21:09:47 UTC (rev 9719)
@@ -87,6 +87,9 @@
def apply(self):
# let the writer (or output software) build the contents list?
toc_by_writer = getattr(self.document.settings, 'use_latex_toc', False)
+ # TODO: handle "generate_oowriter_toc" setting of the "ODT" writer.
+ if toc_by_writer:
+ return
details = self.startnode.details
if 'local' in details:
startnode = self.startnode.parent.parent
@@ -101,16 +104,11 @@
self.backlinks = details['backlinks']
else:
self.backlinks = self.document.settings.toc_backlinks
- if toc_by_writer:
- # move customization settings to the parent node
- self.startnode.parent.attributes.update(details)
- self.startnode.parent.remove(self.startnode)
+ contents = self.build_contents(startnode)
+ if len(contents):
+ self.startnode.replace_self(contents)
else:
- contents = self.build_contents(startnode)
- if len(contents):
- self.startnode.replace_self(contents)
- else:
- self.startnode.parent.parent.remove(self.startnode.parent)
+ self.startnode.parent.parent.remove(self.startnode.parent)
def build_contents(self, node, level=0):
level += 1
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2024-05-21 21:09:47 UTC (rev 9719)
@@ -3224,7 +3224,13 @@
return
# ToC by LaTeX
- depth = node.get('depth', 0)
+ try:
+ details = node.next_node(nodes.pending).details
+ except AttributeError:
+ self.warn('Setting "use_latex_toc" is True but "contents" details '
+ 'are missing. Directive option values may be lost.')
+ details = {}
+ depth = details.get('depth', 0)
maxdepth = len(self.d_class.sections)
if isinstance(node.next_node(), nodes.title):
title = self.encode(node[0].astext())
Modified: trunk/docutils/test/test_writers/test_latex2e_misc.py
===================================================================
--- trunk/docutils/test/test_writers/test_latex2e_misc.py 2024-05-19 16:17:27 UTC (rev 9718)
+++ trunk/docutils/test/test_writers/test_latex2e_misc.py 2024-05-21 21:09:47 UTC (rev 9719)
@@ -47,6 +47,7 @@
"""
settings = self.settings.copy()
settings['output_encoding'] = 'unicode'
+ settings['warning_stream'] = '' # don't warn for missing ToC details
doctree = core.publish_doctree(contents_test_input,
settings_overrides=settings)
result = core.publish_from_doctree(doctree,
@@ -53,7 +54,7 @@
writer_name='latex',
settings_overrides=settings)
self.assertNotIn(r'\item \hyperref[foo]{foo}', result)
- # self.assertIn(r'\tableofcontents', result)
+ self.assertIn(r'\tableofcontents', result)
def test_publish_parts(self):
"""Check for the presence of documented parts.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.