render missing nodes #123

Closed
BrianHung wants to merge 2 commits from render-missing-nodes into master
BrianHung commented 2024-05-18 09:59:44 +02:00 (Migrated from github.com)

I have some custom nodes that don't have a good markdown equivalent.

Instead of throwing an error that node is unsupported, I think for good defaults we can have

  • leaf: no-op
  • inlineContent: renderInline as if it's a paragraph
  • else: renderContent
I have some custom nodes that don't have a good markdown equivalent. Instead of throwing an error that node is unsupported, I think for good defaults we can have - leaf: no-op - inlineContent: renderInline as if it's a paragraph - else: renderContent
marijnh commented 2024-05-18 10:38:20 +02:00 (Migrated from github.com)

What is the reasoning against defining serializers for these nodes? Silently dropping content by default doesn't seem like the best behavior.

What is the reasoning against defining serializers for these nodes? Silently dropping content by default doesn't seem like the best behavior.
BrianHung commented 2024-05-18 11:30:20 +02:00 (Migrated from github.com)

The serializers for nodes which don't have a good markdown equivalent would just be empty string, or plain text equivalent to a paragraph. I would like a single way to handle all of these type of nodes without having to manually add a no-op to MarkdownSerializer each time I update my schema.

Silently dropping content by default doesn't seem like the best behavior.

What about a renderMissingNode option that defaults to throwing an error to be backwards compatible? Set of nodes serializable to markdown is practically static, and defaultMarkdownSerializer with a way to customize default behavior for missing nodes would work for me.

The serializers for nodes which don't have a good markdown equivalent would just be empty string, or plain text equivalent to a paragraph. I would like a single way to handle all of these type of nodes without having to manually add a no-op to `MarkdownSerializer` each time I update my schema. > Silently dropping content by default doesn't seem like the best behavior. What about a `renderMissingNode` option that defaults to throwing an error to be backwards compatible? Set of nodes serializable to markdown is practically static, and `defaultMarkdownSerializer` with a way to customize default behavior for missing nodes would work for me.
BrianHung commented 2024-05-18 11:51:11 +02:00 (Migrated from github.com)

prosemirror-markdown is pretty self-contained; I could extend MarkdownSerializer and MarkdownSerializerState easily to support this behavior internally.

The serializers for nodes which don't have a good markdown equivalent would just be empty string, or plain text equivalent to a paragraph.

HTML is also a possible output.. I can see toDOM() being an alternative other people would use; not sure how MarkdownIt handles that though. Ideally, parser(serializer(doc)).eq(doc).

`prosemirror-markdown` is pretty self-contained; I could extend `MarkdownSerializer` and `MarkdownSerializerState` easily to support this behavior internally. > The serializers for nodes which don't have a good markdown equivalent would just be empty string, or plain text equivalent to a paragraph. HTML is also a possible output.. I can see `toDOM()` being an alternative other people would use; not sure how `MarkdownIt` handles that though. Ideally, `parser(serializer(doc)).eq(doc)`.
marijnh commented 2024-05-20 16:03:44 +02:00 (Migrated from github.com)

Would adding defaultNodeRenderer and defaultMarkRenderer options, and exporting 'blank' render functions that do what your proposed fallback does here so that people can plug them in, work for you?

Would adding `defaultNodeRenderer` and `defaultMarkRenderer` options, and exporting 'blank' render functions that do what your proposed fallback does here so that people can plug them in, work for you?
BrianHung commented 2024-05-20 19:21:09 +02:00 (Migrated from github.com)

Yep that would work!

Yep that would work!
marijnh commented 2024-05-20 19:43:36 +02:00 (Migrated from github.com)

Working on this, I figured that your renderMissingNode proposal made for a nicer API after all. I've called it strict and implemented in attached patch. Does that solve your use case?

Working on this, I figured that your `renderMissingNode` proposal made for a nicer API after all. I've called it `strict` and implemented in attached patch. Does that solve your use case?
BrianHung commented 2024-05-20 20:33:03 +02:00 (Migrated from github.com)

It solves both the missing node and mark use cases; thanks Marijn!

It solves both the missing node and mark use cases; thanks Marijn!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-markdown!123
No description provided.