Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from sundown to commonmark #95

Merged
merged 64 commits into from
Oct 27, 2022
Merged
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9a44718
delete sundown
yihui Oct 19, 2022
8b3445e
markdown -> Markdown, and mark some functions as internal
yihui Oct 19, 2022
b11c1aa
bootcss -> rstudio cdn for mathjax
yihui Oct 19, 2022
1fc067d
delete some options, and normalize character options to boolean, e.g.…
yihui Oct 19, 2022
8d20929
a plain R implementation of smartypants() (not completely compatible …
yihui Oct 19, 2022
c573580
remove rendererOutputType()
yihui Oct 19, 2022
b3609fd
alias the option `hard_wrap` to `hardbreaks`
yihui Oct 20, 2022
c557804
rewrite .b64EncodeImages() and call xfun::base64_uri()
yihui Oct 20, 2022
0a8550b
a basic version using commonmark is working now (still many rough edg…
yihui Oct 20, 2022
5eb297e
no need special handling here (commonmark::markdown_*() can handle th…
yihui Oct 20, 2022
eba22db
delete the test for base64 encoding
yihui Oct 20, 2022
e44b001
import utils for getFromNamespace()
yihui Oct 20, 2022
5dfde60
rename HTMLOptions.R to render-options.R
yihui Oct 20, 2022
5084170
merge markdownExtensions.R into render-options.R
yihui Oct 20, 2022
9c3dcc3
factor out pkg_file() as a wrapper of system.file(package = 'markdown')
yihui Oct 20, 2022
3e38b0b
use xfun::in_dir()
yihui Oct 20, 2022
c50ac26
remove markdownExtensions() and merge `extensions` into `options` ins…
yihui Oct 21, 2022
8be98b3
warn against the old 'stylesheet' argument and suggest using 'css' in…
yihui Oct 21, 2022
5c94e3a
warn against the fragment.only argument and suggest using options = '…
yihui Oct 21, 2022
0a56cf6
keep .b64EncodeFile() for now: https://github.com/rstudio/leaflet/pul…
yihui Oct 21, 2022
519aa57
add markdownExtensions() back for now: https://github.com/rstudio/lea…
yihui Oct 21, 2022
6298d6c
temporarily add the option back for https://github.com/PolMine/polmin…
yihui Oct 21, 2022
ab1b501
temporarily added back
yihui Oct 21, 2022
2a0ffcd
set the option only for the polmineR package: https://github.com/PolM…
yihui Oct 21, 2022
fe655d1
signal the warnings only when doing CRAN incoming checks or running o…
yihui Oct 21, 2022
a7de2e3
some hacks for packages that would be broken
yihui Oct 21, 2022
6184345
mention changes about `stylesheet` and `fragment.only` arguments
yihui Oct 21, 2022
38eb97a
disable `smart` option for gluedown: https://github.com/kiernann/glue…
yihui Oct 21, 2022
d10e784
tweak examples
yihui Oct 21, 2022
7b5e797
polmineR's tests are too strict in terms of white spaces: https://git…
yihui Oct 21, 2022
9ab9e27
tweak language class names (remove the `language-` prefix)
yihui Oct 21, 2022
0e3a871
also need to tweak language class name for gluedown
yihui Oct 22, 2022
4144930
&frac17; doesn't work for 1/7
yihui Oct 22, 2022
e159f8a
enable the `smartypants` option
yihui Oct 22, 2022
a11ceb8
return character output visibly
yihui Oct 22, 2022
39cf670
support and document the `mathjax_embed` option
yihui Oct 22, 2022
e81432f
simplify the smartypants() function by removing the `file` and `outpu…
yihui Oct 23, 2022
cb31584
rename the argument `renderer` to `format`
yihui Oct 23, 2022
ccb4188
implement the latex_math option for html and latex output
yihui Oct 24, 2022
a1f1bef
use renderMarkdown() instead of markdownToHTML() so that we don't nee…
yihui Oct 24, 2022
fa1acab
use dev version of xfun
yihui Oct 24, 2022
74b3ca8
implement ^superscript^ and ~subscript~
yihui Oct 24, 2022
4b14b2c
don't add ## to output
yihui Oct 24, 2022
e089a7c
implement toc
yihui Oct 24, 2022
b147386
rename `fragment_only` to `standalone` to be more consistent with pandoc
yihui Oct 24, 2022
6ff0dd1
document the `options` argument in more detail
yihui Oct 25, 2022
9b7fa8a
copy functions from xfun so that I don't need to wait for the next re…
yihui Oct 25, 2022
f0fc08f
a less smart way to generate the HTML entities
yihui Oct 25, 2022
a3eaacc
change the option `fragment_only` to `-standalone`
yihui Oct 25, 2022
6004385
the trailing spaces may be on the second but last line, when the last…
yihui Oct 25, 2022
96c83e8
always split text input into lines
yihui Oct 25, 2022
bf56456
allow the `file` argument to accept Markdown text input
yihui Oct 25, 2022
9533a70
move the base64_images into renderMarkdown()
yihui Oct 25, 2022
ffaa2a6
all tags should be lowercase
yihui Oct 25, 2022
e16d995
deal with fragment.only = TRUE earlier
yihui Oct 25, 2022
c08fe92
make the template work for arbitrary metadata, and add support for la…
yihui Oct 27, 2022
5557c48
rename scripts
yihui Oct 27, 2022
8acffca
rename renderMarkdown() to mark(), markdownToHTML() to mark_html(), a…
yihui Oct 27, 2022
a99c403
rename markdownOptions() to markdown_options()
yihui Oct 27, 2022
f129bf4
more camel to snake case
yihui Oct 27, 2022
6f1b431
roxygenize
yihui Oct 27, 2022
7860143
update test output
yihui Oct 27, 2022
a2912c6
correct argument order
yihui Oct 27, 2022
db61947
tweak news [ci skip]
yihui Oct 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
delete some options, and normalize character options to boolean, e.g.…
…, 'smart' to list(smart = TRUE)
yihui committed Oct 19, 2022
commit 1fc067d0a1e80b7dde8b8874333af02b7b912c8e
84 changes: 29 additions & 55 deletions R/renderMarkdown.R
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ renderMarkdown <- function(
) {

if (!rendererExists(renderer))
stop("Renderer '", renderer, "' is not registered!")
stop("Renderer '", renderer, "' is not available.!")

# Input from either a file or character vector
if (!is.character(text)) {
@@ -287,14 +287,15 @@ markdownToHTML <- function(
fragment.only = FALSE,
encoding = 'UTF-8'
) {
if (fragment.only) options <- c(options, 'fragment_only')
options <- normalizeOptions(options)
if (fragment.only) options[['fragment_only']] <- TRUE

ret <- renderMarkdown(
file, output = NULL, text, renderer = 'HTML',
renderer.options = options, extensions = extensions, encoding = encoding
renderer.options = options, extensions = extensions
)

if ('base64_images' %in% options) {
if (isTRUE(options[['base64_images']])) {
filedir <- if (!missing(file) && is.character(file) && file.exists(file)) {
dirname(file)
} else '.'
@@ -305,7 +306,7 @@ markdownToHTML <- function(
})
}

if (!'fragment_only' %in% options) {
if (!isTRUE(options[['fragment_only']])) {
if (is.null(template))
template <- system.file('resources', 'markdown.html', package = 'markdown')
html <- paste(readLines(template), collapse = '\n')
@@ -334,27 +335,20 @@ markdownToHTML <- function(
# Need to scrub title more, e.g. strip html, etc.
html <- sub('#!title#', title, html, fixed = TRUE)

if ('mathjax' %in% options && .requiresMathJax(html)) {
mathjax <- .mathJax(embed = 'mathjax_embed' %in% options)
} else mathjax <- ''
mathjax <- if (isTRUE(options[['mathjax']]) && .requiresMathJax(html)) {
.mathJax(embed = isTRUE(options[['mathjax_embed']]))
} else ''
html <- sub('#!mathjax#', mathjax, html, fixed = TRUE)

if ('highlight_code' %in% options && .requiresHighlighting(html)) {
highlight <- paste(readLines(system.file(
'resources', 'r_highlight.html', package = 'markdown'
)), collapse = '\n')
} else highlight <- ''
highlight <- if (isTRUE(options[['highlight_code']]) && .requiresHighlighting(html)) {
xfun::file_string(system.file('resources', 'r_highlight.html', package = 'markdown'))
} else ''
html <- sub('#!r_highlight#', highlight, html, fixed = TRUE)

ret <- html
}

ret <- enc2utf8(ret)
if (is.character(output)) {
# Output should be always UTF8 in accordance with HTML charset
writeLines(ret, output, useBytes = TRUE)
ret <- NULL
}
ret <- if (is.character(output)) xfun::write_utf8(ret, output) else enc2utf8(ret)

invisible(ret)
}
@@ -511,51 +505,24 @@ markdownExtensions <- function()
#' that are available for the HTML renderer in the \pkg{markdown} package. As a
#' convenience, the package default options were chosen to render well-formed
#' stand-alone HTML pages when using \code{\link{markdownToHTML}()}. The default
#' options are \code{'use_xhtml'}, \code{'smartypants'}, \code{'base64_images'},
#' options are \code{'smartypants'}, \code{'base64_images'},
#' \code{'mathjax'}, and \code{'highlight_code'}.
#'
#' The HTML renderer provides several options described below. To turn these on
#' globally in the \pkg{markdown} package, simply place some or all of them in a
#' character vector and assign to the global option \code{markdown.HTML.options}
#' like so:
#'
#' \code{options(markdown.HTML.options = markdownHTMLOptions())}
#'
#' To reset the options to package default, use:
#'
#' \code{options(markdown.HTML.options = markdownHTMLOptions(default = TRUE))}
#'
#' To override the global option, pass the \code{options} as an argument:
#'
#' \code{markdownToHTML(..., options = c('skip_images'))}
#' character vector and assign to the global option \code{markdown.HTML.options}.
#'
#' Description of all options:
#'
#' \describe{
#'
#' \item{\code{'skip_html'}}{ suppress output of all HTML tags in the document.}
#'
#' \item{\code{'skip_style'}}{ suppress output of HTML style tags.}
#'
#' \item{\code{'skip_images'}}{ suppress output of HTML image tags.}
#'
#' \item{\code{'skip_links'}}{ suppress output of HTML anchor tags.}
#'
#' \item{\code{'safelink'}}{ only create links for known url types, e.g. http,
#' ftp, http, etc.}
#'
#' \item{\code{'toc'}}{ assigns an HTML id to each header of the form 'toc_%d'
#' where '%d' is replaced with the position of the header within the document
#' (starting at 0), and creates the table of contents.}
#'
#' \item{\code{'hard_wrap'}}{ adds an HTML br tag for every newline (excluding
#' trailing) found within a paragraph.}
#'
#' \item{\code{'use_xhtml'}}{ create XHMTL 1.0 compliant HTML tags.}
#'
#' \item{\code{'escape'}}{ escape all HTML found within the \emph{Markdown}.
#' Overrides all of the \code{'skip_*'} options mentioned above.}
#'
#' \item{\code{'smartypants'}}{ translates plain ASCII punctuation characters
#' into \emph{smart} typographic punctuation HTML entities. }
#'
@@ -591,17 +558,24 @@ markdownExtensions <- function()
#' # To turn off all HTML options globally:
#' options(markdown.HTML.options = NULL)
#'
#' # To turn on one option globally:
#' options(markdown.HTML.options = 'smartypants')
#'
#' # To turn on package default HTML options globally:
#' options(markdown.HTML.options = markdownHTMLOptions(default = TRUE))
#' options(markdown.HTML.options = markdownHTMLOptions(defaults = TRUE))
#'
#' @example inst/examples/HTMLOptions.R
markdownHTMLOptions <- function(defaults = FALSE) {
allOptions <- c(
'skip_html', 'skip_style', 'skip_images', 'skip_links', 'safelink', 'toc',
'escape', 'fragment_only', 'hard_wrap', 'use_xhtml', 'smartypants',
'base64_images', 'mathjax', 'highlight_code'
)
if (defaults) allOptions[10:14] else allOptions
sort(c(
c('smart', 'smartypants', 'base64_images', 'mathjax', 'highlight_code'),
if (!defaults) c('toc', 'fragment_only', 'hard_wrap')
))
}

#' @import stats
normalizeOptions <- function(x) {
if (is.character(x)) x <- as.list(setNames(rep(TRUE, length(x)), x))
x
}

.onLoad <- function(libname, pkgname) {