Last active
March 7, 2020 08:24
-
-
Save atusy/f2b5b992e45c68ab6823499f2339c6e6 to your computer and use it in GitHub Desktop.
Fold code blocks with Pandc Lua Filter originally posted to https://blog.atusy.net/2020/03/07/pandoc-lua-detailed-codeblock/ in Japanese
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CodeBlock(elem) | |
if elem.classes and elem.classes:find("details") then | |
local summary = "Code" | |
if elem.attributes.summary then | |
summary = elem.attributes.summary | |
end | |
return{ | |
pandoc.RawBlock( | |
"html", "<details><summary>" .. summary .. "</summary>" | |
), | |
elem, | |
pandoc.RawBlock("html", "</details>") | |
} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
output: | |
html_document: | |
pandoc_args: [ | |
"--lua-filter", "foldableCodeBlock.lua" | |
] | |
--- | |
```{r, attr.output='.details summary="Output"'} | |
set.seed(1) | |
rnorm(10) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment