Skip to contents

This function facilitates writing contents in R Markdown formats for CMS the source editor of which silently removes style tags. When run interactively, the resulting HTML code will be copied to the clipboard.

It basically does three things:

  1. it converts (R) Markdown file into a HTML file with knitr::knit() + markdown::mark(),

  2. embed CSS information in style atribute with juicyjuice::css_inline(), and then

  3. extracts article/div element that is ready for copying and pasting into CMS's source editor.

Usage

convert(
  file = NULL,
  dir = NULL,
  tag = NULL,
  id = NULL,
  clip = TRUE,
  full_html = NULL,
  remove_script = NULL,
  stylesheet = NULL,
  template = NULL
)

Arguments

file

character. Path to the (R)markdown file.

dir

character. Output directory.

tag

character. Surrounding tag for the HTML block, "article" and "div" are allowed.

id

character. ID attribute for the surrounding tag.

clip

logical. Whether or not copy the result to clipboard. Ignored (set to FALSE) if full_html = TRUE. Default is TRUE.

full_html

logical. Produce the complete HTML or HTML block only?

remove_script

logical. Whether or not remove script tags. Ignored (set to FALSE) if full_html = TRUE.

stylesheet

character. Paths to the CSS files used in markdown::mark()

template

character. Path to the template used in markdown::mark()

Value

Invisibly returns a character vector identical to the result file.

Details

Change default behaviors with options()

Currently, three global defaults are available. You can set these defaults to alter the appearance of the result.

  • juicedown.template: Defaults to juicedown:::pkg_file("xml", "template.html")

  • juicedown.article.css: Defaults to juicedown:::pkg_file("css", "article.scss")

  • juicedown.div.css: juicedown:::pkg_file("css", "div.scss")

Priority order

You can pass conversion parameters in function argument and YAML metadata (under juicedown key) and for some parameters, global options, with priority given in that order. For instance, if the stylesheet parameter exists in the function call, it is used. If not and if YAML metadata has stylesheet key under juicedown key, then that will be used. In the below example, some.css used.

---
juicedown:
  stylesheet:
     some.css
---

If neither the function argument nor missing YAML metadata exist, then the global option (such as juicedown.article.css) will be used.

Examples

file <- juicedown_example("markdown", "sample.md")
tdir <- tempdir()
convert(file, dir = tdir, clip = FALSE)
unlink(file.path(tdir, "sample.html"))