Skip to content

Commit 03252f8

Browse files
sbfnksbfnk-bot
andcommitted
Fix BibTeX extraction from GitHub issue HTML
Extract from <pre> element inside <details> instead of the entire <details> element. GitHub renders markdown code fences as <pre><code> blocks, so targeting <pre> is more precise and avoids potential whitespace or formatting issues. Added fallback to <details> if <pre> not found, plus validation to catch empty BibTeX early. Co-Authored-By: sbfnk-bot <sbfnk-bot@users.noreply.github.com>
1 parent 80005fe commit 03252f8

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

snippets/update_publications.R

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,28 @@ if (is.null(last_comment_pubs)) {
3131

3232
last_comment_pubs <- xml2::read_html(last_comment_pubs)
3333

34-
last_comment_pubs |>
35-
xml2::xml_find_first("//details") |>
36-
xml2::xml_text() |>
37-
write("bibentries_previous_month.bib")
34+
# Extract BibTeX from the code block inside <details>
35+
# GitHub renders markdown code fences as <pre><code> elements
36+
bib_text <- last_comment_pubs |>
37+
xml2::xml_find_first("//details//pre") |>
38+
xml2::xml_text()
39+
40+
# If no <pre> found, try the <details> element directly (fallback)
41+
if (is.na(bib_text) || nchar(trimws(bib_text)) == 0) {
42+
bib_text <- last_comment_pubs |>
43+
xml2::xml_find_first("//details") |>
44+
xml2::xml_text()
45+
}
46+
47+
# Clean up any leading/trailing whitespace
48+
bib_text <- trimws(bib_text)
49+
50+
if (is.na(bib_text) || nchar(bib_text) == 0) {
51+
message("No BibTeX content found in issue")
52+
quit(save = "no")
53+
}
54+
55+
write(bib_text, "bibentries_previous_month.bib")
3856

3957
bibentries_previous_month <- bibtex::read.bib("bibentries_previous_month.bib")
4058

0 commit comments

Comments
 (0)