Skip to content

Commit

Permalink
Escape special characters in bibtex
Browse files Browse the repository at this point in the history
Fixes #2022
  • Loading branch information
hadley committed May 13, 2024
1 parent a9e7304 commit 46cc1dd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* `build_home()` now correctly escapes special HTML characters in the bibtex citation (#2022).
* `build_articles()` now reports if you are missing alt-text for any images (#2357).
* `check_pkgdown()` and `pkgdown_sitrep()` have been unified so that they both report on the same problems. They now only differ in the style of their output: `pkgdown_sitrep()` reports whether each category is ok or not ok, while `check_pkgdown()` errors on the first issue (#2463).
* `build_site()` automatically runs `pkgdown_sitrep()` at the start of the process (#2380).
Expand Down
2 changes: 1 addition & 1 deletion inst/BS3/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h1 id="citation">{{#translate}}{{citation}}{{/translate}}</h1>

{{#citations}}
{{{html}}}
<pre>{{{bibtex}}}</pre>
<pre>{{bibtex}}</pre>
{{/citations}}

</div>
Expand Down
2 changes: 1 addition & 1 deletion inst/BS5/templates/content-citation-authors.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ <h2 id="citation">{{#translate}}{{citation}}{{/translate}}</h2>

{{#citations}}
{{{html}}}
<pre>{{{bibtex}}}</pre>
<pre>{{bibtex}}</pre>
{{/citations}}
</div>

Expand Down
24 changes: 24 additions & 0 deletions tests/testthat/test-build-home-authors.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,27 @@ test_that("multiple citations all have HTML and BibTeX formats", {
citations <- data_citations(path)
expect_snapshot_output(citations)
})

test_that("bibtex is escaped", {
pkg <- local_pkgdown_site(meta = "
template:
bslib:
version: 5
")
dir_create(path(pkg$src_path, "inst"))
write_lines(path = path(pkg$src_path, "inst", "CITATION"), c(
'citEntry(',
' entry = "Article",',
' title="test special HTML characters: <&>",',
' author="x",',
' journal="x",',
' year="2017"',
')'
))

suppressMessages(init_site(pkg))
suppressMessages(build_citation_authors(pkg))
html <- xml2::read_html(path(pkg$dst_path, "authors.html"))

expect_match(xpath_text(html, "//pre"), "<&>", fixed = TRUE)
})

0 comments on commit 46cc1dd

Please sign in to comment.