👀 Reading hidden code
Enter cell code...
Hello!
This is Markdown but supercharged!!
Here is a list, created using simple string interpolation:
- item 1
- item 2
- item 3
Another list, interpolated as HTML:
- item 1
- item 2
- item 3
Hello
Intepolating a plotly plot
It works!
Code block
function f(x::Int64)
"hello $(x)"
end
# we can interpolate into code blocks!
xs = [1:10..., 20]
map(xs) do x
f(x^2)
end
@md("""
# Hello!
This is *Markdown* but **supercharged**!!
<marquee style=$((color="purple", font_family="cursive"))>Inline HTML supported!</marquee>
Here is a list, created using simple string interpolation:
$((
"- item $i\n" for i in 1:3
))
Another list, interpolated as HTML:
<ul>
$((
@htl("<li>item $i</li>") for i in 1:3
))
</ul>

Hello ``world``
```math
\\sqrt{1+1}
```
## Intepolating a plotly plot
It works!
$(plot(1:10, rand(10)))
## Code block
```julia
function f(x::Int64)
"hello \$(x)"
end
# we can interpolate into code blocks!
$(code_snippet)
```
""")
👀 Reading hidden code
Hello
cm"""
Hello ``world``
```math
\sqrt{1+1}
```
"""
👀 Reading hidden code
Hello!
This is Markdown but supercharged!!
@md("""
# Hello!
This is *Markdown* but **supercharged**!!
""")
👀 Reading hidden code
import PlutoUI
👀 Reading hidden code
- item 1
- item 2
- item 3
@md("""
<ul>
$((
@htl("<li>item $i</li>") for i in 1:3
))
</ul>
""")
👀 Reading hidden code
"xs = [1:10..., 20]\nmap(xs) do x\n\tf(x^2)\nend\n"
code_snippet = """
xs = [1:10..., 20]
map(xs) do x
f(x^2)
end
"""
👀 Reading hidden code
plot (generic function with 1 method)
plot(x, y) = @htl("""
<script src="https://cdn.plot.ly/plotly-1.58.0.min.js"></script>
<script>
const container = html`<div style="width: 100%;"></div>`
Plotly.newPlot( container, [{
x: $(x),
y: $(y),
}], {
margin: { t: 0, b:0, l: 0, r:0 } ,
height: 100,
})
return container
</script>
""")
👀 Reading hidden code
How it works
Use HTL to do the string macro magic, and then ask CommonMark.jl to render it. That's it!
👀 Reading hidden code
using HypertextLiteral
👀 Reading hidden code
using CommonMark
👀 Reading hidden code
@md (macro with 1 method)
macro md(expr)
cm_parser = CommonMark.Parser()
enable!(cm_parser, MathRule())
quote
result = @htl($expr)
htl_output = repr(MIME"text/html"(), result)
$(cm_parser)(htl_output)
end
end
👀 Reading hidden code
Stress test
👀 Reading hidden code
Hello$world
@htl("""
Hello\$world
""")
👀 Reading hidden code
Hello$world
@md("""
Hello\$world
""")
👀 Reading hidden code
👀 Reading hidden code
helo *world*
@htl("""
<div>helo *world*</div>
""")
👀 Reading hidden code
helo *world*
@md("""
<div>helo *world*</div>
""")
👀 Reading hidden code
👀 Reading hidden code
"asdf & 1 &"
difficult = "asdf & 1 &"
👀 Reading hidden code
👀 Reading hidden code
hello asdf & 1 &
hello
123
x1
x2
x3
x4
x5
x6
x7
x8
x9
x10
@md("""
hello $(difficult)
hello $(@md("""
123 $([
@md("x$i") for i in 1:10
])
"""))
""")
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
asdf
h1 = @md("""
<h1>asdf</h1>
""")
👀 Reading hidden code
true
showable(MIME"text/html"(), h1)
👀 Reading hidden code
👀 Reading hidden code
Multiple expressions in one cell.
How would you like to fix it?
cm"""
hello $(difficult)
hello $(cm"""
123 $([
cm"x$i" for i in 1:10
])
""")
"""
👀 Reading hidden code
👀 Reading hidden code
Hello *world*
12
@htl("""
Hello *$("world")*
<script>
let x = 1 *2* 3
x += 1 *$(1 + 1)* 3
return html`<code>\${x}</code>`
</script>
""")
👀 Reading hidden code
Hello world
12
@md("""
Hello *$("world")*
<script>
let x = 1 *2* 3
x += 1 *$(1 + 1)* 3
return html`<code>\${x}</code>`
</script>
""")
👀 Reading hidden code
👀 Reading hidden code
You can use <div>
and </div>
to create a div.
cm"""
You can use `<div>` and `</div>` to create a div.
"""
👀 Reading hidden code
You can use <div>
and </div>
to create a div.
@md("""
You can use `<div>` and `</div>` to create a div.
""")
👀 Reading hidden code
You can use <div>
to create a div.
Close it with </div>
!
@md("""
You can use `<div>` to create a div.
Close it with `</div>`!
""")
👀 Reading hidden code
You can use <div style='color: red;'>
to create a red div.
@md("""
You can use `<div style=$((color="red",))>` to create a red div.
""")
👀 Reading hidden code
You can use `
` and `
` to create a div.
@htl("""
You can use `<div>` and `</div>` to create a div.
""")
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code
👀 Reading hidden code