r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

downlit_md_path() should only modify R CodeBlocks #75

Open maelle opened 3 years ago

maelle commented 3 years ago

At least I didn't expect the YAML chunk below to be modified?

just_yaml <- c("```yaml", "layout: single", "```")
tmp <- tempfile()
file.create(tmp)
#> [1] TRUE
tmp2 <- tempfile()
file.create(tmp2)
#> [1] TRUE
writeLines(just_yaml, tmp)
downlit::downlit_md_path(tmp, tmp2)
readLines(tmp2)
#> [1] "<pre class='chroma'>"                                                                 
#> [2] "<span class='nv'>layout</span><span class='o'>:</span> <span class='nv'>single</span>"
#> [3] "</pre>"

Created on 2021-01-04 by the reprex package (v0.3.0.9001)

hadley commented 3 years ago

Re-opening — this is fiddly because the CodeBlock AST differs between versions. Probably no point in tackling this until the pandoc package is available.