ProseMirror / prosemirror-markdown

ProseMirror Markdown integration
https://prosemirror.net
MIT License
345 stars 81 forks source link

Adding images after spaces wraps image markdown in code block #48

Closed buddh4 closed 4 years ago

buddh4 commented 4 years ago

When adding spaces before an image in the wysiwyg the image markdown will be wrapped in a code block. How could we escape such a case?

grafik

marijnh commented 4 years ago

Could you describe more precisely what you are doing? Adding an image after a space to the document in the ProseMirror editor on https://prosemirror.net/examples/markdown/ and then switching to markdown doesn't do anything unexpected.

buddh4 commented 4 years ago

Sorry, here some infos how to reproduce:

The result in my screenshot above (with the ``` block) happens only if you again switch back to Markdown. The problem is that 4+ spaces at the beginning of a line will be interpreted as code block which is normal markdown syntax, but breaks wysiwyg in this case.

marijnh commented 4 years ago

Ah, okay, that doesn't appear to be related to images, since the same thing happens with text. It seems Markdown doesn't provide a way to escape spaces, and requires parsers to strip leading spaces. So there's not much this serializer can do to preserve those.

More generally, having spaces at the start of a paragraph like that suggests you're trying to do layout with spaces, which is rarely a good idea anyway (HTML will collapse them, for example).

buddh4 commented 4 years ago

Yeah, just thought there maybe was an easy way of escaping such cases. Its not me who wants to use spaces for layouting, but for normal users this is rather unexpected.

I thought about following solutions:

Anyways, thanks for your feedback.

marijnh commented 4 years ago

Markdown, unfortunately, turns out to be somewhat problematic as a serialization format when users aren't directly writing it, since it has a bunch of these corner cases that make some documents unrepresentable.

I don't think I'll be able to address this one at in this module, so I'm closing this issue.