summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstrank <strank@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-04-09 17:25:19 +0000
committerstrank <strank@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-04-09 17:25:19 +0000
commit80edfa385316eb5eff7a29967f59f17c91947d47 (patch)
tree678e6352bee96ee80fb1d0d76450f5ef32c0da8d
parent1d592cc1777b79d66e7de1caed0bbe3c6790c27f (diff)
downloaddocutils-80edfa385316eb5eff7a29967f59f17c91947d47.tar.gz
allow adjacent citation labels (don't for footnotes) plus tests
git-svn-id: http://svn.code.sf.net/p/docutils/code/branches/adjacent-citations@5044 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/parsers/rst/states.py28
-rw-r--r--docutils/writers/latex2e/__init__.py13
-rwxr-xr-xtest/test_parsers/test_rst/test_inline_markup.py23
-rwxr-xr-xtest/test_writers/test_latex2e.py34
4 files changed, 87 insertions, 11 deletions
diff --git a/docutils/parsers/rst/states.py b/docutils/parsers/rst/states.py
index 50f5dd082..9fa561915 100644
--- a/docutils/parsers/rst/states.py
+++ b/docutils/parsers/rst/states.py
@@ -514,6 +514,13 @@ class Inliner:
non_whitespace_after = r'(?![ \n])'
# Alphanumerics with isolated internal [-._] chars (i.e. not 2 together):
simplename = r'(?:(?!_)\w)+(?:[-._](?:(?!_)\w)+)*'
+ # Special case for adjacent citation references:
+ citref_concatenator = ']_['
+ citation_labels = (r'%s(?:%s%s)*'
+ % (simplename,
+ re.escape(citref_concatenator),
+ simplename)
+ )
# Valid URI characters (see RFC 2396 & RFC 2732);
# final \x00 allows backslash escapes in URIs:
uric = r"""[-_.!~*'()[\];/:@&=+$,%a-zA-Z0-9\x00]"""
@@ -546,7 +553,8 @@ class Inliner:
[r'[0-9]+', # manually numbered
r'\#(%s)?' % simplename, # auto-numbered (w/ label?)
r'\*', # auto-symbol
- r'(?P<citationlabel>%s)' % simplename] # citation reference
+ r'(?P<citationlabels>%s)' % citation_labels, # citation ref
+ ]
)
]
),
@@ -856,11 +864,16 @@ class Inliner:
string = match.string
before = string[:match.start('whole')]
remaining = string[match.end('whole'):]
- if match.group('citationlabel'):
- refnode = nodes.citation_reference('[%s]_' % label,
- refname=refname)
- refnode += nodes.Text(label)
- self.document.note_citation_ref(refnode)
+ refnodes = []
+ if match.group('citationlabels'):
+ labels = label.split(Inliner.citref_concatenator)
+ refnames = refname.split(Inliner.citref_concatenator)
+ for label, refname in zip(labels, refnames):
+ refnode = nodes.citation_reference('[%s]_' % label,
+ refname=refname)
+ refnode += nodes.Text(label)
+ self.document.note_citation_ref(refnode)
+ refnodes.append(refnode)
else:
refnode = nodes.footnote_reference('[%s]_' % label)
if refname[0] == '#':
@@ -879,7 +892,8 @@ class Inliner:
self.document.note_footnote_ref(refnode)
if utils.get_trim_footnote_ref_space(self.document.settings):
before = before.rstrip()
- return (before, [refnode], remaining, [])
+ refnodes.append(refnode)
+ return (before, refnodes, remaining, [])
def reference(self, match, lineno, anonymous=None):
referencename = match.group('refname')
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
index 7f7ef3570..985fdc176 100644
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -1065,8 +1065,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
def visit_citation_reference(self, node):
if self._use_latex_citations:
- self.body.append('\\cite{')
- self.inside_citation_reference_label = 1
+ if not self.inside_citation_reference_label:
+ self.body.append('\\cite{')
+ self.inside_citation_reference_label = 1
else:
href = ''
if node.has_key('refid'):
@@ -1077,8 +1078,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
def depart_citation_reference(self, node):
if self._use_latex_citations:
- self.body.append('}')
- self.inside_citation_reference_label = 0
+ next_sibling = node.next_node(descend=0, siblings=1)
+ if next_sibling.__class__ == node.__class__:
+ self.body.append(',')
+ else:
+ self.body.append('}')
+ self.inside_citation_reference_label = 0
else:
self.body.append('}]')
diff --git a/test/test_parsers/test_rst/test_inline_markup.py b/test/test_parsers/test_rst/test_inline_markup.py
index fe1c1aff2..b814a6560 100755
--- a/test/test_parsers/test_rst/test_inline_markup.py
+++ b/test/test_parsers/test_rst/test_inline_markup.py
@@ -637,6 +637,14 @@ totest['footnote_reference'] = [
<paragraph>
<footnote_reference auto="*" ids="id1">
"""],
+["""\
+No footnote refs: [*]_[#label]_ [#]_[2]_ [1]_[*]_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ No footnote refs: [*]_[#label]_ [#]_[2]_ [1]_[*]_
+"""],
]
totest['citation_reference'] = [
@@ -668,6 +676,21 @@ totest['citation_reference'] = [
CIT1
but not [CIT 1]_
"""],
+["""\
+Adjacent citations:
+[citation]_[cit-ation]_[CIT1]_
+""",
+"""\
+<document source="test data">
+ <paragraph>
+ Adjacent citations:
+ <citation_reference ids="id1" refname="citation">
+ citation
+ <citation_reference ids="id2" refname="cit-ation">
+ cit-ation
+ <citation_reference ids="id3" refname="cit1">
+ CIT1
+"""],
]
totest['substitution_references'] = [
diff --git a/test/test_writers/test_latex2e.py b/test/test_writers/test_latex2e.py
index 60492569d..6f229a8df 100755
--- a/test/test_writers/test_latex2e.py
+++ b/test/test_writers/test_latex2e.py
@@ -230,6 +230,40 @@ The underscore is mishandled.
]
+totest_latex_citations['adjacent_citations'] = [
+# input
+["""\
+Two citations: [MeYou2007]_[YouMe2007]_.
+
+.. [MeYou2007] not.
+.. [YouMe2007] important.
+""",
+## # expected output
+latex_head + """\
+\\title{}
+\\author{}
+\\date{}
+\\raggedbottom
+\\begin{document}
+
+\\setlength{\\locallinewidth}{\\linewidth}
+
+Two citations: \\cite{MeYou2007,YouMe2007}.
+
+\\begin{thebibliography}{MeYou2007}
+\\bibitem[MeYou2007]{MeYou2007}{
+not.
+}
+\\bibitem[YouMe2007]{YouMe2007}{
+important.
+}
+\\end{thebibliography}
+
+\\end{document}
+"""],
+]
+
+
totest['enumerated_lists'] = [
# input
["""\