|
From: <mi...@us...> - 2020-07-10 10:08:17
|
Revision: 8524
http://sourceforge.net/p/docutils/code/8524
Author: milde
Date: 2020-07-10 10:08:14 +0000 (Fri, 10 Jul 2020)
Log Message:
-----------
Make the sidebar's "title" argument optional.
Feature request #69.
The analogous DocBook "sidebar" element's title is optional. too
(https://tdg.docbook.org/tdg/5.2/sidebar.html).
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/docs/ref/doctree.txt
trunk/docutils/docs/ref/docutils.dtd
trunk/docutils/docs/ref/rst/directives.txt
trunk/docutils/docs/user/rst/demo.txt
trunk/docutils/docutils/parsers/rst/directives/body.py
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
trunk/docutils/test/functional/expected/standalone_rst_html5.html
trunk/docutils/test/functional/expected/standalone_rst_latex.tex
trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
trunk/docutils/test/functional/input/data/standard.txt
trunk/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/HISTORY.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -40,6 +40,10 @@
- Apply version of patch #167: Let document.set_id() register all
existing IDs (thanks to Takeshi KOMIYA).
+* docutils/parsers/rst/directives/body.py:
+
+ - Make the sidebar's "title" argument optional (feature request #69).
+
* docutils/utils/smartquotes.py
- Fix #383: Smart quotes around opening and separator characters.
Modified: trunk/docutils/docs/ref/doctree.txt
===================================================================
--- trunk/docutils/docs/ref/doctree.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/docs/ref/doctree.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -3765,7 +3765,7 @@
section_
:Children:
- ``sidebar`` elements begin with a title_ and an optional subtitle_
+ ``sidebar`` elements begin with optional title_ and subtitle_
and contain `body elements`_ and topic_ elements.
:Analogues:
@@ -3801,7 +3801,7 @@
The `"sidebar" directive`_ is used to create a ``sidebar`` element.
reStructuredText_ source::
- .. sidebar:: Title
+ .. sidebar:: Optional Title
:subtitle: If Desired
Body.
@@ -3810,7 +3810,7 @@
<sidebar>
<title>
- Title
+ Optional Title
<subtitle>
If Desired
<paragraph>
Modified: trunk/docutils/docs/ref/docutils.dtd
===================================================================
--- trunk/docutils/docs/ref/docutils.dtd 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/docs/ref/docutils.dtd 2020-07-10 10:08:14 UTC (rev 8524)
@@ -350,7 +350,7 @@
<!ELEMENT topic (title?, (%body.elements;)+)>
<!ATTLIST topic %basic.atts;>
-<!ELEMENT sidebar (title, subtitle?, (%body.elements; | topic)+)>
+<!ELEMENT sidebar (title?, subtitle?, (%body.elements; | topic)+)>
<!ATTLIST sidebar %basic.atts;>
<!ELEMENT transition EMPTY>
Modified: trunk/docutils/docs/ref/rst/directives.txt
===================================================================
--- trunk/docutils/docs/ref/rst/directives.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/docs/ref/rst/directives.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -373,7 +373,7 @@
:Directive Type: "sidebar"
:Doctree Element: sidebar_
-:Directive Arguments: One, required (sidebar title).
+:Directive Arguments: One, optional (sidebar title).
:Directive Options: Possible (see below).
:Directive Content: Interpreted as the sidebar body.
@@ -392,7 +392,7 @@
must be blank. All subsequent lines make up the sidebar body,
interpreted as body elements. For example::
- .. sidebar:: Sidebar Title
+ .. sidebar:: Optional Sidebar Title
:subtitle: Optional Sidebar Subtitle
Subsequent indented lines comprise
Modified: trunk/docutils/docs/user/rst/demo.txt
===================================================================
--- trunk/docutils/docs/user/rst/demo.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/docs/user/rst/demo.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -470,7 +470,7 @@
Topics, Sidebars, and Rubrics
`````````````````````````````
-.. sidebar:: Sidebar Title
+.. sidebar:: Optional Sidebar Title
:subtitle: Optional Subtitle
This is a sidebar. It is for text outside the flow of the main
Modified: trunk/docutils/docutils/parsers/rst/directives/body.py
===================================================================
--- trunk/docutils/docutils/parsers/rst/directives/body.py 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/docutils/parsers/rst/directives/body.py 2020-07-10 10:08:14 UTC (rev 8524)
@@ -36,16 +36,20 @@
raise self.error('The "%s" directive may not be used within '
'topics or body elements.' % self.name)
self.assert_has_content()
- title_text = self.arguments[0]
- textnodes, messages = self.state.inline_text(title_text, self.lineno)
- titles = [nodes.title(title_text, '', *textnodes)]
- # Sidebar uses this code.
- if 'subtitle' in self.options:
- textnodes, more_messages = self.state.inline_text(
- self.options['subtitle'], self.lineno)
- titles.append(nodes.subtitle(self.options['subtitle'], '',
- *textnodes))
- messages.extend(more_messages)
+ if self.arguments: # title (in sidebars optional)
+ title_text = self.arguments[0]
+ textnodes, messages = self.state.inline_text(title_text, self.lineno)
+ titles = [nodes.title(title_text, '', *textnodes)]
+ # Sidebar uses this code.
+ if 'subtitle' in self.options:
+ textnodes, more_messages = self.state.inline_text(
+ self.options['subtitle'], self.lineno)
+ titles.append(nodes.subtitle(self.options['subtitle'], '',
+ *textnodes))
+ messages.extend(more_messages)
+ else:
+ titles = []
+ messages = []
text = '\n'.join(self.content)
node = self.node_class(text, *(titles + messages))
node['classes'] += self.options.get('class', [])
@@ -64,6 +68,8 @@
node_class = nodes.sidebar
+ required_arguments = 0
+ optional_arguments = 1
option_spec = BasePseudoSection.option_spec.copy()
option_spec['subtitle'] = directives.unchanged_required
@@ -71,6 +77,10 @@
if isinstance(self.state_machine.node, nodes.sidebar):
raise self.error('The "%s" directive may not be used within a '
'sidebar element.' % self.name)
+ if 'subtitle' in self.options and not self.arguments:
+ raise self.error('The "subtitle" option may not be used '
+ 'without a title.')
+
return BasePseudoSection.run(self)
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2020-07-10 10:08:14 UTC (rev 8524)
@@ -1203,7 +1203,7 @@
\emph{Sidebars} are like miniature, parallel documents.
\DUsidebar{
-\DUtitle[sidebar]{Sidebar Title}
+\DUtitle[sidebar]{Optional Sidebar Title}
\DUsubtitle{Optional Subtitle}
Modified: trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_docutils_xml.xml 2020-07-10 10:08:14 UTC (rev 8524)
@@ -1138,7 +1138,7 @@
<title auto="1" refid="toc-entry-46"><generated classes="sectnum">2.14.5 </generated>Topics, Sidebars, and Rubrics</title>
<paragraph><emphasis>Sidebars</emphasis> are like miniature, parallel documents.</paragraph>
<sidebar>
- <title>Sidebar Title</title>
+ <title>Optional Sidebar Title</title>
<subtitle>Optional Subtitle</subtitle>
<paragraph>This is a sidebar. It is for text outside the flow of the main
text.</paragraph>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html4css1.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_html4css1.html 2020-07-10 10:08:14 UTC (rev 8524)
@@ -813,7 +813,7 @@
<h3><a class="toc-backref" href="#toc-entry-49">2.14.5 Topics, Sidebars, and Rubrics</a></h3>
<p><em>Sidebars</em> are like miniature, parallel documents.</p>
<div class="sidebar">
-<p class="first sidebar-title">Sidebar Title</p>
+<p class="first sidebar-title">Optional Sidebar Title</p>
<p class="sidebar-subtitle">Optional Subtitle</p>
<p>This is a sidebar. It is for text outside the flow of the main
text.</p>
Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html 2020-07-10 10:08:14 UTC (rev 8524)
@@ -813,7 +813,7 @@
<h3><a class="toc-backref" href="#toc-entry-59"><span class="sectnum">2.14.5</span> Topics, Sidebars, and Rubrics</a></h3>
<p><em>Sidebars</em> are like miniature, parallel documents.</p>
<aside class="sidebar">
-<p class="sidebar-title">Sidebar Title</p>
+<p class="sidebar-title">Optional Sidebar Title</p>
<p class="sidebar-subtitle">Optional Subtitle</p>
<p>This is a sidebar. It is for text outside the flow of the main
text.</p>
Modified: trunk/docutils/test/functional/expected/standalone_rst_latex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_latex.tex 2020-07-10 10:08:14 UTC (rev 8524)
@@ -1202,7 +1202,7 @@
\emph{Sidebars} are like miniature, parallel documents.
\DUsidebar{
-\DUtitle[sidebar]{Sidebar Title}
+\DUtitle[sidebar]{Optional Sidebar Title}
\DUsubtitle{Optional Subtitle}
Modified: trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_pseudoxml.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -1603,7 +1603,7 @@
are like miniature, parallel documents.
<sidebar>
<title>
- Sidebar Title
+ Optional Sidebar Title
<subtitle>
Optional Subtitle
<paragraph>
Modified: trunk/docutils/test/functional/expected/standalone_rst_xetex.tex
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/expected/standalone_rst_xetex.tex 2020-07-10 10:08:14 UTC (rev 8524)
@@ -1204,7 +1204,7 @@
\emph{Sidebars} are like miniature, parallel documents.
\DUsidebar{
-\DUtitle[sidebar]{Sidebar Title}
+\DUtitle[sidebar]{Optional Sidebar Title}
\DUsubtitle{Optional Subtitle}
Modified: trunk/docutils/test/functional/input/data/standard.txt
===================================================================
--- trunk/docutils/test/functional/input/data/standard.txt 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/functional/input/data/standard.txt 2020-07-10 10:08:14 UTC (rev 8524)
@@ -693,7 +693,7 @@
*Sidebars* are like miniature, parallel documents.
-.. sidebar:: Sidebar Title
+.. sidebar:: Optional Sidebar Title
:subtitle: Optional Subtitle
This is a sidebar. It is for text outside the flow of the main
Modified: trunk/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py
===================================================================
--- trunk/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py 2020-07-10 09:26:22 UTC (rev 8523)
+++ trunk/docutils/test/test_parsers/test_rst/test_directives/test_sidebars.py 2020-07-10 10:08:14 UTC (rev 8524)
@@ -61,6 +61,17 @@
Body.
"""],
["""\
+.. sidebar::
+
+ The title is optional.
+""",
+"""\
+<document source="test data">
+ <sidebar>
+ <paragraph>
+ The title is optional.
+"""],
+["""\
.. sidebar:: Outer
.. topic:: Topic
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|