Skip to content

Commit

Permalink
notedown
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Jan 10, 2017
1 parent 853111e commit 5adb134
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Depends:
Imports:
knitr,
rmarkdown,
htmltools
htmltools,
tools
RoxygenNote: 5.0.1
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export(hugo)
export(kube)
export(minimal)
export(skeleton)
export(to_jupyter)
import(htmltools)
import(knitr)
import(rmarkdown)
importFrom(tools,file_path_sans_ext)
21 changes: 21 additions & 0 deletions R/ipynb.r
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#' "knit" replacement to generate an ipynb with notedown
#'
#' @export
to_jupyter <- function(inputFile, encoding) {

output_file <- sprintf("%s.%s", tools::file_path_sans_ext(inputFile), "ipynb")

tf <- tempfile(fileext=".Rmd")

tmp <- readLines(inputFile)
yaml_end <- which(grepl("^---", tmp))[2]
writeLines(tmp[(yaml_end+1):length(tmp)], tf)

system2("notedown", args=c(tf, "--rmagic", "--run"), stdout=output_file)

unlink(tf)

output_file

}

3 changes: 2 additions & 1 deletion R/markdowntemplates-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#'
#' @name markdowntemplates
#' @docType package
#' @author Bob Rudis (@@hrbrmstr)
#' @author Bob Rudis ([email protected])
#' @import rmarkdown knitr htmltools
#' @importFrom tools file_path_sans_ext
NULL
11 changes: 5 additions & 6 deletions man/bulma.Rd

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

11 changes: 5 additions & 6 deletions man/kube.Rd

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

2 changes: 1 addition & 1 deletion man/markdowntemplates.Rd

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

11 changes: 5 additions & 6 deletions man/minimal.Rd

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

11 changes: 5 additions & 6 deletions man/skeleton.Rd

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

12 changes: 12 additions & 0 deletions man/to_jupyter.Rd

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

0 comments on commit 5adb134

Please sign in to comment.