|
From: <mi...@us...> - 2017-11-04 21:14:40
|
Revision: 8198
http://sourceforge.net/p/docutils/code/8198
Author: milde
Date: 2017-11-04 21:14:37 +0000 (Sat, 04 Nov 2017)
Log Message:
-----------
Ignore backslash-escaped separators when extracting authors from a paragraph.
Modified Paths:
--------------
trunk/docutils/HISTORY.txt
trunk/docutils/RELEASE-NOTES.txt
trunk/docutils/docutils/transforms/frontmatter.py
trunk/docutils/test/test_transforms/test_docinfo.py
Modified: trunk/docutils/HISTORY.txt
===================================================================
--- trunk/docutils/HISTORY.txt 2017-11-04 10:31:01 UTC (rev 8197)
+++ trunk/docutils/HISTORY.txt 2017-11-04 21:14:37 UTC (rev 8198)
@@ -47,6 +47,8 @@
* docutils/transforms/frontmatter.py:
- Add field name as class argument to generic docinfo fields unconditionally.
+ - Ignore backslash-escaped separators when extracting authors from a
+ paragraph.
* docutils/transforms/references.py:
Modified: trunk/docutils/RELEASE-NOTES.txt
===================================================================
--- trunk/docutils/RELEASE-NOTES.txt 2017-11-04 10:31:01 UTC (rev 8197)
+++ trunk/docutils/RELEASE-NOTES.txt 2017-11-04 21:14:37 UTC (rev 8198)
@@ -58,7 +58,11 @@
- Fixed a bug with the "trim" options of the "unicode" directive.
+ - Allow escaping of author-separators in `bibliographic fields`__.
+
+ __ docs/ref/rst/restructuredtext.html#bibliographic-fields
+
Release 0.14 (2017-08-03)
=========================
Modified: trunk/docutils/docutils/transforms/frontmatter.py
===================================================================
--- trunk/docutils/docutils/transforms/frontmatter.py 2017-11-04 10:31:01 UTC (rev 8197)
+++ trunk/docutils/docutils/transforms/frontmatter.py 2017-11-04 21:14:37 UTC (rev 8198)
@@ -424,6 +424,7 @@
base_node=field)
raise TransformError
title = nodes.title(name, labels[canonical])
+ title[0].rawsource = labels[canonical]
topics[canonical] = biblioclass(
'', title, classes=[canonical], *field[1].children)
else:
@@ -503,20 +504,30 @@
raise
def authors_from_one_paragraph(self, field):
- text = field[1][0].astext().strip()
+ """Return list of Text nodes for ";"- or ","-separated authornames."""
+ # @@ keep original formatting? (e.g. ``:authors: A. Test, *et-al*``)
+ rawnames = (node.rawsource or node.astext
+ for node in field[1].traverse(nodes.Text))
+ text = ''.join(rawnames)
if not text:
raise TransformError
for authorsep in self.language.author_separators:
- authornames = text.split(authorsep)
+ # don't split at escaped `authorsep`:
+ pattern = r'(?<=\\\\)%s|(?<!\\)%s' % (authorsep, authorsep)
+ authornames = re.split(pattern, text)
if len(authornames) > 1:
break
- authornames = [author.strip() for author in authornames]
- authors = [[nodes.Text(author)] for author in authornames if author]
+ authornames = ((utils.unescape_rawsource(rawname).strip(),
+ rawname.strip()) for rawname in authornames)
+ authors = [[nodes.Text(author, rawname)]
+ for (author, rawname) in authornames if author]
return authors
def authors_from_bullet_list(self, field):
authors = []
for item in field[1][0]:
+ if isinstance(item, nodes.comment):
+ continue
if len(item) != 1 or not isinstance(item[0], nodes.paragraph):
raise TransformError
authors.append(item[0].children)
@@ -526,7 +537,8 @@
def authors_from_paragraphs(self, field):
for item in field[1]:
- if not isinstance(item, nodes.paragraph):
+ if not isinstance(item, (nodes.paragraph, nodes.comment)):
raise TransformError
- authors = [item.children for item in field[1]]
+ authors = [item.children for item in field[1]
+ if not isinstance(item, nodes.comment)]
return authors
Modified: trunk/docutils/test/test_transforms/test_docinfo.py
===================================================================
--- trunk/docutils/test/test_transforms/test_docinfo.py 2017-11-04 10:31:01 UTC (rev 8197)
+++ trunk/docutils/test/test_transforms/test_docinfo.py 2017-11-04 21:14:37 UTC (rev 8198)
@@ -230,6 +230,49 @@
<author>
One, Only
"""],
+[r""":Authors: Me\, Myself; **I**
+:Authors: Pac\;Man\\; Ms. Pac\Man; Pac\ Man, Jr.
+:Authors:
+ Here
+
+ The\re
+
+ *Every\ where*
+:Authors: - First\\
+ - Se\ cond
+ - Thir\d
+""",
+"""\
+<document source="test data">
+ <docinfo>
+ <authors>
+ <author>
+ Me, Myself
+ <author>
+ I
+ <authors>
+ <author>
+ Pac;Man\\
+ <author>
+ Ms. PacMan
+ <author>
+ PacMan, Jr.
+ <authors>
+ <author>
+ Here
+ <author>
+ There
+ <author>
+ <emphasis>
+ Everywhere
+ <authors>
+ <author>
+ First\\
+ <author>
+ Second
+ <author>
+ Third
+"""],
["""\
:Authors:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|