Open abielr opened 3 years ago
The .md files generated by knitr are Pandoc markdown, not commonmark markdown. Does it help if you insert this into the middle of your workflow?
pandoc -f markdown -t commonmark <filename>
I've been thinking of converting <!--html_preserve-->
to use raw blocks, but these are different in pandoc ({=html}
) versus commonmark ({raw} html
, apparently?) so I think that might make your problem worse, not better.
Edit: Oh, is {raw} html
a Jupyter/Jupyter Book thing, perhaps?
Using the recommended pandoc
command solves one issue but causes another: while <!--html_preserve-->
gets put on a new line, it also adds a lot of whitespace to the HTML which causes it to change how it is rendered in the browser. For example, something like
<td class="gt_row gt_right">4</td>
becomes
<td class="gt_row gt_right">
4
</td>
However, if in htmltools/R/tags.R::htmlPreserve()
you were to change
sprintf("<!--html_preserve-->%s<!--/html_preserve-->", x)
to
sprintf("<!--html_preserve-->\n%s\n<!--/html_preserve-->", x)
than it appears to work fine with commonmark.
I'm creating
.Rmd
files and translating them to.md
withknitr
, then later combining them with other Markdown files to generate a book using the Jupyter Book project. My understanding is that this tool uses Sphinx to parse Markdown, and that Sphinx in turn relies on the recommonmark package to parse Markdown files. In any case, thehtml_preserve
comments inserted byhtmltools
seem to breakrecommonmark
's parsing, as discussed here. The problem goes away, however, if the HTML comments are on their own line.Raising this issue here as I don't know if the fix should be in
htmltools
or inrecommonmark
. Obviously it would be straightforward to changehtmltools
to have the comments on their own line, but not sure if this would break other downstream things in the R ecosystem.