Skip to content

Commit 3c82be2

Browse files
committed
add experimental knit preview
1 parent aed7af4 commit 3c82be2

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ Imports:
1717
Suggests:
1818
testthat
1919
LazyData: true
20-
RoxygenNote: 6.0.1.9000
20+
RoxygenNote: 6.1.1
2121
Encoding: UTF-8
2222
Roxygen: list(markdown = TRUE)

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export("%>%")
4+
export(knit_selection_addin)
45
export(str_rmd_wrap)
56
export(wrap_rmd_addin)
67
import(stringr)

R/package.R

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
NULL
1111

1212

13+
1314
#' Wrap text but don't insert lines breaks into inline R code
1415
#'
1516
#' Call this addin to wrap paragraphs in an R Markdown document.
@@ -23,6 +24,22 @@ wrap_rmd_addin <- function() {
2324
}
2425

2526

27+
#' Run selection through knitr and commonmark
28+
#'
29+
#' Call this addin to preview output of an R markdown selection.
30+
#'
31+
#' @export
32+
knit_selection_addin <- function() {
33+
context <- rstudioapi::getActiveDocumentContext()
34+
selection <- context$selection
35+
36+
text <- unlist(selection)["text"]
37+
cat(
38+
commonmark::markdown_commonmark(
39+
knitr::knit(text = text, quiet = TRUE)))
40+
}
41+
42+
2643
#' Wrap text but don't insert lines breaks into inline R code
2744
#'
2845
#' @param string a string to wrap

inst/rstudio/addins.dcf

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ Name: Wrap Rmd
22
Description: Wrap selected R Markdown text but don't insert lines breaks into inline R code
33
Binding: wrap_rmd_addin
44
Interactive: false
5+
6+
Name: Knit Selection
7+
Description: Run selection through knitr/commonmark to preview results.
8+
Binding: knit_selection_addin
9+
Interactive: false

man/knit_selection_addin.Rd

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)