Skip to content

Instantly share code, notes, and snippets.

@atusy
Last active March 7, 2020 08:24
Show Gist options
  • Save atusy/f2b5b992e45c68ab6823499f2339c6e6 to your computer and use it in GitHub Desktop.
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
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
---
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