knitr::opts_chunk$set(results.folding = NULL) `%>%` <- magrittr::`%>%`
This article introduces rich features of minidown::mini_document
with live examples.
This format is powered by R Markdown, Pandoc, KaTeX and light weight CSS framewroks such as sakura (default), Water.css, mini.css, and so on.
If you haven't installed the minidown
package on R, install it by
remotes::install_github('atusy/minidown')
Documentation is ready at here.
THe default framework and its theme are "sakura"
and "default"
.
Followings are the list of available ones.
To preview them, use the UI at the top of this page.
frameworks <- lapply( minidown::frameworks, function(x) names(x$stylesheet) ) %>% tibble::enframe() %>% tidyr::unchop(value) %>% purrr::set_names(c("framework", "theme")) %>% dplyr::mutate(output_file = paste0(framework, '-', theme, '.html')) %>% dplyr::mutate( output_file = ifelse( output_file == "sakura-default.html", "index.html", .data$output_file ), ) frameworks %>% dplyr::mutate(framework = factor(framework, levels = unique(framework))) %>% dplyr::group_by(framework) %>% dplyr::summarise(theme = paste(theme, collapse = ', ')) %>% knitr::kable(escape=FALSE)
Here's an example YAML frontmatter specifying a framework and a theme.
output: minidown::mini_document: framework: sakura theme: default
Code folding can be controlled by the YAML frontmatter like:
output: minidown::mini_document: code_folding: source: show output: show message: hide warning: hide error: show
The above results in
f <- function() { print(1) message('message') warning('warning') stop('error') } f()
If the code folding is specified for some of them,
then the code folding of the others will be none
.
Like rmarkdown::html_document
,
code_folding: show
indicates source is show
and others are none
.
By default code_folding
is none
, however, you can select some chunks be folded by giving the details
class (e.g., class.source='details'
).
When source: show
, all the sources are shown.
In case you need exceptions, add the hide
class to the source.
If you want to hide all with exceptions, add the show
class to the exceptions.
Of course, this feature is not limited to the source.
--- output: minidown::mini_document: code_folding: source: show --- `r ''````r 'This is shown' `r ''```` `r ''````r 'This is hidden' `r ''````
and hide
classes.
The content of summary can be controlled via summary.*
chunk options.
This feature is useful when you want to show the title of the source, to treat the output as a hidden answer, and so on.
# summary.source='iris.R', summary.output='Answer', class.output='hide' head(iris)
Even if none
is specified in YAML, code folding can be enabled for selected chunks by adding the details
class.
--- output: minidown::mini_document: code_folding: none --- `r ''````r 'This is shown' `r ''```` `r ''````r 'This is hidden' `r ''````
rmarkdown::html_document
If you prefer rmarkdown::html_document
except for the code foliding,
specify the framework: bootstrap
.
output: minidown::mini_document: framework: bootstrap code_folding: show
By specifying result_folding: show
or hide
, you can fold entire results.
output: minidown::mini_document: results_folding: show # hide or none
This is a good option when you have side effects such as drawing figures and tables. Result button is placed on the left so that you can distinguish from code_folding buttons.
knitr::kable(iris[1:2, ])
By default, summary text is "Results".
You can change this by a chunk option, summary.results
.
Just like summary.*
in code folding.
If you have multiple results per chunk and combine them to a single folding, you have three options.
with results='hold'
and/or fig.show='hold'
.
'foo' knitr::kable(iris[1:2, ])
for
or lapply
or their friends.
for (i in 1:2) print(i)
f <- function() { print('foo') knitr::knit_print(knitr::kable(iris[1:2, ])) } f()
To disable folding for some chunks, specify results.folding=NULL
as a chunk option.
When results_folding: show
and you want to hide for some, then specify results.folding='hide'
as a chunk option.
Similarly, you make exeptions for results_folding: hide
as well.
To disable folding by default, but enable it for some chunks,
then specify results_folding: show # or hide
as a YAML front matter,
and run knitr::opts_chunk$set(results.folding=NULL)
at the beggining of your document.
Then, you can enable the feature for selected chunks by specifying 'show'
or 'hide'
to the results.folding
chunk option.
--- output: minidown::mini_document: result_folding: show --- `r ''````r knitr::opts_knit$set(results.folding=NULL) `r ''```` `r ''````r 'This chunk does not fold results' `r ''```` `r ''````r 'This chunk hides not fold results' `r ''````
Table of contents can be floated on the left of the page by specifying toc_float: true
.
The layout is responsive to the windows size.
Thus, floating TOC is available when the viewport has the enough width.
See what happens by shrinking the width of your browser.
Also, the floating ToC can also be highlighted according to the browsing section by specifying toc_highlight: true
output: minidown::mini_document: toc: true toc_float: true toc_highlight: true
Sections become tabs when they belong to the tabset
-class section, and
minidown::mini_document(tabset = TRUE)
.
This feature is similar to the one in rmarkdown::html_document
.
Two major difference are
2 + 1 steps to use:
tabset
class to a header (e.g., # Tabset {.tabset}
)## Introduction
and ## Example Rmd
)active
class to a nested header (e.g., ## Example Rmd {.active}
)Note that a tab may nest tabs, however there will be
toc_highlight
option (cf. [Floating TOC]{#floating-toc}).--- title: tabset output: minidown::mini_document: tabset: true --- # Tabset {.tabset} ## Tab 1 This is the first tab. ## Tab 2 {.active} This is the second tab, which is initially active due to the `{.active}` attribute. If the attribute is missing, the first tab is initially active.
[[]{.icon-info}Tooltips]{tooltip='Here is a tooltip'} are available.
[text]{tooltip='tooltip'}
$\sum_{i=1}^{10}{\alpha_i}$
becomes $\sum_{i=1}^{10}{\alpha_i}$ and
$$ \sum_{i=1}^{10}{\alpha_i} $$
becomes
$$ \sum_{i=1}^{10}{\alpha_i} $$
Single
Nesting
another
A code block without line numbers.
Code block
A code block with line numbers.
```{.r .numberLines startFrom=10} f <- function() { print(1) message('message') warning('warning') stop('error') } f()
### Code blocks with long lines #### Without specifiying language
long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long
#### With specifying language ##### Without line numbers ```{.r} long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long
```{.r .numberLines} long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long
## Lists ### Bullet lists Tight * Tight 1 * Tight 2 * Tight 2-1 * Tight 2-2 Loose * Loose 1 * Loose 2 * Loose 3 ### Ordered lists 1. one 2. two 3. three ### Task lists - [ ] an unchecked task list item - [x] checked item ### Definition lists Term 1 ~ Definition 1 Term 2 ~ Definition 2a ~ Definition 2b ## Horizontal rule ___ ## Table ```r knitr::kable(head(iris))
Verbatim
{data-external="1"}
See^[footnote]
all_framework <- identical( rmarkdown::metadata$output[["minidown::mini_document"]]$framework, "all" )
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.