Unnecessary escape for # character #105

Closed
opened 2023-07-27 13:45:56 +02:00 by dragonman225 · 2 comments
dragonman225 commented 2023-07-27 13:45:56 +02:00 (Migrated from github.com)

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.

### Problem According to the [CommonMark spec](https://spec.commonmark.org/0.30/#atx-headings), `#` 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 2023-07-27 21:36:15 +02:00 (Migrated from github.com)

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?

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 2023-07-28 08:30:38 +02:00 (Migrated from github.com)

Sure! I'll try.

Sure! I'll try.
Sign in to join this conversation.
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#105
No description provided.