Tech With Galvan
Back to Articles
DevelopmentOct 18, 2026 • 6 min read

Build a Notion-Style Markdown Editor in Streamlit

Build a Notion-like markdown editor in Streamlit — live preview, slash commands, block-based editing, and persistent storage with Supabase.

Galvan
Galvan

Founder & Creator

Introduction

Notion’s block-based editor is beloved — but it’s closed-source and SaaS. What if you could build a Notion-style markdown editor in Python with Streamlit? Live preview, slash commands, and persistent storage — in under 100 lines.

This post builds one. It’s a great internal-tool project and a fun weekend build.

What we’re building

  • Split-pane editor: markdown on the left, live preview on the right
  • Slash commands (/heading, /todo, /code) that insert templates
  • Block-based rendering with st.markdown
  • Persistent storage via Supabase (or local JSON for prototyping)
  • Export to .md file

Setup

pip install streamlit supabase

Step 1: Basic split-pane editor

import streamlit as st

st.set_page_config(page_title="Markdown Editor", layout="wide")

col1, col2 = st.columns(2)

with col1:
    st.subheader("Editor")
    content = st.text_area("Write markdown...", height=600, key="editor")

with col2:
    st.subheader("Preview")
    st.markdown(content)

That’s a working editor in 8 lines. The preview updates live as you type.

Step 2: Slash commands

SLASH_COMMANDS = {
    "/h1": "# Heading 1\n",
    "/h2": "## Heading 2\n",
    "/h3": "### Heading 3\n",
    "/todo": "- [ ] Task\n",
    "/code": "```\n# your code here\n```\n",
    "/quote": "> Quote text\n",
    "/divider": "---\n",
    "/table": "| Col1 | Col2 |\n|------|------|\n| A    | B    |\n",
    "/image": "![alt](url)\n",
    "/link": "[text](url)\n",
}

def handle_slash(text):
    for cmd, template in SLASH_COMMANDS.items():
        if text.strip() == cmd:
            return template
    return None

Wire it into the editor:

# Check for slash command on submit
if content.strip() in SLASH_COMMANDS:
    st.session_state.editor = SLASH_COMMANDS[content.strip()]
    st.rerun()

Or use a selectbox for discoverability:

cmd = st.selectbox("Insert block", [""] + list(SLASH_COMMANDS.keys()))
if cmd:
    st.session_state.editor = st.session_state.get("editor", "") + SLASH_COMMANDS[cmd]
    st.rerun()

Step 3: Block-based rendering

Instead of one big text area, render blocks individually:

if "blocks" not in st.session_state:
    st.session_state.blocks = [{"type": "text", "content": ""}]

for i, block in enumerate(st.session_state.blocks):
    if block["type"] == "text":
        new = st.text_area(f"Block {i}", value=block["content"], key=f"block-{i}")
        st.session_state.blocks[i]["content"] = new
    elif block["type"] == "code":
        new = st.text_area(f"Code {i}", value=block["content"], key=f"code-{i}")
        st.code(new, language="python")
    elif block["type"] == "todo":
        checked = st.checkbox(block["content"], value=block.get("done", False), key=f"todo-{i}")
        st.session_state.blocks[i]["done"] = checked

Each block is independently editable and rendered. This is closer to Notion’s model.

Step 4: Add block controls

col1, col2, col3 = st.columns(3)
if col1.button("➕ Add text block"):
    st.session_state.blocks.append({"type": "text", "content": ""})
    st.rerun()
if col2.button("➕ Add code block"):
    st.session_state.blocks.append({"type": "code", "content": ""})
    st.rerun()
if col3.button("➕ Add todo"):
    st.session_state.blocks.append({"type": "todo", "content": "New task"})
    st.rerun()

Step 5: Render the full document

st.divider()
st.subheader("Full preview")
full_md = "\n\n".join(b["content"] for b in st.session_state.blocks if b["content"])
st.markdown(full_md)

Step 6: Persistent storage with Supabase

from supabase import create_client

supabase = create_client(st.secrets["SUPABASE_URL"], st.secrets["SUPABASE_KEY"])

def save_doc(title, content):
    supabase.table("docs").upsert({"title": title, "content": content}).execute()

def load_doc(title):
    res = supabase.table("docs").select("content").eq("title", title).execute()
    return res.data[0]["content"] if res.data else ""

# UI
docs = supabase.table("docs").select("title").execute().data
titles = [d["title"] for d in docs]
selected = st.selectbox("Open document", ["New"] + titles)

if selected != "New":
    content = load_doc(selected)
    st.session_state.editor = content

Step 7: Export to .md

full_content = "\n\n".join(b["content"] for b in st.session_state.blocks if b["content"])
st.download_button(
    "📥 Export as Markdown",
    data=full_content.encode("utf-8"),
    file_name="document.md",
    mime="text/markdown",
)

Step 8: Keyboard shortcuts (via JS)

st.markdown("""
<script>
document.addEventListener('keydown', function(e) {
    if (e.ctrlKey && e.key === 's') {
        e.preventDefault();
        // trigger save
        document.querySelector('button[kind="primary"]').click();
    }
});
</script>
""", unsafe_allow_html=True)

Ctrl+S to save. Hacky but works for internal tools.

Common mistakes

  • No persistence — in-memory state resets on refresh. Use Supabase or a file.
  • Giant text areas — split into blocks for better UX.
  • No export — always offer a download button.
  • Ignoring mobile — split-pane doesn’t work on phones. Use tabs on small screens.
  • Over-engineering — start with the simple split-pane; add blocks only if needed.

Key Concepts

  • Split-pane editor = textarea + live markdown preview
  • Slash commands = quick block insertion
  • Block-based = independent editable units
  • Supabase = persistent storage
  • Export = download as .md

What to Try Next

  • Add collaborative editing with Supabase real-time.
  • Add version history (save snapshots, restore).
  • Add search across documents with full-text search.
  • Combine with auth for per-user docs.
  • Style with theming for a Notion-like look.

FAQ

Streamlit editor vs a real Notion clone?

Streamlit’s editor is functional but lacks Notion’s polish (drag-and-drop blocks, nested pages, rich embeds). For internal tools and personal use, it’s great. For a product, build with React + a real editor (TipTap, Slate).

Can I use a WYSIWYG editor instead of markdown?

Yes — use streamlit-quill or embed a JS editor via components.html. But markdown is simpler and version-control friendly.

How do I handle images in markdown?

Upload to Supabase Storage, get a public URL, insert as ![alt](url). Or use base64 (bloats the doc). Prefer storage URLs.