add copy button to code blocks
This commit is contained in:
parent
c6f47db8ba
commit
cdcf69db60
5 changed files with 122 additions and 17 deletions
|
|
@ -1,26 +1,40 @@
|
|||
#import "./custom_html.typ": code-block
|
||||
#import "./figures.typ": show-rule-figure
|
||||
#import "./code.typ": show-rule-code-block
|
||||
|
||||
#let css-list = state("css-list", ())
|
||||
#let js-list = state("js-list", ())
|
||||
|
||||
/// Add string `css` to `css-list` if not already present
|
||||
#let add-css(css) = context {
|
||||
css-list.update(x => if css in x { x } else { x + (css,) })
|
||||
}
|
||||
|
||||
/// Add string `js` to `js-list` if not already present
|
||||
#let add-js(js) = context {
|
||||
js-list.update(x => if js in x { x } else { x + (js,) })
|
||||
}
|
||||
|
||||
/// Concatenate all css found in css-list at the end of the document
|
||||
#let get-css() = context {
|
||||
css-list.final().join("\n\n")
|
||||
}
|
||||
|
||||
/// Concatenate all js found in js-list at the end of the document
|
||||
#let get-js() = context {
|
||||
js-list.final().join("\n\n")
|
||||
}
|
||||
|
||||
#let html_show(body) = {
|
||||
show raw: it => {
|
||||
if it.lang == "raw-css" {
|
||||
// remove code and add it to css style
|
||||
add-css(it.text)
|
||||
} else if it.lang == "raw-js" {
|
||||
// remove code and add it to css style
|
||||
add-js(it.text)
|
||||
} else if it.block {
|
||||
// wrap <pre><code> inside a <code-block>
|
||||
code-block(it)
|
||||
show-rule-code-block(it)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue