Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interpolation: Pass-through IOContext to JuliaValue in HTML render #58

Merged
merged 4 commits into from
Jan 17, 2023

Conversation

fonsp
Copy link
Contributor

@fonsp fonsp commented Dec 22, 2022

Hey Michael 👋

This PR makes the rendering IOContext available to interpolated Julia objects. Example of using the IO context in an HTML render:

struct MyType
end

function Base.show(io::IO, m::MIME"text/html", x::MyType)
	if get(io, :limit, false) === true
		write(io, "hello")
	else
		write(io, "<marquee> hello hello hello </marquee>")
	end
end

This PR will fix fonsp/Pluto.jl#1807 , because Pluto and /~https://github.com/JuliaPluto/AbstractPlutoDingetjes.jl use IOContext to communicate which Pluto API is available to the renderer.

This PR is similar to JuliaPluto/HypertextLiteral.jl#27

Example notebook that works after this PR:

# ╔═╡ 618a92b2-a418-40c6-8d71-2129b056aa5c
begin
	import Pkg
	Pkg.activate(temp=true)
	Pkg.add([
		Pkg.PackageSpec(name="PlutoUI")
		Pkg.PackageSpec(url="/~https://github.com/fonsp/CommonMark.jl", rev="patch-3")
	])
end

# ╔═╡ 97d567f2-8203-11ed-1857-bdfd226ad0b7
using CommonMark

# ╔═╡ d9207c56-d2b9-48bb-b803-b94a0b685daa
using PlutoUI

# ╔═╡ 8ae91af4-8651-4bc3-bd42-98909c6ee5a7
@bind a Slider(5:9)

# ╔═╡ d4fd82c7-7eaa-4c2c-9c37-5a54986b4b49
a

# ╔═╡ 93c0ba03-ff14-492c-95f7-b454afb4fb47
bb = cm"$(@bind b Slider(5:9))"

# ╔═╡ 4331aad6-b709-464e-8ec8-0b2cea99484e
b

Copy link
Owner

@MichaelHatherly MichaelHatherly left a comment

Choose a reason for hiding this comment

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

Thanks @fonsp, happy new year 🥳

You reckon adding a test to ensure this doesn't break later is easily doable?

@fonsp fonsp requested a review from MichaelHatherly January 17, 2023 11:59
@MichaelHatherly MichaelHatherly merged commit 33e8d70 into MichaelHatherly:master Jan 17, 2023
@MichaelHatherly
Copy link
Owner

Thanks @fonsp. Will release a new version shortly containing this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slider fails if in CommonMark string
2 participants