Skip to content

Commit

Permalink
preserve trailing \n in source code by doubling it, because later we …
Browse files Browse the repository at this point in the history
…will remove trailing \n in fenced_block()

one example is here: https://github.com/PRQL/prqlc-r/blob/d3606f09b4efda020967c2b8518ea90a830a63e0/R/knitr-engine.R#L51 sql_code contains a trailing \n, but prql_code doesn't, so

```
sql_code
```

will generate

```
prql_code```

after substitution, which is wrong Markdown output
  • Loading branch information
yihui committed Apr 4, 2024
1 parent 346e2ec commit 4ce8111
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion R/hooks-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ hooks_markdown = function(strict = FALSE, fence_char = '`') {
list(
source = function(x, options) {
x = hilight_source(x, 'markdown', options)
if (strict) hook.t(x) else hook.r(x, options)
if (strict) hook.t(x) else hook.r(sub('\n$', '\n\n', x), options)
},
inline = function(x) {
if (is_latex_output()) .inline.hook.tex(x) else {
Expand Down

0 comments on commit 4ce8111

Please sign in to comment.