```{r eval=TRUE, echo=FALSE, results="asis"}
# take a character vector of parameters and inject
# the appropriate script tag for code mirror
# ensures that the script tags are only inserted once
for(i in seq_along(params$hilang)) {
js_mode <- paste0("\n\n")
cat(htmltools::htmlPreserve(js_mode))
}
```
```{r eval=TRUE, echo=FALSE}
knitr::knit_hooks$set(source = function(x, options) {
if (!is.null(options$hilang)) {
textarea_id <- paste(sample(LETTERS, 5), collapse = "")
code_open <- paste0("\n\n"
jscript_editor <- paste0("\n\n")
# if the option from_file is set to true then assume that
# whatever is in the code chunk is a file path
if (!is.null(options$from_file) && options$from_file) {
code_body <- readLines(file.path(x))
} else {
code_body <- x
}
knitr::asis_output(
htmltools::htmlPreserve(
stringr::str_c(
code_open,
paste(code_body, collapse = "\n"),
code_close,
jscript_editor
)
)
)
} else {
stringr::str_c("\n\n```", tolower(options$engine), "\n", paste0(x, collapse = "\n"), "\n```\n\n")
}
})
```