SF.net SVN: docutils:[10013 ] trunk/docutils
milde--- via Docutils-checkins <[email protected]> Fri, 21 Feb 2025 23:16:31 +0000
| Newsgroups | gmane.text.docutils.cvs |
|---|---|
| Message-ID | <[email protected]> |
Revision: 10013
http://sourceforge.net/p/docutils/code/10013
Author: milde
Date: 2025-02-21 23:16:30 +0000 (Fri, 21 Feb 2025)
Log Message:
-----------
Docinfo fixes.
Improve warning messages for problematic docinfo field content.
Use `isinstance()` instead of "name" argument to identify node type
in `LaTeXTranslator.visit_docinfo_item()`.
Keep inline markup in docinfo fields with "use_latex_docinfo".
Modified Paths:
--------------
trunk/docutils/RELEASE-NOTES.rst
trunk/docutils/docutils/transforms/frontmatter.py
trunk/docutils/docutils/writers/latex2e/__init__.py
trunk/docutils/test/functional/expected/latex_docinfo.tex
trunk/docutils/test/functional/expected/latex_memoir.tex
trunk/docutils/test/test_transforms/test_docinfo.py
Modified: trunk/docutils/RELEASE-NOTES.rst
===================================================================
--- trunk/docutils/RELEASE-NOTES.rst 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/RELEASE-NOTES.rst 2025-02-21 23:16:30 UTC (rev 10013)
@@ -163,6 +163,9 @@
* Remove the "rawsource" argument from `nodes.Text.__init__()`
in Docutils 2.0.
+* Remove the "name" argument from
+ `writers.latex2e.LaTeXTranslator.visit_docinfo_item()` in Docutils 0.24
+
* Remove attributes `nodes.Element.known_attributes`,
`nodes.Element.basic_attributes`, and `nodes.Element.local_attributes`,
in Docutils 2.0.
Modified: trunk/docutils/docutils/transforms/frontmatter.py
===================================================================
--- trunk/docutils/docutils/transforms/frontmatter.py 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/docutils/transforms/frontmatter.py 2025-02-21 23:16:30 UTC (rev 10013)
@@ -453,7 +453,8 @@
f_body.children = _document.children
return True
# Check failed, add a warning
- content = [f'<{e.tagname}>' for e in f_body.children]
+ content = [f'<{e.tagname}>' for e in f_body.children
+ if not isinstance(e, nodes.system_message)]
if len(content) > 1:
content = '[' + ', '.join(content) + ']'
else:
@@ -491,7 +492,8 @@
field[-1] += self.document.reporter.warning(
f'Cannot extract "{name}" from bibliographic field:\n'
f'Bibliographic field "{name}" must contain either\n'
- ' a single paragraph (with author names separated by one of '
+ ' a single paragraph (with author names separated by a'
+ ' character from the set '
f'"{"".join(self.language.author_separators)}"),\n'
' multiple paragraphs (one per author),\n'
' or a bullet list with one author name per item.\n'
Modified: trunk/docutils/docutils/writers/latex2e/__init__.py
===================================================================
--- trunk/docutils/docutils/writers/latex2e/__init__.py 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/docutils/writers/latex2e/__init__.py 2025-02-21 23:16:30 UTC (rev 10013)
@@ -1690,7 +1690,7 @@
self.depart_inline(node)
def visit_address(self, node) -> None:
- self.visit_docinfo_item(node, 'address')
+ self.visit_docinfo_item(node)
def depart_address(self, node) -> None:
self.depart_docinfo_item(node)
@@ -1721,7 +1721,7 @@
def visit_author(self, node) -> None:
self.pdfauthor.append(self.attval(node.astext()))
- self.visit_docinfo_item(node, 'author')
+ self.visit_docinfo_item(node)
def depart_author(self, node) -> None:
self.depart_docinfo_item(node)
@@ -1873,7 +1873,7 @@
self.duclass_close(node)
def visit_contact(self, node) -> None:
- self.visit_docinfo_item(node, 'contact')
+ self.visit_docinfo_item(node)
def depart_contact(self, node) -> None:
self.depart_docinfo_item(node)
@@ -1885,13 +1885,13 @@
self.duclass_close(node)
def visit_copyright(self, node) -> None:
- self.visit_docinfo_item(node, 'copyright')
+ self.visit_docinfo_item(node)
def depart_copyright(self, node) -> None:
self.depart_docinfo_item(node)
def visit_date(self, node) -> None:
- self.visit_docinfo_item(node, 'date')
+ self.visit_docinfo_item(node)
def depart_date(self, node) -> None:
self.depart_docinfo_item(node)
@@ -1949,38 +1949,45 @@
self.docinfo.append('\\end{tabularx}\n'
'\\end{center}\n')
- def visit_docinfo_item(self, node, name):
- if self.use_latex_docinfo:
- if name in ('author', 'organization', 'contact', 'address'):
- # We attach these to the last author. If any of them precedes
+ def visit_docinfo_item(self, node, name=None) -> None:
+ # auxiliary method, called by the visitors of "bibliographic elements"
+ if name is not None:
+ warnings.warn('visit_docinfo_item(): argument "name" is obsolete'
+ ' and will be removed in Docutils 0.24',
+ DeprecationWarning, stacklevel=2)
+ if isinstance(node, nodes.address):
+ self.insert_newline = True # preserve newlines
+ if self.use_latex_docinfo and isinstance(
+ node, (nodes.address, nodes.author, nodes.contact,
+ nodes.date, nodes.organization)):
+ self.push_output_collector([]) # see depart_docinfo_item()
+ else:
+ self.out.append('\\textbf{%s}: &\n\t'
+ % self.language_label(node.tagname))
+ if isinstance(node, nodes.address):
+ self.out.append('{\\raggedright\n')
+
+ def depart_docinfo_item(self, node) -> None:
+ self.insert_newline = False # reset change with <address> node
+ if self.use_latex_docinfo and isinstance(
+ node, (nodes.address, nodes.author, nodes.contact,
+ nodes.date, nodes.organization)):
+ text = ''.join(self.out)
+ self.pop_output_collector()
+ if isinstance(node, nodes.date):
+ self.date.append(text)
+ else:
+ # Attach to the last author. If any of them precedes
# the first author, put them in a separate "author" group
# (in lack of better semantics).
- if name == 'author' or not self.author_stack:
+ if isinstance(node, nodes.author) or not self.author_stack:
self.author_stack.append([])
- if name == 'address': # newlines are meaningful
- self.insert_newline = True
- text = self.encode(node.astext())
- self.insert_newline = False
- else:
- text = self.attval(node.astext())
self.author_stack[-1].append(text)
- raise nodes.SkipNode
- elif name == 'date':
- self.date.append(self.attval(node.astext()))
- raise nodes.SkipNode
- self.out.append('\\textbf{%s}: &\n\t' % self.language_label(name))
- if name == 'address':
- self.insert_newline = True
- self.out.append('{\\raggedright\n')
- self.context.append(' } \\\\\n')
else:
- self.context.append(' \\\\\n')
+ if isinstance(node, nodes.address):
+ self.out.append(' }')
+ self.out.append(' \\\\\n')
- def depart_docinfo_item(self, node) -> None:
- self.out.append(self.context.pop())
- # for address we did set insert_newline
- self.insert_newline = False
-
def visit_doctest_block(self, node) -> None:
self.visit_literal_block(node)
@@ -2751,7 +2758,7 @@
pass
def visit_organization(self, node) -> None:
- self.visit_docinfo_item(node, 'organization')
+ self.visit_docinfo_item(node)
def depart_organization(self, node) -> None:
self.depart_docinfo_item(node)
@@ -2864,7 +2871,7 @@
self.out.append('\n')
def visit_revision(self, node) -> None:
- self.visit_docinfo_item(node, 'revision')
+ self.visit_docinfo_item(node)
def depart_revision(self, node) -> None:
self.depart_docinfo_item(node)
@@ -2944,7 +2951,7 @@
self.out.append(self.context.pop() + '\n')
def visit_status(self, node) -> None:
- self.visit_docinfo_item(node, 'status')
+ self.visit_docinfo_item(node)
def depart_status(self, node) -> None:
self.depart_docinfo_item(node)
@@ -3343,7 +3350,7 @@
pass
def visit_version(self, node) -> None:
- self.visit_docinfo_item(node, 'version')
+ self.visit_docinfo_item(node)
def depart_version(self, node) -> None:
self.depart_docinfo_item(node)
Modified: trunk/docutils/test/functional/expected/latex_docinfo.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_docinfo.tex 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/test/functional/expected/latex_docinfo.tex 2025-02-21 23:16:30 UTC (rev 10013)
@@ -29,7 +29,7 @@
\title{}
\author{Foo Fred\\
Food Foomatics \& Friends\\
[email protected]\\
+\href{mailto:[email protected]}{[email protected]}\\
Fox St 13\\
Foowood \and
Bar Barney\\
Modified: trunk/docutils/test/functional/expected/latex_memoir.tex
===================================================================
--- trunk/docutils/test/functional/expected/latex_memoir.tex 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/test/functional/expected/latex_memoir.tex 2025-02-21 23:16:30 UTC (rev 10013)
@@ -205,12 +205,12 @@
123 Example Street\\
Example, EX Canada\\
A1B 2C3\\
[email protected] \and
+\href{mailto:[email protected]}{[email protected]} \and
Me \and
Myself \and
I\\
humankind}
-\date{Now, or yesterday. Or maybe even before yesterday.}
+\date{Now, or yesterday. Or maybe even \emph{before} yesterday.}
%%% Body
\begin{document}
Modified: trunk/docutils/test/test_transforms/test_docinfo.py
===================================================================
--- trunk/docutils/test/test_transforms/test_docinfo.py 2025-02-21 23:16:17 UTC (rev 10012)
+++ trunk/docutils/test/test_transforms/test_docinfo.py 2025-02-21 23:16:30 UTC (rev 10013)
@@ -360,7 +360,7 @@
<paragraph>
Cannot extract "Authors" from bibliographic field:
Bibliographic field "Authors" must contain either
- a single paragraph (with author names separated by one of ";,"),
+ a single paragraph (with author names separated by a character from the set ";,"),
multiple paragraphs (one per author),
or a bullet list with one author name per item.
Note: Leading initials can cause (mis)recognizing names as enumerated list.
@@ -375,7 +375,7 @@
<paragraph>
Cannot extract "Authors" from bibliographic field:
Bibliographic field "Authors" must contain either
- a single paragraph (with author names separated by one of ";,"),
+ a single paragraph (with author names separated by a character from the set ";,"),
multiple paragraphs (one per author),
or a bullet list with one author name per item.
Note: Leading initials can cause (mis)recognizing names as enumerated list.
@@ -393,7 +393,7 @@
<paragraph>
Cannot extract "Authors" from bibliographic field:
Bibliographic field "Authors" must contain either
- a single paragraph (with author names separated by one of ";,"),
+ a single paragraph (with author names separated by a character from the set ";,"),
multiple paragraphs (one per author),
or a bullet list with one author name per item.
Note: Leading initials can cause (mis)recognizing names as enumerated list.
@@ -411,7 +411,7 @@
<paragraph>
Cannot extract "Authors" from bibliographic field:
Bibliographic field "Authors" must contain either
- a single paragraph (with author names separated by one of ";,"),
+ a single paragraph (with author names separated by a character from the set ";,"),
multiple paragraphs (one per author),
or a bullet list with one author name per item.
Note: Leading initials can cause (mis)recognizing names as enumerated list.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins