Skip to content

Commit

Permalink
fix backslashing in pybtex parsiong
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamd committed Jan 20, 2022
1 parent 3fb00db commit 1f198ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/mkdocs_bibtex/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def format_simple(entries):
entry_text = formatted_entry.text.render(backend)
entry_text = entry_text.replace("\n", " ")
# Local reference list for this file
citations[key] = entry_text
citations[key] = (
entry_text.replace("\\(", "(").replace("\\)", ")").replace("\\.", ".")
)
return citations


Expand Down
28 changes: 14 additions & 14 deletions test_files/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def test_format_citations(plugin):
"[@test]",
"test",
"1",
"First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\.",
"First Author and Second Author. Test title. *Testing Journal*, 2019.",
) == plugin.format_citations(["[@test]"])[0]

assert (
"[@test2]",
"test2",
"1",
"First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019\\.",
"First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019.",
) == plugin.format_citations(["[@test2]"])[0]

# Test compound citation
Expand All @@ -70,13 +70,13 @@ def test_format_citations(plugin):
"[@test; @test2]",
"test",
"1",
"First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\.",
"First Author and Second Author. Test title. *Testing Journal*, 2019.",
),
(
"[@test; @test2]",
"test2",
"1",
"First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019\\.",
"First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019.",
),
] == plugin.format_citations(["[@test; @test2]"])

Expand All @@ -85,7 +85,7 @@ def test_format_citations(plugin):
"[@Bivort2016]",
"Bivort2016",
"1",
"Benjamin L\\. De Bivort and Bruno Van Swinderen\\. Evidence for selective attention in the insect brain\\. *Current Opinion in Insect Science*, 15:1–7, 2016\\. [doi:10\\.1016/j\\.cois\\.2016\\.02\\.007](https://doi.org/10.1016/j.cois.2016.02.007)\\.", # noqa: E501
"Benjamin L. De Bivort and Bruno Van Swinderen. Evidence for selective attention in the insect brain. *Current Opinion in Insect Science*, 15:1–7, 2016. [doi:10.1016/j.cois.2016.02.007](https://doi.org/10.1016/j.cois.2016.02.007).", # noqa: E501
) == plugin.format_citations(["[@Bivort2016]"])[0]

# Test formatting using a CSL style
Expand All @@ -94,14 +94,14 @@ def test_format_citations(plugin):
"[@test]",
"test",
"1",
"First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\.",
"First Author and Second Author. Test title. *Testing Journal*, 2019.",
) == plugin.format_citations(["[@test]"])[0]

assert (
"[@Bivort2016]",
"Bivort2016",
"1",
"Benjamin L\\. De Bivort and Bruno Van Swinderen\\. Evidence for selective attention in the insect brain\\. *Current Opinion in Insect Science*, 15:1–7, 2016\\. [doi:10\\.1016/j\\.cois\\.2016\\.02\\.007](https://doi.org/10.1016/j.cois.2016.02.007)\\.", # noqa: E501
"Benjamin L. De Bivort and Bruno Van Swinderen. Evidence for selective attention in the insect brain. *Current Opinion in Insect Science*, 15:1–7, 2016. [doi:10.1016/j.cois.2016.02.007](https://doi.org/10.1016/j.cois.2016.02.007).", # noqa: E501
) == plugin.format_citations(["[@Bivort2016]"])[0]

# Test a CSL that outputs references in a different style
Expand All @@ -110,7 +110,7 @@ def test_format_citations(plugin):
"[@test]",
"test",
"1",
"First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\.",
"First Author and Second Author. Test title. *Testing Journal*, 2019.",
) == plugin.format_citations(["[@test]"])[0]


Expand Down Expand Up @@ -149,7 +149,7 @@ def test_insert_citation_keys():
"[@test; @test2]",
"@test2",
"2",
"First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019", # noqa: E501
"First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019", # noqa: E501
),
],
"[@test; @test2]",
Expand All @@ -170,15 +170,15 @@ def test_format_bibliography():
"[@test; @test2]",
"@test2",
"2",
"First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019",
"First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019",
),
]

bib = format_bibliography(quads)

assert "[^1]: First Author and Second Author" in bib
assert (
"[^2]: First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019"
"[^2]: First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019"
in bib
)

Expand All @@ -191,11 +191,11 @@ def test_format_simple(entries):

assert (
citations["test"]
== "First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\."
== "First Author and Second Author. Test title. *Testing Journal*, 2019."
)
assert (
citations["test2"]
== "First Author and Second Author\\. Test Title \\(TT\\)\\. *Testing Journal \\(TJ\\)*, 2019\\."
== "First Author and Second Author. Test Title (TT). *Testing Journal (TJ)*, 2019."
)


Expand All @@ -220,6 +220,6 @@ def test_on_page_markdown(plugin):
test_markdown = "This is a citation. [@test]\n\n \\bibliography"

assert (
"[^1]: First Author and Second Author\\. Test title\\. *Testing Journal*, 2019\\."
"[^1]: First Author and Second Author. Test title. *Testing Journal*, 2019."
in plugin.on_page_markdown(test_markdown, None, None, None)
)

0 comments on commit 1f198ea

Please sign in to comment.