Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/HypertextLiteral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ See also: [`@htl`](@ref), [`HypertextLiteral.@htl_str`](@ref)
"""
module HypertextLiteral

@static if VERSION >= v"1.3"
using Tricks: static_hasmethod
end
using Tricks: compat_hasmethod

export @htl, @htl_str

Expand Down
37 changes: 11 additions & 26 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,36 +86,21 @@ used. Otherwise, the result is printed within a `<span>` tag, using a
serialized as: `<span class="Base-Missing">missing</span>`.
""" content

@static if VERSION >= v"1.3"
function content(x::T) where {T}
if static_hasmethod(show, Tuple{IO, MIME{Symbol("text/html")}, T})
return Render(x)
else
mod = parentmodule(T)
cls = string(nameof(T))
if mod == Core || mod == Base || pathof(mod) !== nothing
cls = join(fullname(mod), "-") * "-" * cls
end
span = """<span class="$cls">"""
return reprint(Bypass(span), x, Bypass("</span>"))
end
end
else
@generated function content(x)
if hasmethod(show, Tuple{IO, MIME{Symbol("text/html")}, x})
return :(Render(x))
else
mod = parentmodule(x)
cls = string(nameof(x))
if mod == Core || mod == Base || pathof(mod) !== nothing
cls = join(fullname(mod), "-") * "-" * cls
end
span = """<span class="$cls">"""
return :(reprint(Bypass($span), x, Bypass("</span>")))
function content(x::T) where {T}
if compat_hasmethod(show, Tuple{IO, MIME{Symbol("text/html")}, T})
return Render(x)
else
mod = parentmodule(T)
cls = string(nameof(T))
if mod == Core || mod == Base || pathof(mod) !== nothing
cls = join(fullname(mod), "-") * "-" * cls
end
span = """<span class="$cls">"""
return reprint(Bypass(span), x, Bypass("</span>"))
end
end


function reprint(xs...)
# generated functions cannot contain a closure
Reprint() do io::IO
Expand Down