Public
Edited
Jun 12, 2023
Paused
1 fork
Importers
5 stars
Insert cell
Insert cell
instructions = md`---
## How to add instructions
### 1. Import the function
### 2. Write your instructions
### 3. Call the function`
Insert cell
Insert cell
Insert cell
toc = instructions => {
const tocWidth = 200;
const paragraphWidth = 640;
if (width < paragraphWidth + tocWidth) return "";
const instructionsTitle = instructions.querySelector("h2").innerText;
const headers = Array.from(document.querySelectorAll("h2, h3")).map(d => [d.tagName, d.innerText])
const start = headers.indexOf(headers.find(d => d[1] === instructionsTitle))
const end = headers.indexOf(headers.find((d, i) => d[0] === "H2" && i > start))
const subheds = headers.slice(start + 1, end !== -1 ? end : undefined)
return htl.html`<div style=${{
width: `${tocWidth}px`,
float: "right",
fontFamily: "var(--sans-serif)",
fontSize: "12px",
marginTop: "12px",
zIndex: 1,
position: "relative",
}}>
<strong>${instructionsTitle}</strong>
${subheds.map(d => htl.html`<div>${d[1]}</div>`)}
<div><a href="#instructions">details…</a></div>
</div>`
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more