| 1 |
test_that("Markdown without newlines translates", { |
| 2 |
expect_equal(markdown("# a top level"), HTML("<h1>a top level</h1>\n")) |
| 3 |
expect_equal(markdown("## a subheading"), HTML("<h2>a subheading</h2>\n")) |
| 4 |
expect_equal(markdown("[rstudio](https://rstudio.com)"), HTML("<p><a href=\"https://rstudio.com\">rstudio</a></p>\n")) |
| 5 |
}) |
| 6 |
|
| 7 |
test_that("HTML has correct attributes", { |
| 8 |
html <- markdown("a paragraph", .noWS = "outside") |
| 9 |
expect_s3_class(html, "html") |
| 10 |
expect_equal(attr(html, "noWS"), "outside") |
| 11 |
}) |
| 12 |
|
| 13 |
test_that("Github extensions are on by default", { |
| 14 |
html <- markdown("a ~~paragraph~~ with a link: https://example.com") |
| 15 |
expect_equal(html, HTML("<p>a <del>paragraph</del> with a link: <a href=\"https://example.com\">https://example.com</a></p>\n")) |
| 16 |
}) |
| 17 |
|
| 18 |
test_that("Github extensions can be disabled", { |
| 19 |
html <- markdown("a ~~paragraph~~", extensions = FALSE) |
| 20 |
expect_equal(html, HTML("<p>a ~~paragraph~~</p>\n")) |
| 21 |
}) |
| 22 |
|
| 23 |
test_that("Additional options are respected", { |
| 24 |
html <- markdown("a ~~paragraph~~", extensions = FALSE, sourcepos = TRUE) |
| 25 |
expect_equal(html, HTML("<p data-sourcepos=\"1:1-1:15\">a ~~paragraph~~</p>\n")) |
| 26 |
}) |
| 27 |
|
| 28 |
test_that("Multiline markdown works properly", { |
| 29 |
essay <- paste0(" |
| 30 |
# The [Louisiana Purchase](https://en.wikipedia.org/wiki/Louisiana_Purchase)\n", |
| 31 |
" ", " |
| 32 |
Larry Sellers |
| 33 |
Mrs. Jamtoss |
| 34 |
History Period 4 |
| 35 |
|
| 36 |
## Introduction |
| 37 |
|
| 38 |
The most important purchase in history is the Lousiana |
| 39 |
Purchase. It was also the most important evente. It |
| 40 |
happened in President Jeffersons 1st administration. |
| 41 |
Its when the United States bought 827,987 square miles |
| 42 |
of lande from the French guys. |
| 43 |
|
| 44 |
The end.") |
| 45 |
|
| 46 |
expect_equal(strsplit(essay, "\n")[[1]][[3]], " ") |
| 47 |
|
| 48 |
expected <- HTML(paste0(c( |
| 49 |
"<h1>The <a href=\"https://en.wikipedia.org/wiki/Louisiana_Purchase\">Louisiana Purchase</a></h1>", |
| 50 |
"<p>Larry Sellers", |
| 51 |
"Mrs. Jamtoss", |
| 52 |
"History Period 4</p>", |
| 53 |
"<h2>Introduction</h2>", |
| 54 |
"<p>The most important purchase in history is the Lousiana", |
| 55 |
"Purchase. It was also the most important evente. It", |
| 56 |
"happened in President Jeffersons 1st administration.", |
| 57 |
"Its when the United States bought 827,987 square miles", |
| 58 |
"of lande from the French guys.</p>", |
| 59 |
"<p>The end.</p>", |
| 60 |
"" |
| 61 |
), collapse = "\n")) |
| 62 |
expect_equal(markdown(essay), expected) |
| 63 |
}) |