shurcooL-legacy / atom-markdown-format

Formats your Markdown text on save.

Home Page:https://atom.io/packages/markdown-format

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect Formatting when escaping characters

Lindenk opened this issue · comments

When escaping * for instance (by using *), the formatter removes the \ which breaks the escape.

This also applies to:

_
[
]
(
)
<


.
`

Any others?

I hope that http://daringfireball.net/projects/markdown/syntax#backslash is the complete list. Fix incoming.

Actually, it's turning out more difficult to do this correctly in all cases because the parser doesn't tell me if a given piece of text was originally escaped or not, so I need to reverse-engineer based on context.

Consider two pieces of Markdown that render (to HTML) the same:

1986\. What a great season. Was it *not*.
1986\. What a great season. Was it *not*\.

The period after the number must be escaped, because otherwise it will parsed as a list instead of plain text. But the last period after *not* may or may not be escaped, it makes no difference. However, the parser presents both periods the same to me.

It's still doable (by keeping track of context), but more tricky.

I've written a workaround that seems to work okay-ish in shurcooL/markdownfmt@d996910. But to really do this properly, I'd need to make changes to the parser to provide more info (which is currently not included).

But to really do this properly, I'd want to write a new simpler spec, parser and renderer for the entire Markdown language (making it no longer exactly Markdown). That's a pretty large scope, and I have no plans to do that right now, hence the workaround will have to suffice.

Oh wow that was an incredibly fast response. I think those are all of the escapable characters. Thanks