ProseMirror / prosemirror-markdown

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

Unnecessary escape for `#` character #105

Closed dragonman225 closed 1 year ago

dragonman225 commented 1 year ago

Problem

According to the CommonMark spec, # that is not followed by spaces, tabs, or the end of line, would not become headings.

Example: https://spec.commonmark.org/dingus/?text=%23%20abc%20(heading)%0A%0A%23abc%20(not%20heading)%0A%0A%23%0A(%E2%86%91%20empty%20heading)%0A

But the serializer of prosemirror-markdown escapes # even if the text would not be parsed as headings. e.g.

#foo

would be serialized back to

\#foo

making the generated Markdown less clean and less readable.

Solution

Given my previous experience with #101, I wonder if this can be solved by changing the regular expressions in the esc function a bit.

marijnh commented 1 year ago

Yes, this sounds like it could also be fixed by not matching these characters if they are followed by non-whitespace. Want to submit a PR?

dragonman225 commented 1 year ago

Sure! I'll try.