Skip to content

Commit c82409c

Browse files
committed
Remove tag wrapping from HTML show method
It's an undocumented extension to Base.show, and can be done by the caller.
1 parent 03211c9 commit c82409c

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/io.jl

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,9 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
432432
print(io, "\">")
433433
end
434434

435-
function Base.show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}; wrap::Symbol=:pre)
435+
function Base.show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}})
436436
htmlescape(str) = replace(str, '&' => "&amp;", '<' => "&lt;", '>' => "&gt;")
437437
buf = IOBuffer() # Avoid potential overhead in repeatadly printing a more complex IO
438-
wrap == :none ||
439-
print(buf, '<', String(wrap), '>')
440438
lastface::Face = getface()
441439
stylestackdepth = 0
442440
for (str, styles) in eachregion(s)
@@ -459,22 +457,11 @@ function Base.show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubStr
459457
htmlstyle(buf, face, lastface)
460458
stylestackdepth += 1
461459
end
462-
if wrap == :p
463-
newpara = false
464-
for para in eachsplit(str, "\n\n")
465-
newpara && print(buf, "</p>\n<p>")
466-
print(buf, htmlescape(para))
467-
newpara = true
468-
end
469-
else
470-
print(buf, htmlescape(str))
471-
end
460+
print(buf, htmlescape(str))
472461
!isnothing(link) && print(buf, "</a>")
473462
lastface = face
474463
end
475464
print(buf, "</span>" ^ stylestackdepth)
476-
wrap == :none ||
477-
print(buf, "</", String(wrap), '>')
478465
write(io, take!(buf))
479466
nothing
480467
end

test/runtests.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -633,15 +633,15 @@ end
633633
to provide a {(underline=(red,curly)):full-fledged} textual {(bg=#4063d8,fg=#adbdf8,inherit=[bold,strikethrough]):styling} \
634634
system, suitable for {inverse:terminal} and graphical displays."
635635
@test sprint(show, MIME("text/html"), fancy_string[1:27]) ==
636-
"<pre>The <span style=\"color: #803d9b;\">`</span><span style=\"color: #25a268;\">StyledStrings</span>\
637-
<span style=\"color: #803d9b;\">`</span> package</pre>"
636+
"The <span style=\"color: #803d9b;\">`</span><span style=\"color: #25a268;\">StyledStrings</span>\
637+
<span style=\"color: #803d9b;\">`</span> package"
638638
@test sprint(show, MIME("text/html"), fancy_string) ==
639-
"<pre>The <span style=\"color: #803d9b;\">`</span><span style=\"color: #25a268;\">StyledStrings</span><span style=\"color: #803d9b;\">\
639+
"The <span style=\"color: #803d9b;\">`</span><span style=\"color: #25a268;\">StyledStrings</span><span style=\"color: #803d9b;\">\
640640
`</span> package <span style=\"font-style: italic;\">builds<span style=\"font-weight: 700;font-style: normal;\"> on top</span></span> \
641641
of the <span style=\"color: #803d9b;\">`</span><span style=\"color: #25a268;\">AnnotatedString</span><span style=\"color: #803d9b;\">\
642642
`</span> <a href=\"https://en.wikipedia.org/wiki/Type_system\">type</a> to provide a <span style=\"text-decoration: #a51c2c wavy underline;\">\
643643
full-fledged</span> textual <span style=\"font-weight: 700;color: #adbdf8;background-color: #4063d8;text-decoration: line-through\">styling</span> \
644-
system, suitable for <span style=\"\">terminal</span> and graphical displays.</pre>"
644+
system, suitable for <span style=\"\">terminal</span> and graphical displays."
645645
end
646646

647647
@testset "Legacy" begin

0 commit comments

Comments
 (0)