Skip to content

Commit

Permalink
Use container node for citation nodes to respect docutils spec. (#274)
Browse files Browse the repository at this point in the history
Closes #273.
  • Loading branch information
mcmtroffaes committed Oct 5, 2021
1 parent 34cef6e commit 7b0e2ac
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
2.4.2 (in development)
----------------------

* Use container node instead of paragraph node for containing bibliographies,
fixing a violation against the docutils spec
(see issue #273, reported by rappdw, with additional input from brechtm).

2.4.1 (10 September 2021)
-------------------------

Expand Down
4 changes: 2 additions & 2 deletions src/sphinxcontrib/bibtex/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class BibtexDomain(Domain):
encoding='',
bibfiles={},
data=pybtex.database.BibliographyData()),
bibliography_header=docutils.nodes.paragraph(),
bibliography_header=docutils.nodes.container(),
bibliographies={},
citations=[],
citation_refs=[],
Expand Down Expand Up @@ -350,7 +350,7 @@ def __init__(self, env: "BuildEnvironment"):
# parse bibliography header
header = getattr(env.app.config, "bibtex_bibliography_header")
if header:
self.data["bibliography_header"] = \
self.data["bibliography_header"] += \
parse_header(header, "bibliography_header")

def clear_doc(self, docname: str) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/sphinxcontrib/bibtex/foot_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BibtexFootDomain(Domain):
label = 'BibTeX Footnote Citations'
data_version = 0
initial_data = dict(
bibliography_header=docutils.nodes.paragraph(),
bibliography_header=docutils.nodes.container(),
)
reference_style: BaseReferenceStyle

Expand All @@ -60,7 +60,7 @@ def __init__(self, env: "BuildEnvironment"):
# parse bibliography header
header = getattr(env.app.config, "bibtex_footbibliography_header")
if header:
self.data["bibliography_header"] = \
self.data["bibliography_header"] += \
parse_header(header, "foot_bibliography_header")

def merge_domaindata(self, docnames: List[str], otherdata: Dict) -> None:
Expand Down
8 changes: 4 additions & 4 deletions test/test_bibliography.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ def test_bibliography_custom_ids(app, warning) -> None:
app.build()
assert not warning.getvalue()
output = (app.outdir / "index.html").read_text(encoding='utf-8')
assert '<p id="bibliography-id-1">' in output
assert '<p id="bibliography-id-2">' in output
assert '<p id="footbibliography-id-1">' in output
assert '<p id="footbibliography-id-2">' in output
assert ' id="bibliography-id-1"' in output
assert ' id="bibliography-id-2"' in output
assert ' id="footbibliography-id-1"' in output
assert ' id="footbibliography-id-2"' in output
match1 = html_citations(text='.*Evensen.*').search(output)
match2 = html_citations(text='.*Mandel.*').search(output)
match3 = html_citations(text='.*Lorenc.*').search(output)
Expand Down
4 changes: 2 additions & 2 deletions test/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<reference internal="True" refid="id3" reftitle="The title.">
tes
]
<paragraph ids="id2">
<container ids="id2">
<citation backrefs="id1" docname="index" ids="id3">
<label support_smartquotes="False">
tes
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_debug_minimal_example(app, warning) -> None:
' Nel87',
' ]',
' .',
' <paragraph ids="id3">',
' <container ids="id3">',
' <citation backrefs="id1 id2" docname="index" ids="id4">',
' <label support_smartquotes="False">',
' Nel87',
Expand Down

0 comments on commit 7b0e2ac

Please sign in to comment.