Prevent chunk options from ending up in HTML source? #5995
Replies: 4 comments 7 replies
-
Indeed, we only consider known knitr and Quarto options - all other options are passing through and considered attributes on the code block. We would need to have a way to pass information to quarto of what chunk options should be considered as option for knitr only. We'll think about that. I believe for now you could create a Lua filter (https://quarto.org/docs/extensions/filters.html) that would catch your known options and remove them, so that they don't end up in the output. |
Beta Was this translation helpful? Give feedback.
-
Thanks, I'll take a look at that. In the mean time, is there a way I can detect in R whether the knitr hook is being run in a quarto document so I can use stop() (or at least throw a warning()) when the hook is run? |
Beta Was this translation helpful? Give feedback.
-
For other people's reference, this lua filter seems to work: if FORMAT:match 'html' then
function Div (elem)
elem.attributes.mySetting = nil
return elem
end
end Edited to add: it seems the attribute's capitalization has to be like the original, not as it appears in the html output. |
Beta Was this translation helpful? Give feedback.
-
Sure, I've written some knitr hooks that take the output (or source) from a chunk and puts an encrypted div in the HTML document. The knitr hook looks for specific chunk options, the content of which is the key; eg,
would lead to an encrypted div with the plot in it. There's some javascript that gets injected for decrypting it when you input the correct key. This all works fine in Rmarkdown and Quarto, except that in Quarto the divs have the chunk option in them; which means that the key is sitting in the document (obviously not good). In general, because I work with educational material, it is often useful not to have some information about how the document was compiled in the resulting compiled document. Could we, say, do something like the following (note the double pipe) to indicate that the chunk option should not be passed into the rendered document?
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Description
If we have the following
qmd
file:...when I render it and look at the source, I see:
In particular, there is a
div
that has a data attribute (data-mysetting
) equal to my chunk setting (hi there
). There are cases where chunk options might contain information I do not want in the source (but want to be available when usingknitr
hooks, for instance) and I'd like to disable it.How can I prevent information from leaking from the chunk options into the compiled source?
Beta Was this translation helpful? Give feedback.
All reactions