Last active
August 27, 2020 23:55
-
-
Save Lirimy/2962c626941361f8b789fe3f669b5b15 to your computer and use it in GitHub Desktop.
Julia Browser Output Sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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