Skip to content

Instantly share code, notes, and snippets.

@dralletje
Created November 29, 2020 14:52
Show Gist options
  • Save dralletje/42d645974c6311280a9e0cee0d9fcdc0 to your computer and use it in GitHub Desktop.
Save dralletje/42d645974c6311280a9e0cee0d9fcdc0 to your computer and use it in GitHub Desktop.
# ╔═╡ 8dcf6da4-b05c-4cb3-a566-0a03180d3554
function to_expr(x::T) where T <: Union{
AttributeDoubleQuoted,
AttributeSingleQuoted,
AttributeUnquoted,
BeforeAttributeName,
StateData,
}
:($(T)($(to_expr(x.value))))
end
# ╔═╡ a434bbbd-000a-483b-a406-fa3081368dd7
function to_expr(x::AttributeValue)
:($(AttributeValue)($(to_expr(x.name)), $(to_expr(x.value))))
end
# ╔═╡ fa2528e5-7cc2-4cc8-9583-1c11405ed801
function to_expr(x::Union{String,Symbol,Bool,Number})
x
end
# ╔═╡ fccf16f8-2f49-415f-9a54-5e9583206944
function to_expr(x::Expr)
if x.head == :...
to_expr(x.args[1])
else
x
end
end
# ╔═╡ 20bb3eda-b9cd-4a61-aaa1-fe06a40fb4f6
function to_expr(x::InterpolateArray)
quote
$(InterpolateArray)([
$(map(x.arr) do x
esc(to_expr(x))
end...)
])
end
end
# ╔═╡ 50b261ae-1284-11eb-1496-d300a0e1d2a0
macro htl(expr)
if expr isa String
return hypertext([expr])
end
@assert expr.head == :string
segments_escaped = map(expr.args) do segment
if segment isa String
segment
else
Escaped(segment)
end
end
result = hypertext(segments_escaped)
return to_expr(result)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment