Implementing a ProseMirror Remark plugin - How to work with non-unist, non-string inputs? #254
-
Howdy! I do a lot of work with ProseMirror, a rich text editing library. Recently I've been working with some folks that are interested in serializing ProseMirror documents to Markdown, and I love the unified/remark stack for working with Markdown. I started by working out a basic remark plugin that converts mdast to a ProseMirror node tree (you can see that here: https://github.com/handlewithcarecollective/remark-prosemirror). I used the declare module "unified" {
interface CompileResultMap {
PmNode: PmNode;
}
} Which is awesome, I really appreciate how extensible this is. Now I'm trying to go in the opposite direction, from ProseMirror nodes to mdast/Markdown, and I'm not sure what the correct way to model that is. What I want to be able to do is just the inverse operation: tell unified to start with a ProseMirror node and output a markdown vFile. This doesn't really seem to align with unified's processing model, though. ProseMirror nodes have already been "parsed" from the DOM, so It seems like the move here is to produce a unist-compatible ProseMirror syntax-tree, convert the ProseMirror doc to that tree, and then Does that seem right? Or am I missing something about how to handle situations like this? It seems like comparable plugins like rehype-react are essentially one way; they don't have a way to get from the CompileResult back to on AST. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
Unified has several different approaches to being used.
Exactly
I'd recommend using |
Beta Was this translation helpful? Give feedback.
Unified has several different approaches to being used.
You appear to be referring mostly to the programmatic Node/JS API.
The string requirement comes in because it also has a CLI that expects to be able to read a file.
https://unifiedjs.com/learn/
Exactly
I'd recommend creating an mdast util, there may be some inspiration to draw from a now deprecated quill connector https://github.com/syntax-tree/md…