Skip to content

Commit

Permalink
Make #id URLs work by setting the location.hash again after all cel…
Browse files Browse the repository at this point in the history
…ls are rendered (#2789)
  • Loading branch information
fonsp committed Jan 23, 2024
1 parent 7e99895 commit 2307d84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion frontend/components/Notebook.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PlutoActionsContext } from "../common/PlutoContext.js"
import { html, useContext, useEffect, useMemo, useRef, useState } from "../imports/Preact.js"
import { html, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from "../imports/Preact.js"

import { Cell } from "./Cell.js"
import { nbpkg_fingerprint } from "./PkgStatusMark.js"
Expand Down Expand Up @@ -166,6 +166,20 @@ export const Notebook = ({
),
[notebook?.cell_dependencies]
)

useLayoutEffect(() => {
let oldhash = window.location.hash
if (oldhash.length > 1) {
let go = () => {
window.location.hash = "#"
window.location.hash = oldhash
}
go()
// Scrolling there might trigger some codemirrors to render and change height, so let's do it again.
requestIdleCallback(go)
}
}, [cell_outputs_delayed])

return html`
<pluto-notebook id=${notebook.notebook_id}>
${notebook.cell_order
Expand Down
2 changes: 1 addition & 1 deletion src/runner/PlutoRunner/src/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ function format_output(binding::Base.Docs.Binding; context=default_iocontext)
try
("""
<div class="pluto-docs-binding">
<span>$(binding.var)</span>
<span id="$(binding.var)">$(binding.var)</span>
$(repr(MIME"text/html"(), Base.Docs.doc(binding)))
</div>
""", MIME"text/html"())
Expand Down

0 comments on commit 2307d84

Please sign in to comment.