Skip to content

Commit 1fc13cc

Browse files
authored
Merge pull request #29 from MichaelHatherly/mh/iocontext
Use `show` instead of `repr`.
2 parents c780f6d + c59f46b commit 1fc13cc

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.jl.*.cov
33
*.jl.mem
44
.DS_Store
5+
/Manifest.toml

Project.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ uuid = "47d2ed2b-36de-50cf-bf87-49c2cf4b8b91"
33
author = ["Yuri Vishnevsky <[email protected]>"]
44
version = "0.0.4"
55

6-
[compat]
7-
julia = "1"
8-
96
[deps]
107
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
8+
9+
[compat]
10+
julia = "1"

src/Hyperscript.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ renderdomchild(io, rctx::RenderContext, ctx, x::Nothing) = nothing
238238
# Render and escape other HTMLSVG children, including CSS nodes, in the parent context.
239239
# If a child is `showable` with text/html, render with that using `repr`.
240240
renderdomchild(io, rctx::RenderContext, ctx, x) =
241-
showable(MIME("text/html"), x) ? print(io, repr(MIME("text/html"), x)) : printescaped(io, x, escapechild(ctx))
241+
showable(MIME("text/html"), x) ? show(io, MIME("text/html"), x) : printescaped(io, x, escapechild(ctx))
242242

243243
# All camelCase attribute names from HTML 4, HTML 5, SVG 1.1, SVG Tiny 1.2, and SVG 2
244244
const HTML_SVG_CAMELS = Dict(lowercase(x) => x for x in [

test/runtests.jl

+15
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,18 @@ import Hyperscript: px, em
278278
@test string(5 * (1px + 2em)) == "calc(5 * (1px + 2em))"
279279
@test string(5 * (1px + 3px + 4.3em)) == "calc(5 * (4px + 4.3em))"
280280
@test string(3.2 * (4.3em + 1px + 3px)) == "calc(3.2 * ((4.3em + 1px) + 3px))"
281+
282+
# IOContext passthrough.
283+
struct MyType
284+
end
285+
Base.show(io::IO, ::MIME"text/html", ::MyType) = print(io, get(io, :key, ""))
286+
287+
let
288+
io = IOBuffer()
289+
show(io, MIME("text/html"), m("div")(MyType()))
290+
@test String(take!(io)) == "<div></div>"
291+
292+
ctx = IOContext(io, :key => "value")
293+
show(ctx, MIME("text/html"), m("div")(MyType()))
294+
@test String(take!(io)) == "<div>value</div>"
295+
end

0 commit comments

Comments
 (0)