Skip to content

Commit 4692835

Browse files
committed
move tests for Markdown options from the R script to an Rmd example, which is rendered on the package site
1 parent b6d19e9 commit 4692835

File tree

10 files changed

+736
-378
lines changed

10 files changed

+736
-378
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
tests: tests/tests.Rout.save
2-
3-
tests/tests.Rout.save: tests/tests.R inst/examples/render-options.R
1+
all:
42
ln -f ../lite.js/js/snap.js ../lite.js/css/snap.css ../lite.js/css/default.css inst/resources/
53
Rscript -e "Rd2roxygen::rab('.', install=TRUE)"
64
rm litedown_*.tar.gz
7-
cd tests && R CMD BATCH --no-save --no-restore --no-timing tests.R tests.Rout.save
5+
cd examples && Rscript _run.R

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
- Fixed a bug that inline code expressions (`` `{lang} expr` ``) cannot be correctly located when the line has leading spaces that are not meaningful.
88

9+
- Deleted vignettes `markdown-examples` and `markdown-output`. They are rendered on the package site now: https://git.yihui.org/litedown/examples/test-options.html
10+
911
# CHANGES IN litedown VERSION 0.6
1012

1113
- Added a Markdown rendering option `offline` to download web resources when this option is set to true, so that the HTML output can be viewed offline (thanks, @TimTaylor, #73). See https://yihui.org/litedown/#sec:offline for more info.

R/mark.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
416416
# for RStudio to capture the output path when previewing the output
417417
if (is_rmd_preview()) message('\nOutput created: ', output)
418418
if (is_pdf) invisible(output) else write_utf8(ret, output)
419-
} else raw_string(ret, lang = format)
419+
} else raw_string(ret, lang = paste0('.', format))
420420
}
421421

422422
# insert body and meta variables into a template
@@ -470,8 +470,6 @@ yaml_text = function(part, text) if (length(l <- part$lines) == 2) text[l[1]:l[2
470470
#' @examples
471471
#' # all available options
472472
#' litedown::markdown_options()
473-
#'
474-
#' @example inst/examples/render-options.R
475473
markdown_options = function() {
476474
# options enabled by default
477475
x1 = c(
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,72 @@
1+
## Test Markdown options
2+
3+
```{r, test-a}
14
library(litedown)
25
36
# toc example
4-
mkd <- c("# Header 1", "p1", "## Header 2", "p2")
7+
mkd <- c('# Header 1', 'p1', '## Header 2', 'p2')
58
6-
mark(mkd, options = "+number_sections")
7-
mark(mkd, options = "+number_sections+toc")
9+
mark(mkd, options = '+number_sections')
10+
mark(mkd, options = '+number_sections+toc')
811
912
# hard_wrap example
10-
mark("foo\nbar\n")
11-
mark("foo\nbar\n", options = "+hardbreaks")
13+
mark('foo\nbar\n')
14+
mark('foo\nbar\n', options = '+hardbreaks')
1215
1316
# latex math example
1417
mkd <- c(
15-
"`$x$` is inline math $x$!", "", "Display style:", "", "$$x + y$$", "",
16-
"\\begin{align}
18+
'`$x$` is inline math $x$!', '', 'Display style:', '', '$$x + y$$', '',
19+
'\\begin{align}
1720
a^{2}+b^{2} & = c^{2}\\\\
1821
\\sin^{2}(x)+\\cos^{2}(x) & = 1
19-
\\end{align}"
22+
\\end{align}'
2023
)
2124
2225
mark(mkd)
23-
mark(mkd, options = "-latex_math")
26+
mark(mkd, options = '-latex_math')
2427
2528
# table example
26-
mark("
29+
mark('
2730
First Header | Second Header
2831
------------- | -------------
2932
Content Cell | Content Cell
3033
Content Cell | Content Cell
31-
")
34+
')
3235
3336
# caption
34-
mark("
37+
mark('
3538
| a | b |
3639
|---|--:|
3740
| A | 9 |
3841
3942
Table: A table _caption_.
40-
")
43+
')
4144
4245
# no table
43-
mark("
46+
mark('
4447
First Header | Second Header
4548
------------- | -------------
4649
Content Cell | Content Cell
4750
Content Cell | Content Cell
48-
", options = '-table')
51+
', options = '-table')
4952
5053
# autolink example
51-
mark("https://www.r-project.org/")
52-
mark("https://www.r-project.org/", options = "-autolink")
54+
mark('https://www.r-project.org/')
55+
mark('https://www.r-project.org/', options = '-autolink')
5356
5457
# links and spans
5558
mark('[a b](#){.red}')
5659
mark('[a\nb](){.red}')
5760
5861
# strikethrough example
59-
mark("~~awesome~~")
60-
mark("~~awesome~~", options = "-strikethrough")
62+
mark('~~awesome~~')
63+
mark('~~awesome~~', options = '-strikethrough')
6164
6265
# superscript and subscript examples
63-
mark("2^10.5^")
64-
mark("2^10.5^", options = "-superscript")
65-
mark("H~2~O")
66-
mark("H~2~O", options = "-subscript")
67-
mark("X~i,j~")
66+
mark('2^10^')
67+
mark('2^10^', options = '-superscript')
68+
mark('H~2~O')
69+
mark('H~2~O', options = '-subscript')
6870
6971
# code blocks
7072
mark('```r\n1 + 1;\n```')
@@ -82,8 +84,22 @@ mark('```{=latex}\n\\textbf{raw LaTeX}\n```')
8284
mark('::: foo\nasdf\n:::')
8385
mark('::: {.foo .bar #baz style="color: red;"}\nasdf\n:::')
8486
87+
# smartypants example
88+
mark('1/2 (c)')
89+
mark('1/2 (c)', options = '+smartypants')
90+
91+
mkd <- paste(names(litedown:::pants), collapse = ' ')
92+
mark(mkd, options = '+smartypants')
93+
8594
# filter out HTML tags
8695
mkd = '<style>a {}</style><script type="text/javascript">console.log("No!");</script>\n[Hello](#)'
8796
mark(mkd)
8897
# tagfiler doesn't work: https://github.com/r-lib/commonmark/issues/15
89-
# mark(mkd, options = "tagfilter")
98+
# mark(mkd, options = 'tagfilter')
99+
```
100+
101+
## The HTML output of above examples
102+
103+
```{r, test-b, results = 'asis'}
104+
`<test-a>`
105+
```

0 commit comments

Comments
 (0)