Skip to content

Commit

Permalink
🖱 Right click to save SVG
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Aug 4, 2020
1 parent 51164c5 commit 9128ead
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>", "MikoÅ‚aj Bochenski <[email protected]>"]
version = "0.11.2"
version = "0.11.3"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/Cell.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const empty_cell_data = (cell_id) => {
local_code: {
body: "",
},
code_folded: true,
code_folded: false,
running: true,
runtime: null,
errored: false,
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/CellInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const CellInput = ({
// if the CodeMirror initialized/changed while it was hidden, and it suddely became unhidden, we need to refresh it to fix a layout bug where the gutter takes no horizontal space.
useLayoutEffect(() => {
if (!is_hidden) {
cm_ref.current.refresh()
cm_ref.current && cm_ref.current.refresh()
}
}, [is_hidden])

Expand Down
2 changes: 1 addition & 1 deletion frontend/components/CellOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ const OutputBody = ({ mime, body, cell_id, all_completed_promise, requests }) =>
case "image/jpg":
case "image/gif":
case "image/bmp":
case "image/svg+xml":
return html`<div><img src=${body} /></div>`
break
case "text/html":
case "image/svg+xml": // TODO: don't run scripts here
case "application/vnd.pluto.tree+xml":
return html`<${RawHTMLContainer} body=${body} all_completed_promise=${all_completed_promise} requests=${requests} />`
break
Expand Down
1 change: 1 addition & 0 deletions frontend/components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export class Editor extends Component {
cells: update.message.cells.map((cell) => {
const cell_data = empty_cell_data(cell.cell_id)
cell_data.running = run_all
cell_data.code_folded = true
return cell_data
}),
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/RunArea.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { html } from "../common/Preact.js"
export const RunArea = ({ runtime, onClick }) => {
return html`
<pluto-runarea>
<span class="runtime">${prettytime(runtime)}</span>
<button onClick=${onClick} class="runcell" title="Run"><span></span></button>
<span class="runtime">${prettytime(runtime)}</span>
</pluto-runarea>
`
}
Expand Down
51 changes: 33 additions & 18 deletions src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,39 @@ function show_richest(io::IO, @nospecialize(x); onlyhtml::Bool=false)::MIME
return MIME"application/vnd.pluto.tree+xml"()
end

if istextmime(mime)
if mime ∈ imagemimes
if mime isa MIME"image/svg+xml"
if onlyhtml
print(io, "<img src=\"data:", mime, ",")
htmlesc(io, repr(mime, x; context=io))
print(io, "\">")
return MIME"text/html"()
else
print(io, "data:", mime, ",")
show(io, mime, x)
return mime
end
else
# svg is a text mime, all other imagy MIMEs are "raw" mimes: show returns a UInt8[]
# so we base64 encode the result

enc_pipe = Base64.Base64EncodePipe(io)
io_64 = IOContext(enc_pipe, iocontext)

if onlyhtml
print(io, "<img src=\"data:", mime, ";base64,")
show(io_64, mime, x)
close(enc_pipe)
print(io, "\">")
return MIME"text/html"()
else
print(io, "data:", mime, ";base64,")
show(io_64, mime, x)
close(enc_pipe)
return mime
end
end
else
if onlyhtml || mime isa MIME"text/latex"
# see onlyhtml description in docstring
if mime isa MIME"text/plain"
Expand All @@ -309,23 +341,6 @@ function show_richest(io::IO, @nospecialize(x); onlyhtml::Bool=false)::MIME
show(io, mime, x)
return mime
end
else
# these are the "raw" MIME types
# they happen to all be imagy MIMEs
enc_pipe = Base64.Base64EncodePipe(io)
io_64 = IOContext(enc_pipe, iocontext)
if onlyhtml
print(io, "<img src=\"data:", mime, ";base64,")
show(io_64, mime, x)
close(enc_pipe)
print(io, "\">")
return MIME"text/html"()
else
print(io, "data:", mime, ";base64,")
show(io_64, mime, x)
close(enc_pipe)
return mime
end
end
end

Expand Down

5 comments on commit 9128ead

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 9128ead Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: Changing package repo URL not allowed, please submit a pull request with the URL change to the target registry and retry.

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 9128ead Aug 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 9128ead Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/19014

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.11.3 -m "<description of version>" 9128eadec331a6d6be76b5d3e20d4b7b9559f882
git push origin v0.11.3

Please sign in to comment.