Title: | 'juice' + 'markdown': Convert 'R Markdown' into 'HTML' with Inline Styles |
---|---|
Description: | A convenience tool to create 'HTML' with inline styles using 'juicyjuice' and 'markdown' packages. It is particularly useful when working on a content management system (CMS) whose code editor eliminates style and link tags. The main use case of the package is the learning management system, 'Moodle'. Additional helper functions for teaching purposes are provided. Learn more about 'juicedown' at <https://kenjisato.github.io/juicedown/>. |
Authors: | Kenji Sato [aut, cre, cph] |
Maintainer: | Kenji Sato <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1.9000 |
Built: | 2024-11-04 06:05:36 UTC |
Source: | https://github.com/kenjisato/juicedown |
This function inserts HTML snippet to help students memorize important concepts.
To make this function to work, you need to run anki_setup()
somewhere in
the markdown document.
anki(text)
anki(text)
text |
character. Text to toggle. |
HTML code span.
This function inserts JavaScript code for anki texts.
Call this function in a code chunk somewhere in your R Markdown file.
Use anki()
function with a inline r code, to make a hidden block.
anki_setup( background = "yellow", color = "blue", border = "slateblue", padding = 3, margin = 3, cursor = "pointer" )
anki_setup( background = "yellow", color = "blue", border = "slateblue", padding = 3, margin = 3, cursor = "pointer" )
background |
character. Background color of the blank box. |
color |
character. Font color of the answer of the blank box. |
border |
character. Border color of the blank box. |
padding |
integer. Space between the answer text and the border. |
margin |
integer. Left and right margin around the border. |
cursor |
character. |
character. CSS/JavaScript code for anki texts.
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:
it converts (R) Markdown file into a HTML file with
knitr::knit()
+ markdown::mark()
,
embed CSS information in style atribute with juicyjuice::css_inline()
,
and then
extracts article/div element that is ready for copying and pasting into CMS's source editor.
convert( file = NULL, dir = NULL, tag = NULL, id = NULL, clip = TRUE, full_html = NULL, remove_script = NULL, stylesheet = NULL, template = NULL )
convert( file = NULL, dir = NULL, tag = NULL, id = NULL, clip = TRUE, full_html = NULL, remove_script = NULL, stylesheet = NULL, template = NULL )
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 |
logical. Produce the complete HTML or HTML block only? |
remove_script |
logical. Whether or not remove script tags. Ignored
(set to FALSE) if |
stylesheet |
character. Paths to the CSS files used in markdown::mark() |
template |
character. Path to the template used in markdown::mark() |
Invisibly returns a character vector identical to the result file.
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")
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.
file <- juicedown_example("markdown", "sample.md") tdir <- tempdir() convert(file, dir = tdir, clip = FALSE) unlink(file.path(tdir, "sample.html"))
file <- juicedown_example("markdown", "sample.md") tdir <- tempdir() convert(file, dir = tdir, clip = FALSE) unlink(file.path(tdir, "sample.html"))
Convert a HTML file into a HTML block to be copied and pasted for CMS.
convert_html2cms( in_text, full_html = the$full_html %||% FALSE, tag = the$tag %||% "body", id = the$id, remove_script = the$remove_script %||% FALSE )
convert_html2cms( in_text, full_html = the$full_html %||% FALSE, tag = the$tag %||% "body", id = the$id, remove_script = the$remove_script %||% FALSE )
in_text |
character. Character vector representing the HTML file to convert. |
full_html |
logical. If TRUE, produce complete html output, convenient when drafting a document. When this option is enabled, tag and id and remove_script options are silently ignored. |
tag |
character. Outer-most tag for the resulting HTML snippet. |
id |
character. id attribute for the outer-most tag. |
remove_script |
logical. If TRUE, script tags are all stripped out. |
character. HTML block.
Define a counter with cnt <- counter("type")
. Add cross-referenced label
in your document with cnt$set("ref")
. Refer to "ref" with cnt$get("ref")
.
counter(label, open = NULL, close = NULL, sep = " ", link = FALSE)
counter(label, open = NULL, close = NULL, sep = " ", link = FALSE)
label |
character. Default prefix for the counter. |
open |
character. Opening bracket such as "(" or "[" |
close |
character. Closing bracket such as ")" or "]" |
sep |
character. Separator between label and counter. |
link |
logical. If TRUE, get() method returns a counter surrounded by a tag, linked to the referenced id. |
List of functions to set and get counters with label.
cnt <- counter("Quiz") cnt$set("aaa") cnt$set() cnt$set("bbb", quiet = TRUE) cnt$get("aaa") cnt$get("bbb") cnt$get("aaa", type = "bare") cnt$dump()
cnt <- counter("Quiz") cnt$set("aaa") cnt$set() cnt$set("bbb", quiet = TRUE) cnt$get("aaa") cnt$get("bbb") cnt$get("aaa", type = "bare") cnt$dump()
Include Audio media.
includeAudio( url, preload = c("metadata", "auto", "none"), alt = "Your browser does not support the audio element." )
includeAudio( url, preload = c("metadata", "auto", "none"), alt = "Your browser does not support the audio element." )
url |
character. URL of the audio. The media must not be gated. |
preload |
character. One of metadata, auto and none. |
alt |
character. Message displayed when the browser does not support the audio tag. |
An R object of class "knit_asis" (defined in the knitr package), the data of which is the HTML audio tag to insert into the document.
Include Flickr album
includeFlickr(albumUrl, title = NULL, width = 480, height = 360)
includeFlickr(albumUrl, title = NULL, width = 480, height = 360)
albumUrl |
character. Share URL of a public album |
title |
character. Default NULL. If given, overwrite the title of the album. |
width |
integer. Width of the widget in pixel. |
height |
integer. Height of the widget in pixel. |
Flickr embed code.
This function is a wrapper for knitr::include_graphics()
.
includeGraphics(path, ...)
includeGraphics(path, ...)
path |
character. Path to the image. |
... |
Parameters passed to |
The result of knitr::include_graphics()
Include Summary/Details block.
includeQuestion( summary, detail, summary_label = "Quiz", detail_label = "Answer", ... )
includeQuestion( summary, detail, summary_label = "Quiz", detail_label = "Answer", ... )
summary |
character. Text to show, typically, question string. |
detail |
character. Texts to hide, typically, answer string. |
summary_label |
character. Label for the open block. |
detail_label |
character. Label for the hidden block. |
... |
character. Concatenated with the detail argument. |
HTML5 summary/details block is inserted.
Insert text into a document.
includeText(path, data = parent.frame(), quiet = TRUE)
includeText(path, data = parent.frame(), quiet = TRUE)
path |
Path to the child document. |
data |
Environment or list used to knit the child document. |
quiet |
Passed to |
An R object of class "knit_asis" (defined in the knitr package),
the data of which represents the content of the child document (after
knitr::knit()
)
template <- tempfile() cat("Hello, `r name`.\n", file = template) includeText(template, data = list(name = "Alice")) file.remove(template)
template <- tempfile() cat("Hello, `r name`.\n", file = template) includeText(template, data = list(name = "Alice")) file.remove(template)
Include YouTube video.
includeYT(url, .class = "includeYT")
includeYT(url, .class = "includeYT")
url |
character. URL of the YouTube video. |
.class |
character. The resulting iframe tag is surrounded by div block. You can specify its class attribute to modify its styling. |
An embed code of a YouTube video is inserted.
List example files for the package. Show the path when the exact name is given.
juicedown_example(name = NULL, file = NULL)
juicedown_example(name = NULL, file = NULL)
name |
character. A single string for example name. |
file |
character. A single string for the main file. |
The package sample files are organized under samples directory like so:
samples/
|– from-html/
| -- sample.html
– include/
|– pic/
'– sample.Rmd
juicedown_example()
is equivalent to ls samples
,
juicedown_example("from-html")
is to ls samples/from-html
, and
juicedown_example("from-html", "sample.html")
shows the full path.
character. A list of example files or a path string to each example file.
juicedown_example() juicedown_example("from-html") juicedown_example("from-html", "sample.html")
juicedown_example() juicedown_example("from-html") juicedown_example("from-html", "sample.html")
Footnote highlighting is corrupt when CSS is in-lined. Fix this by calling this function in a code chunk somewhere in your R Markdown file.
tweak_footnote_highlight()
tweak_footnote_highlight()
Script block that makes highlighting possible.
You may want the title of the article to be different from the title of the resource. Call this function in a code chunk somewhere in your R Markdown file.
tweak_moodle_heading()
tweak_moodle_heading()
Script block that makes H2 head of the content invisible.