From 2bf00d3ec756000799ff9baf7e786e7a1125eea5 Mon Sep 17 00:00:00 2001 From: atusy <30277794+atusy@users.noreply.github.com> Date: Thu, 22 Oct 2020 22:40:55 +0900 Subject: [PATCH] 'add .extensions and .pandoc_args arguments' (#26) * add .extensions and .pandoc_args arguments * update vignettes * update NEWS * build docs and man * update NEWS --- NEWS.md | 3 ++- R/as-paragraph-md.R | 29 ++++++++++++++++++++++------ R/colformat.R | 5 ++++- R/md2ast.R | 6 ++---- R/md2df.R | 4 ++-- docs/articles/format_columns.html | 4 ++-- docs/news/index.html | 7 ++++--- docs/pkgdown.yml | 2 +- docs/reference/as_paragraph_md.html | 16 ++++++++++++--- docs/reference/colformat_md.html | 12 +++++++++++- docs/reference/footnote_options.html | 2 +- man/as_paragraph_md.Rd | 10 ++++++++-- man/colformat_md.Rd | 8 +++++++- vignettes/format_columns.Rmd | 6 +++--- 14 files changed, 83 insertions(+), 31 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0cc7fd6..a560323 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# ftExtra 0.0.3.6 +# ftExtra 0.0.3.7 * Support markdown footnote with `colformat_md`. Currently, one footnote per a cell is allowed, and it must be located at the end of the cell content (#22). * Add `footnote_options()` to configure options for footnotes (#23). @@ -6,6 +6,7 @@ * Support single- and double-quotes by a lua filter (dfc82e0). * Support attributes with Span, Link, and Code. Useful attributes include the `.underline` class and the `color`, `shading.color`, and `font.family` attributes (#24). * Support inline code (#25). +* Add the `.extensions` and `.pandoc_args` arguments to `colformat_md()` and `as_paragraph_md()` (#26). # ftExtra 0.0.3 diff --git a/R/as-paragraph-md.R b/R/as-paragraph-md.R index d6a9741..f2871c5 100644 --- a/R/as-paragraph-md.R +++ b/R/as-paragraph-md.R @@ -31,14 +31,23 @@ image_size <- function(x, y = "width") { } parse_md <- function(x, - .from = "markdown", auto_color_link = "blue", + .from = "markdown", + .pandoc_args = NULL, .footnote_options = NULL) { if (!is.character(auto_color_link) || length(auto_color_link) != 1L) { stop("`auto_color_link` must be a string") } - md_df <- md2df(x, .from = .from) + md_df <- md2df( + x, + .from = .from, + .pandoc_args = c( + "--lua-filter", system.file("lua/smart.lua", package = "ftExtra"), + "--lua-filter", system.file("lua/inline-code.lua", package = "ftExtra"), + .pandoc_args + ) + ) if (is.null(.footnote_options) || (all(names(md_df) != "Note"))) { y <- md_df @@ -96,7 +105,12 @@ construct_chunk <- function(x, auto_color_link = "blue") { #' @param auto_color_link A color of the link texts. #' @param .from #' Pandoc's `--from` argument (default: `'markdown+autolink_bare_uris'`). -#' @param .footnote_options Spec options for footnotes via `colformat_md`. +#' @param .extensions +#' Pandoc's extensions (see ) +#' @param .pandoc_args +#' Extra arguments given to Pandoc +#' @param ... +#' Arguments passed to internal functions. #' #' @examples #' if (rmarkdown::pandoc_available()) { @@ -114,10 +128,13 @@ construct_chunk <- function(x, auto_color_link = "blue") { as_paragraph_md <- function(x, auto_color_link = "blue", .from = "markdown+autolink_bare_uris", - .footnote_options = NULL) { + .extensions = NULL, + .pandoc_args = NULL, + ...) { structure(lapply(x, parse_md, - .from = .from, + .from = paste0(.from, paste(.extensions, collapse="")), + .pandoc_args = .pandoc_args, auto_color_link = auto_color_link, - .footnote_options = .footnote_options), + ...), class = "paragraph") } diff --git a/R/colformat.R b/R/colformat.R index 13d3057..bdd4497 100644 --- a/R/colformat.R +++ b/R/colformat.R @@ -25,7 +25,9 @@ colformat_md <- function(x, part = c("body", "header", "all"), auto_color_link = "blue", .footnote_options = footnote_options(), - .from = "markdown+autolink_bare_uris" + .from = "markdown+autolink_bare_uris", + .extensions = NULL, + .pandoc_args = NULL ) { .j <- rlang::enexpr(j) part <- match.arg(part) @@ -56,6 +58,7 @@ colformat_md <- function(x, unlist(dataset[col], use.names = FALSE), auto_color_link = auto_color_link, .from = .from, + .extensions = .extensions, .footnote_options = .footnote_options )) diff --git a/R/md2ast.R b/R/md2ast.R index eda48c2..5998b68 100644 --- a/R/md2ast.R +++ b/R/md2ast.R @@ -2,7 +2,7 @@ #' @param x A character vector #' @param .from Markdown format #' @noRd -md2ast <- function(x, .from = "markdown") { +md2ast <- function(x, .from = "markdown", .pandoc_args = NULL) { tf <- tempfile() writeLines(x, tf) jsonlite::fromJSON( @@ -12,9 +12,7 @@ md2ast <- function(x, .from = "markdown") { tf, "--from", .from, "--to json", - "--lua-filter", system.file("lua/smart.lua", package = "ftExtra"), - "--lua-filter", system.file("lua/inline-code.lua", package = "ftExtra"), - "" + paste(.pandoc_args, collapse = " ") ), intern = TRUE ), diff --git a/R/md2df.R b/R/md2df.R index 9dfc7f7..cd9a466 100644 --- a/R/md2df.R +++ b/R/md2df.R @@ -149,8 +149,8 @@ ast2df <- function(x) { #' Convert Pandoc's Markdown to data frame #' @noRd -md2df <- function(x, .from) { - ast <- md2ast(x, .from = .from) +md2df <- function(x, .from = "markdown", .pandoc_args = NULL) { + ast <- md2ast(x, .from = .from, .pandoc_args = .pandoc_args) if ((ast$blocks[[1]]$t != "Para") || (length(ast$blocks) > 1)) { stop("Markdown text must be a single paragraph") diff --git a/docs/articles/format_columns.html b/docs/articles/format_columns.html index a4a26e4..aaf543e 100644 --- a/docs/articles/format_columns.html +++ b/docs/articles/format_columns.html @@ -267,10 +267,10 @@

Emoji

-

Pandoc’s markdown provides an extension, 'emoji'. To use it with colformat_md(), specify markdown+emoji.

+

Pandoc’s markdown provides an extension, emoji. To use it with colformat_md(), specify .extensions="+emoji".

data.frame(emoji = c(":+1:"), stringsAsFactors = FALSE) %>%
   as_flextable() %>%
-  colformat_md(.from = "markdown+emoji")
+ colformat_md(.extensions = "+emoji")
diff --git a/docs/news/index.html b/docs/news/index.html index 76912d3..928f48e 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -132,9 +132,9 @@

Changelog

Source: NEWS.md -
-

-ftExtra 0.0.3.6 Unreleased +
+

+ftExtra 0.0.3.7 Unreleased

  • Support markdown footnote with colformat_md. Currently, one footnote per a cell is allowed, and it must be located at the end of the cell content (#22).
  • @@ -143,6 +143,7 @@

  • Support single- and double-quotes by a lua filter (dfc82e0).
  • Support attributes with Span, Link, and Code. Useful attributes include the .underline class and the color, shading.color, and font.family attributes (#24).
  • Support inline code (#25).
  • +
  • Add the .extensions and .pandoc_args arguments to colformat_md() and as_paragraph_md() (#26).
diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3f48efb..64f6378 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -5,5 +5,5 @@ articles: format_columns: format_columns.html group-rows: group-rows.html transform-headers: transform-headers.html -last_built: 2020-10-22T12:58Z +last_built: 2020-10-22T13:37Z diff --git a/docs/reference/as_paragraph_md.html b/docs/reference/as_paragraph_md.html index 2b47fb9..6084d97 100644 --- a/docs/reference/as_paragraph_md.html +++ b/docs/reference/as_paragraph_md.html @@ -142,7 +142,9 @@

Convert a character vector into markdown paragraph(s)

x, auto_color_link = "blue", .from = "markdown+autolink_bare_uris", - .footnote_options = NULL + .extensions = NULL, + .pandoc_args = NULL, + ... )

Arguments

@@ -161,8 +163,16 @@

Arg

- - + + + + + + + + + +

emoji

👍

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

.footnote_options

Spec options for footnotes via colformat_md.

.extensions

Pandoc's extensions (see https://www.pandoc.org/MANUAL.html#extensions)

.pandoc_args

Extra arguments given to Pandoc

...

Arguments passed to internal functions.

diff --git a/docs/reference/colformat_md.html b/docs/reference/colformat_md.html index ef8d26f..681863b 100644 --- a/docs/reference/colformat_md.html +++ b/docs/reference/colformat_md.html @@ -144,7 +144,9 @@

Format character columns as markdown text

part = c("body", "header", "all"), auto_color_link = "blue", .footnote_options = footnote_options(), - .from = "markdown+autolink_bare_uris" + .from = "markdown+autolink_bare_uris", + .extensions = NULL, + .pandoc_args = NULL )

Arguments

@@ -176,6 +178,14 @@

Arg .from

Pandoc's --from argument (default: 'markdown+autolink_bare_uris').

+ + .extensions +

Pandoc's extensions (see https://www.pandoc.org/MANUAL.html#extensions)

+ + + .pandoc_args +

Extra arguments given to Pandoc

+ diff --git a/docs/reference/footnote_options.html b/docs/reference/footnote_options.html index d384779..233eb53 100644 --- a/docs/reference/footnote_options.html +++ b/docs/reference/footnote_options.html @@ -183,7 +183,7 @@

Value

An environment

Examples

-
footnote_options("1", start = 1L)
#> <environment: 0x555f363da2b8>
+
footnote_options("1", start = 1L)
#> <environment: 0x558411bd1ac8>