I’ve been building a Markdown editor component on top of ProseMirror for a while. The first version is now public (MPL-2.0), though it’s still very early, so I thought I’d share it here.
The basic idea is Typora-style editing. You see the formatted document, and the Markdown syntax shows up when your cursor moves into it, then folds away again when you leave.
You can also drag blocks around, Notion-style. I spent a lot of time getting this to behave with nested structure, so when you drag into or out of lists and quotes, the block should land where the drop indicator says it will.
The other thing I cared a lot about is the Markdown itself:
Parsing follows CommonMark closely. Under the hood it uses a modified micromark.
Markdown recognition is always on, not just a one-off input rule. If you have x- text and delete the x, you get a list item, the same thing the Markdown means, not a paragraph that happens to contain - text. This holds even for really complex Markdown.
When you open an existing file, blocks you don’t touch are written back as they were. Blocks you do edit are re-serialized using the syntax they were originally written with (bullet character -/*/+, fence style, leading space, and so on), so the file stays close to what you actually wrote.
It’s very early alpha, and the APIs will change. There are probably still plenty of bugs, and parts of the code haven’t been fully refactored yet. Would love to hear what you think!
Interesting! I’m actually working on the same thing right now but for CodeMirror. What’s the reason why you went with ProseMirror on this instead of something like CodeMirror? Imo it’s a bit more straightforward using the actual Markdown & then render the richtext via decorations on valid markdown ranges instead of doing it the other way around (rendering richtext & turning it back to markdown when the cursor is inside, etc.)
Layout matters a lot to me. I see it as part of the live-preview experience: paragraphs should have proper spacing, and quotes and lists should look like nested boxes. That’s where I don’t think building on a source editor works.
I haven’t tried this in CodeMirror myself, and I don’t know it well enough to say it can’t be done. But the precedents are bad. In Obsidian’s editor and HyperMD, nested blocks that are even a little complex fall apart. My guess is that this kind of editor just wasn’t something CodeMirror was designed for.
The problem is the model. A source editor lays the document out as lines, and all you can tune is the size of characters and rows. A Markdown document is a tree, though. A quote or a list item is a box around its children, but in the source it’s cut into a marker at the start of every line it spans:
Two-space and four-space indentation in a list item mean the same thing and should look the same. But the spaces are characters you can see and type, so you end up stretching and shrinking characters to fake the indent.
A quote is one box with one continuous bar down its left side. In source, the “bar” is a > typed at the start of each line, and Markdown doesn’t require those to line up or even be there:
> a
> b
> c
> a
b
c
Both are a single quote with three lines. A source editor has to draw one straight bar from a > that moves from line to line, or that only exists on the first line.
The space between paragraphs is a margin, but in source it’s a blank line. You can shrink that row, but when the first character is typed on it, the row jumps back to full height.
So Kagami keeps blocks as a ProseMirror tree and draws them as real boxes. Inline text is still edited as Markdown source with the syntax hidden outside the selection, which is the part where your approach is right.
On the CodeMirror point specifically: CM6 does have block-level decorations and replaced widgets that can span multiple lines, which is how some editors render tables or embedded blocks in place. So the line model is less of a hard limit than it was for CM5-era HyperMD — you can draw a real box around a quote range instead of stretching characters to fake indentation. The cost is that you then fight the source model for cursor placement, hit-testing and drag-and-drop, which ProseMirror hands you as nodes. Did drag-and-drop end up being the deciding factor for you?