miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
784 stars 110 forks source link

Support of Smart punctuation / Simple typographic replacements #139

Open return42 opened 2 years ago

return42 commented 2 years ago

Is there any plan to support Smart punctuation?

By example en-dash, em-dash and curly quotes commonmark.js ..

- en-dash: foo -- bar
- em-dash: foo --- bar
- curly quotes: 'hello'

is rendered

<ul>
<li>en-dash: foo – bar</li>
<li>em-dash: foo — bar</li>
<li>curly quotes: ‘hello’</li>
</ul>

Instead of smart punctuation it might be better to just do some simple typographic replacements, like it is done in the markdown-it-py project.

* ``(c)``, ``(C)`` → ©
* ``(tm)``, ``(TM)`` → ™
* ``(r)``, ``(R)`` → ®
* ``(p)``, ``(P)`` → §
* ``+-`` → ±
* ``...`` → …
* ``?....`` → ?..
* ``!....`` → !..
* ``????????`` → ???
* ``!!!!!`` → !!!
* ``,,,`` → ,
* ``--`` → &ndash
* ``---`` → &mdash
pbodnar commented 2 years ago

Hi @return42, AFAIK the support for Smart punctuation as you describe is not in the plan, yet it might be something to consider - I think some kind of an optional "(raw)text replacements module" could be implemented...

And thanks to the link to markdown-it-py - it looks like a promising project, surely more active than this one and although defining an own renderer in it doesn't seem so straightforward as in mistletoe at the 1st sight (and there is just the HTML renderer available OOTB?), I guess I will check it out sooner or later. :)

return42 commented 2 years ago

@pbodnar TBH I am coming from reST markup (Sphinx-doc framework), we also have some content in our project written in markdown. For a while we used mistletoe to render some online (HTML) pages from this content but these days we changed to markdown-it-py since this is the same parser we used in Sphnix-doc (the myst-parser is based on). Hope you are not disappointed by our decision, but its easier for us to maintain one markdown parser than having twice in the same project.

Anyway .. thanks a lot for taking the time!!

pbodnar commented 2 years ago

@return42, yeah, I think your move is only logical, thx for the insight. :)