From: Waylan L. <way...@ic...> - 2015-05-01 01:27:46
|
Kalle, Sorry for the delayed response. You may be interested to know that the Smarty Extension [1] exists which already implements what you are trying to achieve along with all the various other parts of SmartyPants. However, if you would prefer to not have all of SmartyPants, but only your specific feature, then you need to be aware that HTML entities (like `—`) are considered raw HTML and will get escaped by the serializer when you insert them into an ElementTree Element. Therefore, you will need to avoid them going through the serializer, which can be accomplished with the HtmlStash [2], an instance of which is available at `self.markdown.htmlStash` within an Inlinepattern. Note that you will want to pass you HTML entity to the `store` method which will return a placeholder. Your `handleMatch` method will then need to return that placeholder. Something like this: def handleMatch(self, m): placeholder = self.markdown.htmlStash.store('—') return placeholder Then, after the ElementTree is serialized, the parser will go through the entire document and swap out all the placeholders for the raw HTML in the stash. I hope this helps. Waylan Limberg [1]: https://pythonhosted.org/Markdown/extensions/smarty.html [2]: https://github.com/waylan/Python-Markdown/blob/master/markdown/util.py#L131 On Apr 29, 2015, at 07:57 AM, Kalle Rutanen <kal...@ho...> wrote: Hi everyone, I'm trying to extend Python Markdown so that --- would be converted to an em-dash. For this, I built up an inline-pattern which matches --, and returns "—" from handleMatch(). Unfortunately, this gets to converted to "&mdash;" by Python Markdown. How can I get the — through without changes? Kalle ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Python-markdown-discuss mailing list Pyt...@li... https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss |