Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions images/marimo-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
117 changes: 117 additions & 0 deletions scripts/export-marimo-cookbook-md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/usr/bin/env bash
# Export marimo cookbooks under weave/cookbooks/source/ to Markdown (.mdx) for
# inclusion in weave/cookbooks/*.mdx via import.
#
# Requires: marimo CLI (pip install marimo)
#
# Usage:
# ./scripts/export-marimo-cookbook-md.sh
# ./scripts/export-marimo-cookbook-md.sh path/to/notebook.py # single file
#
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "${ROOT}"
SOURCE_DIR="${ROOT}/weave/cookbooks/source"
OUT_DIR="${ROOT}/weave/cookbooks/generated"

if ! command -v marimo >/dev/null 2>&1; then
echo "error: marimo not found on PATH. Install with: pip install marimo" >&2
exit 1
fi

process_export() {
local out_path="$1"
python3 - "${out_path}" <<'PY'
import re
import sys
from pathlib import Path

path = Path(sys.argv[1])
text = path.read_text(encoding="utf-8")

# Strip YAML frontmatter (marimo adds title / marimo-version).
lines = text.splitlines(keepends=True)
if lines and lines[0].strip() == "---":
i = 1
while i < len(lines) and lines[i].strip() != "---":
i += 1
if i < len(lines):
text = "".join(lines[i + 1 :])

# Remove Docusaurus meta block if present.
text = re.sub(
r"<!--\s*docusaurus_head_meta::start.*?docusaurus_head_meta::end\s*-->",
"",
text,
flags=re.DOTALL,
)

# MDX treats `{...}` as expressions in some parsers; marimo uses `{.marimo}` on fences.
text = text.replace(" {.marimo}", "")

# Marimo cell markers and HTML comments: `<!---->` / `<!-- ... -->` break MDX parsing.
text = re.sub(r"<!---->\s*", "", text)
text = re.sub(r"<!--.*?-->", "", text, flags=re.DOTALL)

# Self-close img tags (marimo exports </img> which MDX rejects).
text = re.sub(r"<img([^>]+)>\s*</img>", r"<img\1 />", text, flags=re.IGNORECASE)

# Remove boilerplate cells that are only `import marimo as mo` (noise in docs).
text = re.sub(
r"```python\s*\nimport marimo as mo\s*\n```\s*\n",
"",
text,
)
text = text.lstrip("\n")

path.write_text(text, encoding="utf-8")
PY
}

export_one() {
local py_path="$1"
local base
base="$(basename "${py_path}" .py)"
local out_path="${OUT_DIR}/${base}.mdx"
mkdir -p "${OUT_DIR}"
echo "marimo export md: ${py_path} -> ${out_path}"
marimo export md "${py_path}" -o "${out_path}" -f
process_export "${out_path}"
}

if [[ $# -gt 0 ]]; then
for f in "$@"; do
export_one "${f}"
done
exit 0
fi

mkdir -p "${OUT_DIR}"

# Only notebooks that have a matching weave/cookbooks/<name>.mdx page.
shopt -s nullglob
for mdx in "${ROOT}/weave/cookbooks/"*.mdx; do
base="$(basename "${mdx}" .mdx)"
py="${SOURCE_DIR}/${base}.py"
if [[ -f "${py}" ]]; then
export_one "${py}"
else
echo "skip (no source): ${base}.mdx" >&2
fi
done

cat > "${OUT_DIR}/README.md" <<'EOF'
# Generated marimo Markdown

These `.mdx` files are produced by `marimo export md` from notebooks in
`../source/`. Regenerate after editing a notebook:

```bash
./scripts/export-marimo-cookbook-md.sh
```

Do not edit generated files by hand.
EOF

echo "done. Output: ${OUT_DIR}"
79 changes: 79 additions & 0 deletions snippets/button-links.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,85 @@
border-color: rgba(63, 63, 70, 1);
}

/*
* Molab: same neutral surfaces as Colab links; green comes from marimo-icon.svg only.
* Prose styles (e.g. .prose a { line-height: …; min-height: … }) override plain .class on
* anchors. Use .prose a.molab-link so these rules win over .prose a.
*/
.prose a.molab-link,
a.molab-link {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
box-sizing: border-box;
width: fit-content;
min-width: fit-content;
min-height: 0;
max-height: 50px;
padding: 4px 12px;
border-radius: 8px;
border: 1px solid rgba(230, 228, 224, 0.7);
font-size: 15px;
font-weight: 400;
font-family: Inter, "Inter Fallback";
line-height: 1.2;
color: rgb(87, 85, 81);
background-color: rgba(255, 255, 255, 0.5);
text-decoration: none;
cursor: pointer;
transition: background-color 0.2s ease, border-color 0.2s ease;
margin-bottom: 1rem;
}

.prose a.molab-link:hover,
a.molab-link:hover {
background-color: rgba(255, 255, 255, 0.8);
border-color: rgba(230, 228, 224, 1);
}

.dark .prose a.molab-link,
.dark a.molab-link {
color: rgb(214, 211, 209);
background-color: rgba(39, 39, 42, 0.5);
border: 1px solid rgba(63, 63, 70, 0.7);
}

.dark .prose a.molab-link:hover,
.dark a.molab-link:hover {
background-color: rgba(39, 39, 42, 0.8);
border-color: rgba(63, 63, 70, 1);
}

.molab-link__logo {
flex-shrink: 0;
display: block;
width: 16px;
height: 16px;
}

.molab-link__external {
flex-shrink: 0;
display: block;
opacity: 0.85;
}

/* Cookbook molab block: h2 for "Try in marimo" + badge (see MolabLink embed) */
.cookbook-molab-heading {
margin-top: 0;
margin-bottom: 0.5rem;
}

/* "New" badge next to cookbook h2: raised like superscript */
.cookbook-try-badge {
display: inline-block;
vertical-align: super;
margin-left: 0.35rem;
line-height: 0;
position: relative;
top: -0.15em;
}

/* Compact source link for SDK reference docs */
.source-link {
float: right;
Expand Down
Loading
Loading