Skip to content

Commit

Permalink
Merge pull request #557 from carpentries/fix-556
Browse files Browse the repository at this point in the history
prevent duplication of callout heading text with markup
  • Loading branch information
zkamvar authored Dec 14, 2023
2 parents 50bfd5a + 83e289b commit 9ef1e34
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: sandpaper
Title: Create and Curate Carpentries Lessons
Version: 0.16.0
Version: 0.16.1
Authors@R: c(
person(given = "Zhian N.",
family = "Kamvar",
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# sandpaper 0.16.1 (2023-12-14)

## BUG FIX

* Callout headings with markup in the titles will no longer have text duplicated
(reported: @zkamvar, #556; fixed: @zkamvar, #557)

# sandpaper 0.16.0 (2023-12-13)

## NEW FEATURES
Expand Down
4 changes: 3 additions & 1 deletion R/utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ fix_callouts <- function(nodes = NULL) {
callouts <- xml2::xml_find_all(nodes, ".//div[starts-with(@class, 'callout ')]")
h3 <- xml2::xml_find_all(callouts, "./div/h3")
translations <- get_callout_translations()
xml_text_translate(h3, translations)
# https://github.com/carpentries/sandpaper/issues/556
h3_text <- xml2::xml_find_all(h3, ".//text()")
xml_text_translate(h3_text, translations)
xml2::xml_set_attr(h3, "class", "callout-title")
inner_div <- xml2::xml_parent(h3)
# remove the "section level3 callout-title" attrs
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/examples/callout-ids.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ <h2>Markdown</h2>
<i class="callout-icon" data-feather="message-circle"></i>
</div>
<div class="section level3 callout-title callout-inner">
<h3 class="callout-title">Challenge</h3>
<h3 class="callout-title">Challenge (<code>this is code</code>)</h3>
<div class="callout-content">
<p>How do you write markdown divs?</p>
</div>
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-utils-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("fix figures account for inline images and do not clobber them into fi



test_that("callout ids are processed correctly", {
test_that("(#556) (#454) callout are processed correctly", {
html_test <- xml2::read_html(test_path("examples/callout-ids.html"))
fix_callouts(html_test)
anchors <- xml2::xml_find_all(html_test, ".//a")
Expand All @@ -70,6 +70,11 @@ test_that("callout ids are processed correctly", {
expect_equal(ids, c("discussion1", "wait-what"))
# The IDs should match the anchors
expect_equal(paste0("#", ids), xml2::xml_attr(anchors, "href"))
# The headings should match what we expect
# (https://github.com/carpentries/sandpaper/issues/556)
htext <- xml2::xml_find_all(headings, ".//text()")
expect_equal(xml2::xml_text(htext),
c("Challenge (", "this is code", ")", "Wait what?"))
})


Expand Down

0 comments on commit 9ef1e34

Please sign in to comment.