test_that("highlights
wrapped inwith language info", { skip_if_no_pandoc("2.16") withr::local_options(downlit.topic_index = c(foo = "foo")) html <- xml2::read_html('') tweak_reference_highlighting(html) expect_equal(xpath_attr(html, ".//code//a", "href"), "foo.html") # Or upper case R html <- xml2::read_html('foo(x)
') tweak_reference_highlighting(html) expect_equal(xpath_attr(html, ".//code//a", "href"), "foo.html") html <- xml2::read_html('foo(x)
') tweak_reference_highlighting(html) # Select all leaf to work around variations in pandoc styling expect_equal(xpath_attr(html, "//code//span[not(span)]", "class")[[1]], "fu") expect_equal(xpath_text(html, "//code//span[not(span)]")[[1]], "field") # But don't touch examples or usage html <- xml2::read_html('field: value
foo(x)
') tweak_reference_highlighting(html) expect_equal(xpath_length(html, "//code//span"), 0) html <- xml2::read_html('foo(x)
') tweak_reference_highlighting(html) expect_equal(xpath_length(html, "//code//span"), 0) }) test_that("highlight unwrapped", { withr::local_options(downlit.topic_index = c(foo = "foo")) # If parseable, assume R html <- xml2::read_html('') tweak_reference_highlighting(html) expect_equal(xpath_attr(html, ".//code//a", "href"), "foo.html") expect_equal(xpath_attr(html, ".//div/div", "class"), "sourceCode") # If not parseable, leave as is html <- xml2::read_html('foo(x)
') tweak_reference_highlighting(html) expect_equal(xpath_length(html, "//code//span"), 0) expect_equal(xpath_attr(html, ".//div/div", "class"), "sourceCode") }) # highlighting ------------------------------------------------------------ test_that("can highlight R code", { html <- xml2::read_xml('foo(
') tweak_highlight_r(html) expect_equal(xpath_attr(html, "//code//span[@class]", "class"), c("fl", "op", "fl")) expect_equal(xpath_text(html, "//code//span[@class]"), c("1", "+", "2")) }) test_that("fails cleanly", { html <- xml2::read_xml('1 + 2
') expect_equal(tweak_highlight_r(html), FALSE) html <- xml2::read_xml('1 +
') expect_equal(tweak_highlight_r(html), FALSE) html <- xml2::read_xml('') expect_equal(tweak_highlight_r(html), FALSE) }) test_that("can highlight other languages", { skip_if_no_pandoc("2.16") html <- xml2::read_xml('') tweak_highlight_other(html) # Select all leaf to work around variations in pandoc styling expect_equal(xpath_attr(html, "//code//span[not(span)]", "class")[[1]], "fu") expect_equal(xpath_text(html, "//code//span[not(span)]")[[1]], "field") }) test_that("can highlight 'rmd'", { skip_if_no_pandoc("2.16") html <- xml2::read_xml('field: value
') tweak_highlight_other(html) expect_equal(xpath_attr(html, "//code//span[not(span)]", "class")[[1]], "an") }) test_that("fails cleanly", { html <- xml2::read_xml('field: value
') tweak_highlight_other(html) expect_equal(xpath_text(html, "//code"), "") html <- xml2::read_xml('') expect_equal(tweak_highlight_other(html), FALSE) }) # logo -------------------------------------------------------------------- test_that("can strip extra logo from description", { html <- xml2::read_html('') tweak_extra_logo(html) expect_equal(xpath_length(html, "//img"), 0) })Hi
Bye