File: get_extensions.R

package info (click to toggle)
r-cran-simplermarkdown 0.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,568 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' Get the extensions that are needed when converting from json to markdown by 
#' pandoc.
#'
#' @details
#' Checks which extensions are available in pandoc and returns a character
#' string disabling extensions that interfere with the conversion of the
#' processed document (in json format) back to markdown. At the moment only one
#' extension is disabled.
#'
#' \describe{
#'   \item{\code{raw_attribute}}{ This extension is disabled. Some of the output
#'   functions write raw markdown blocks. This extension only recognises html
#'   and tex raw blocks. Raw markdown blocks are ignored when converting to
#'   other formats. }
#' }
#'
#' @return 
#' Returns a character vector of the form \code{"+extension1-extension2"} with
#' the extensions that are to be enabled (\code{+}) or disables (\code{-}).
#' The function calls \code{pandoc} to check which extensions are available.
#'
#' @export
get_extensions <- function() {
  extensions <- character(0)
  # Get the list of extensions supported by the installed pandoc
  supported_extensions <- system("pandoc --list-extensions", intern = TRUE)
  # when converting from json to markdown we need to disable the raw_attribute
  # extension. Some of the output functions write raw markdown. With this
  # extension this raw markdown is put into a
  # ```{=markdown}
  # markdown
  # ```
  # block. This is not recognised when converting to other formats.
  has_raw <- any(grepl("^[+-]raw_attribute", supported_extensions))
  if (has_raw) {
    extensions <- paste0(extensions, "-raw_attribute")
  }
  extensions
}