R/args-preprocessors.r

Defines functions args_preprocessors

preprocessors_re <- '^\\s*%%\\s*\\\\VignettePreprocessors\\{%s\\}\\{\\s*([^}]+?)\\s*\\}\\s*$'

args_preprocessors <- function(lines, fmt) {
	kind <- switch(
		fmt, html = 'HTML', latex = 'Latex', markdown = 'Markdown',
		pdf = 'PDF', rst = 'RST', script = 'Script', slides = 'Slides')
	
	re <- sprintf(preprocessors_re, fmt)
	
	preprocessors_lines <- grep(re, lines, value = TRUE)
	preprocessors <- unlist(lapply(
		sub(re, '\\1', preprocessors_lines),
		function(pps) strsplit(pps, '\\s*,\\s*')))
	
	if (length(preprocessors) > 0L) {
		sprintf('--%sExporter.preprocessors=["%s"]', kind, paste(preprocessors, collapse = '","'))
	} else character(0L)
}

Try the nbconvertR package in your browser

Any scripts or data that you put into this service are public.

nbconvertR documentation built on Jan. 11, 2020, 9:09 a.m.