Skip to content

Instantly share code, notes, and snippets.

@Lirimy
Last active August 27, 2020 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lirimy/2962c626941361f8b789fe3f669b5b15 to your computer and use it in GitHub Desktop.
Save Lirimy/2962c626941361f8b789fe3f669b5b15 to your computer and use it in GitHub Desktop.
Julia Browser Output Sample
# Browser Output Sample
#
# Copyright (c) 2020 Lirimy
# Released under the MIT license
# https://opensource.org/licenses/MIT
#
# Reference
# https://github.com/GiovineItalia/Gadfly.jl
##
using DefaultApplication
## Object Representation
struct Hoge end
function Base.show(io::IO, ::MIME"text/html", ::Hoge)
html = """
<!DOCTYPE html>
<html>
<head>
<title>Julia Output</title>
</head>
<body>
Hello, <strong>Julia</strong> !!!
</body>
</html>
"""
write(io, html)
flush(io)
end
x = Hoge()
## Original Display
struct MyDisplay <: AbstractDisplay end
pushdisplay(MyDisplay())
## Display Implimentation
function Base.display(d::MyDisplay, @nospecialize x)
if showable(MIME("text/html"), x)
display(d, MIME("text/html"), x)
else
throw(MethodError(Base.display, (d, x)))
end
end
function Base.display(::MyDisplay, mime::MIME"text/html", @nospecialize x)
filename = tempname() * ".html"
open(filename, "w") do f
show(f, mime, x)
end
DefaultApplication.open(filename; wait=true)
nothing
end
##
display(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment