From 91237d4fa488146ea8310c10c392a59c7fe9ca18 Mon Sep 17 00:00:00 2001 From: Yihui Xie Date: Sun, 13 Oct 2024 06:50:40 +1300 Subject: [PATCH] Require double-tilde for strikethrough (#33) --- DESCRIPTION | 2 +- NEWS | 3 ++- R/extensions.R | 2 +- man/extensions.Rd | 2 +- src/wrapper.c | 1 + tests/testthat/test-extensions.R | 18 +++++++++--------- 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c16582c..2dfe0be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Suggests: curl, testthat, xml2 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Language: en-US Encoding: UTF-8 diff --git a/NEWS b/NEWS index 59be9da..42c3e65 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ -1.9.3 +1.9.4 - Apply upstream PR https://github.com/github/cmark-gfm/pull/362 + - Require double-tilde `~~` for the strikethrough extension, for consistency with Pandoc's Markdown 1.9.1 - Update libcmark-gfm to 0.29.0.gfm.13 diff --git a/R/extensions.R b/R/extensions.R index 25fa328..64b4a2a 100644 --- a/R/extensions.R +++ b/R/extensions.R @@ -6,7 +6,7 @@ #' Currently the following extensions are supported: #' #' - **table** support rendering of tables: [gfm-spec section 4.10](https://github.github.com/gfm/#tables-extension-) -#' - **strikethrough** via `~sometext~` syntax: [gfm-spec section 6.5](https://github.github.com/gfm/#strikethrough-extension-) +#' - **strikethrough** via `~~sometext~~` syntax: [gfm-spec section 6.5](https://github.github.com/gfm/#strikethrough-extension-) #' - **autolink** automatically turn URLs into hyperlinks: [gfm-spec section 6.9](https://github.github.com/gfm/#autolinks-extension-) #' - **tagfilter** blacklist html tags: `title` `textarea` `style` `xmp` `iframe` #' `noembed` `noframes` `script` `plaintext`: [gfm-spec section 6.11](https://github.github.com/gfm/#disallowed-raw-html-extension-) diff --git a/man/extensions.Rd b/man/extensions.Rd index 9751016..33937ae 100644 --- a/man/extensions.Rd +++ b/man/extensions.Rd @@ -15,7 +15,7 @@ features which are not (yet) in the official commonmark spec. Currently the following extensions are supported: \itemize{ \item \strong{table} support rendering of tables: \href{https://github.github.com/gfm/#tables-extension-}{gfm-spec section 4.10} -\item \strong{strikethrough} via \verb{~sometext~} syntax: \href{https://github.github.com/gfm/#strikethrough-extension-}{gfm-spec section 6.5} +\item \strong{strikethrough} via \verb{~~sometext~~} syntax: \href{https://github.github.com/gfm/#strikethrough-extension-}{gfm-spec section 6.5} \item \strong{autolink} automatically turn URLs into hyperlinks: \href{https://github.github.com/gfm/#autolinks-extension-}{gfm-spec section 6.9} \item \strong{tagfilter} blacklist html tags: \code{title} \code{textarea} \code{style} \code{xmp} \code{iframe} \code{noembed} \code{noframes} \code{script} \code{plaintext}: \href{https://github.github.com/gfm/#disallowed-raw-html-extension-}{gfm-spec section 6.11} diff --git a/src/wrapper.c b/src/wrapper.c index f409f12..d50beef 100644 --- a/src/wrapper.c +++ b/src/wrapper.c @@ -63,6 +63,7 @@ SEXP R_render_markdown(SEXP text, SEXP format, SEXP sourcepos, SEXP hardbreaks, /* combine options */ int options = CMARK_OPT_DEFAULT; + options += CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE; options += Rf_asLogical(sourcepos) * CMARK_OPT_SOURCEPOS; options += Rf_asLogical(hardbreaks) * CMARK_OPT_HARDBREAKS; options += Rf_asLogical(smart) * CMARK_OPT_SMART; diff --git a/tests/testthat/test-extensions.R b/tests/testthat/test-extensions.R index fa922fe..bcd27ef 100644 --- a/tests/testthat/test-extensions.R +++ b/tests/testthat/test-extensions.R @@ -5,19 +5,19 @@ test_that("list extensions", { }) test_that("strikethrough", { - md <- "foo ~bar~ baz" - expect_equal(markdown_html(md, extensions = FALSE), "

foo ~bar~ baz

\n") - expect_equal(markdown_html(md, extensions = TRUE), "

foo bar baz

\n") + md <- "~Hello~ ~~world~~!" + expect_equal(markdown_html(md), "

~Hello~ ~~world~~!

\n") + expect_equal(markdown_html(md, extensions = "strikethrough"), "

~Hello~ world!

\n") - expect_equal(markdown_latex(md, extensions = FALSE), "foo \\textasciitilde{}bar\\textasciitilde{} baz\n") - expect_equal(markdown_latex(md, extensions = TRUE), "foo \\sout{bar} baz\n") + expect_equal(markdown_latex(md), "\\textasciitilde{}Hello\\textasciitilde{} \\textasciitilde{}\\textasciitilde{}world\\textasciitilde{}\\textasciitilde{}!\n") + expect_equal(markdown_latex(md, extensions = "strikethrough"), "\\textasciitilde{}Hello\\textasciitilde{} \\sout{world}!\n") - expect_equal(markdown_man(md, extensions = FALSE), ".PP\nfoo ~bar~ baz\n") - expect_equal(markdown_man(md, extensions = TRUE), ".PP\nfoo \n.ST \"bar\"\n baz\n") + expect_equal(markdown_man(md), ".PP\n~Hello~ ~~world~~!\n") + expect_equal(markdown_man(md, extensions = "strikethrough"), ".PP\n~Hello~ \n.ST \"world\"\n!\n") library(xml2) - doc1 <- xml_ns_strip(read_xml(markdown_xml(md, extensions = FALSE))) - doc2 <- xml_ns_strip(read_xml(markdown_xml(md, extensions = TRUE))) + doc1 <- xml_ns_strip(read_xml(markdown_xml(md))) + doc2 <- xml_ns_strip(read_xml(markdown_xml(md, extensions = "strikethrough"))) expect_length(xml_find_all(doc1, "//strikethrough"), 0) expect_length(xml_find_all(doc2, "//strikethrough"), 1)