Skip to content

Commit

Permalink
Add embed_fonts argument to readthedown
Browse files Browse the repository at this point in the history
  • Loading branch information
juba committed Jun 23, 2020
1 parent 8b97336 commit d584b5e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
17 changes: 14 additions & 3 deletions R/readthedown.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' @param pandoc_args arguments passed to the pandoc_args argument of rmarkdown \code{\link[rmarkdown]{html_document}}
#' @param md_extensions arguments passed to the md_extensions argument of rmarkdown \code{\link[rmarkdown]{html_document}}
#' @param toc_depth adjust table of contents depth
#' @param embed_fonts if TRUE, use local files for Lato and Roboto Slab fonts used in the template. This leads to bigger files but ensures that these fonts are available.
#' @param use_bookdown if TRUE, uses \code{\link[bookdown]{html_document2}} instead of \code{\link[rmarkdown]{html_document}}, thus providing numbered sections and cross references
#' @param mathjax set to NULL to disable Mathjax insertion
#' @param ... Additional function arguments passed to R Markdown \code{\link[rmarkdown]{html_document}}
Expand All @@ -38,6 +39,7 @@ readthedown <- function(fig_width = 8,
thumbnails = FALSE,
gallery = FALSE,
toc_depth = 2,
embed_fonts = TRUE,
use_bookdown = FALSE,
pandoc_args = NULL,
md_extensions = NULL,
Expand All @@ -48,7 +50,7 @@ readthedown <- function(fig_width = 8,
template_name = "readthedown",
template_path = "templates/template.html",
template_dependencies = list(
html_dependency_readthedown()
html_dependency_readthedown(embed_fonts)
),
pandoc_args = pandoc_args,
fig_width = fig_width,
Expand All @@ -69,10 +71,19 @@ readthedown <- function(fig_width = 8,
}

# readthedown js and css
html_dependency_readthedown <- function() {
html_dependency_readthedown <- function(embed_fonts = TRUE) {
stylesheets <- "readthedown.css"
if (embed_fonts) stylesheets <- c(stylesheets, "readthedown_fonts.css")
htmltools::htmlDependency(name = "readthedown",
version = "0.1",
src = system.file("templates/readthedown", package = "rmdformats"),
script = "readthedown.js",
stylesheet = c("readthedown.css"))
stylesheet = stylesheets)
}







33 changes: 0 additions & 33 deletions inst/templates/readthedown/readthedown.css
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
/* Palette : https://coolors.co/211103-3d1308-7b0d1e-9f2042-f8e5ee */

@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: url(fonts/Lato.ttf) format('truetype');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: url(fonts/LatoBold.ttf) format('truetype');
}
@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: url(fonts/LatoItalic.ttf) format('truetype');
}
@font-face {
font-family: 'Roboto Slab';
font-style: normal;
font-weight: 400;
src: url(fonts/RobotoSlab-Regular.ttf) format('truetype');
}
@font-face {
font-family: 'Roboto Slab';
font-style: normal;
font-weight: 700;
src: url(fonts/RobotoSlab-Bold.ttf) format('truetype');
}


/* Nav pills */

Expand Down
32 changes: 32 additions & 0 deletions inst/templates/readthedown/readthedown_fonts.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 400;
src: url(fonts/Lato.ttf) format('truetype');
}
@font-face {
font-family: 'Lato';
font-style: normal;
font-weight: 700;
src: url(fonts/LatoBold.ttf) format('truetype');
}
@font-face {
font-family: 'Lato';
font-style: italic;
font-weight: 400;
src: url(fonts/LatoItalic.ttf) format('truetype');
}
@font-face {
font-family: 'Roboto Slab';
font-style: normal;
font-weight: 400;
src: url(fonts/RobotoSlab-Regular.ttf) format('truetype');
}
@font-face {
font-family: 'Roboto Slab';
font-style: normal;
font-weight: 700;
src: url(fonts/RobotoSlab-Bold.ttf) format('truetype');
}
3 changes: 3 additions & 0 deletions man/readthedown.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d584b5e

Please sign in to comment.