Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Add marimo-snippets to the docs (#4239)

vincent d warmerdam6a13b395566e
diff --git a/docs/guides/publishing/index.md b/docs/guides/publishing/index.md
index 279eb896fa..fa96f0d70a 100644
--- a/docs/guides/publishing/index.md
+++ b/docs/guides/publishing/index.md
@@ -13,6 +13,7 @@ This guide provides an overview of the various ways to publish marimo notebooks.
| Guide | Description |
| ----------------------------------------------------- | ------------------------------------------------------------ |
| [Embedding](embedding.md) | An overview of embedding notebooks in other sites |
+| [Markdown Snippets](marimo-snippets.md) | Use the `marimo-snippets` plugin to host marimo |
| [From GitHub](from_github.md) | How to share links to executable notebooks hosted on GitHUb |
| [GitHub Pages](github_pages.md) | Publishing interactive notebooks on GitHub Pages |
| [Cloudflare Pages](cloudflare_pages.md) | Publishing interactive notebooks on Cloudflare Pages |
diff --git a/docs/guides/publishing/marimo-snippets.md b/docs/guides/publishing/marimo-snippets.md
new file mode 100644
index 0000000000..3f6456718d
--- /dev/null
+++ b/docs/guides/publishing/marimo-snippets.md
@@ -0,0 +1,74 @@
+# Publish using `marimo-snippets`
+
+You can host marimo entire notebooks directly by exporting them to WASM but thanks to the `marimo-snippets` library you can also choose to embed a marimo notebook on your site via markdown blocks.
+
+Here's a quick demo on how you might set that up.
+
+````md
+<div>
+<marimo-iframe>
+```python
+import marimo as mo
+```
+```python
+slider = mo.ui.slider(1, 10)
+slider
+```
+
+```python
+slider.value * "🍃"
+```
+</marimo-iframe>
+</div>
+
+<script src="https://cdn.jsdelivr.net/npm/@marimo-team/marimo-snippets@1"></script>
+````
+
+!!! note
+
+ You might wonder why we wrap the `<marimo-button>` element with an extra `<div>`. This is related to how different markdown preprocessors might handle the custom HTML elements. To guarantee that this approach works across most markdown tools, we need to wrap the custom elements in a block element.
+
+This will embed an iframe on your behalf with an interactive slider.
+
+<div>
+<marimo-iframe>
+```python
+import marimo as mo
+```
+```python
+slider = mo.ui.slider(1, 10)
+slider
+```
+
+```python
+slider.value * "🍃"
+```
+</marimo-iframe>
+</div>
+
+<script src="https://cdn.jsdelivr.net/npm/@marimo-team/marimo-snippets@1"></script>
+
+## Configuration
+
+To configure the rendering behavior globally, you can include script elements *before* the marimo snippets script.
+
+```html
+<!-- Optionally configure how buttons and iframes are rendered. -->
+<!-- Configuration must come _before_ the main extractor script is loaded. -->
+<script type="text/x-marimo-snippets-config">
+configureMarimoButtons({title: "Open in a marimo notebook"});
+configureMarimoIframes({height: "400px"});
+</script>
+
+<script src="https://cdn.jsdelivr.net/npm/@marimo-team/marimo-snippets@1"></script>
+```
+
+You can also configure data attributes per-element.
+
+```html
+<marimo-iframe data-height="600px" data-show-code="false">
+...
+</marimo-iframe>
+```
+
+Check the [Github repository](https://github.com/marimo-team/marimo-snippets) to learn more about [the configuration options](https://github.com/marimo-team/marimo-snippets?tab=readme-ov-file#configuration).
\ No newline at end of file
diff --git a/mkdocs.yml b/mkdocs.yml
index d8c8f0ac89..67698ebe7e 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -110,6 +110,7 @@ nav:
- Publish to the web:
- Publish to the web: guides/publishing/index.md
- Embedding: guides/publishing/embedding.md
+ - Marimo Snippets: guides/publishing/marimo-snippets.md
- From GitHub: guides/publishing/from_github.md
- GitHub Pages: guides/publishing/github_pages.md
- Cloudflare Pages: guides/publishing/cloudflare_pages.md