diff --git a/docs/.vitepress/theme/custom.css b/docs/.vitepress/theme/custom.css
index 56d88d7854..123ecb9d66 100644
--- a/docs/.vitepress/theme/custom.css
+++ b/docs/.vitepress/theme/custom.css
@@ -31,6 +31,23 @@
z-index: 1;
}
+.vp-doc .plot-figure {
+ margin: 16px 0;
+}
+
+.vp-doc .plot-figure h2,
+.vp-doc .plot-figure h3 {
+ all: unset;
+ display: block;
+}
+
+.vp-doc .plot-figure h2 {
+ line-height: 28px;
+ font-size: 20px;
+ font-weight: 600;
+ letter-spacing: -0.01em;
+}
+
.vp-doc .plot a:hover {
text-decoration: initial;
}
diff --git a/docs/components/PlotRender.js b/docs/components/PlotRender.js
index 07b6acf171..be06c57e9c 100644
--- a/docs/components/PlotRender.js
+++ b/docs/components/PlotRender.js
@@ -212,7 +212,10 @@ export default {
}
if (typeof document !== "undefined") {
const plot = Plot[method](options);
- const replace = (el) => el.firstChild.replaceWith(plot);
+ const replace = (el) => {
+ while (el.lastChild) el.lastChild.remove();
+ el.append(plot);
+ };
return withDirectives(h("span", [toHyperScript(plot)]), [[{mounted: replace, updated: replace}]]);
}
return h("span", [Plot[method]({...options, document: new Document()}).toHyperScript()]);
diff --git a/docs/features/plots.md b/docs/features/plots.md
index 5cf465401d..88b79ff5ac 100644
--- a/docs/features/plots.md
+++ b/docs/features/plots.md
@@ -248,15 +248,19 @@ When using facets, set the *fx* and *fy* scales’ **round** option to false if
## Other options
-If a **caption** is specified, Plot.plot wraps the generated SVG element in an HTML figure element with a figcaption, returning the figure. To specify an HTML caption, the caption can be specified as an HTML element, say using the [`html` tagged template literal](http://github.com/observablehq/htl); otherwise, the specified string represents text that will be escaped as needed.
+By default, [plot](#plot) returns an SVG element; however, if the plot includes a title, subtitle, [legend](./legends.md), or caption, plot wraps the SVG element with an HTML figure element. You can also force Plot to generate a figure element by setting the **figure** option