From: Waylan L. <way...@ic...> - 2014-12-24 00:09:25
|
Nerade, Sorry for the delayed response. As the info you provided is a little sparse on details, I'm not sure how much help I can provide. If I'm understanding you correctly, you are looking to create an extension or two for Python-Markdown. All of the Extension API is documented on this page: https://pythonhosted.org/Markdown/extensions/api.html However, I appears that you are unclear which parts of the API to use. Without more specifics I cant say for sure, so here are some guidelines: Most extensions use InlinePatterns (in fact it is the oldest part of the API). If you are looking to add/change any inline markup (e.g.: anything that might be within a paragraph along with other text), then this is what you want. There is a fairly new tutorial [1] on the wiki that covers InlinePatterns in more detail. If also provides a little more clear guidance in how to tell Markdown about your extensions regardless of what part of the API you are using. If you want to add block level markup (if your "gallery" is wrapped in a HTML `<div>`), then you probably what to use a BlockProcessor. Unfortunately, this part of the API is the newest and least documented. I would suggest reading the source of the Admonition [6] and Table [2] extensions for some additional guidance. I'm not sure what exactly you want to accomplish with your "outline", but the Table of Contents extension [3] may already give you what you want. Or at least it may point you in the right direction. You might also want to look at the mdx_outline [4] (a third party extension). Both of those extensions use TreeProcessors, which provide you with a ElementTree object. You can iterate through the tree and pull the info out you want in a hierarchal manner. That leaves Preprocessors and Postprocessors, which operate on the plain text before and after the parser runs and should only be used as a last resort when the other options just wont work. The Footnotes [5] extension uses both (plus an InlinePattern). While it is more complex that most, it serves as a good example of using multiple parts of the API together. The Fenced Code [7] Extension also uses a Preprocessor and then relies on the built-in HtmlStash and its corresponding postprocessor [8]. However, that severely limits its functionality (fenced code blocks cannot be nested in lists, blockquotes, etc.) and it should be rewritten as a Blockprocessor. You can also find a lot of other examples of third party extensions listed on the wiki [9]. I hope you find this helpful. If you have any more specific questions, please feel free to ask. I'll try to help where I can. [1]: https://github.com/waylan/Python-Markdown/wiki/Tutorial:-Writing-Extensions- for-Python-Markdown [2]: https://github.com/waylan/Python-Markdown/blob/master/markdown/extensions/ta bles.py [3]: https://github.com/waylan/Python-Markdown/blob/master/markdown/extensions/to c.py [4]: https://github.com/aleray/mdx_outline [5]: https://github.com/waylan/Python-Markdown/blob/master/markdown/extensions/fo otnotes.py [6]: https://github.com/waylan/Python-Markdown/blob/master/markdown/extensions/ad monition.py [7]: https://github.com/waylan/Python-Markdown/blob/master/markdown/extensions/fe nced_code.py [8]: https://github.com/waylan/Python-Markdown/blob/master/markdown/postprocessor s.py#L48 [9]: https://github.com/waylan/Python-Markdown/wiki/Third-Party-Extensions Waylan -----Original Message----- From: Marcel Pörner [mailto:me...@ne...] Sent: Monday, December 22, 2014 12:14 PM To: pyt...@li... Subject: [Python-markdown-discuss] Clarification on different types of parser/pattern Hello, for the last few days I was looking for documentation for python markdown and explanation for the different mechanisms of markdown parser. Unfortunately the information on pyhtonhosted.org was not helpful for me. In fact I am trying to use markdown for an app in which the user should be able to markup a text. This text should contain an additional tag for an image gallery like object. I want to transform it into proper html output. Furthermore I was trying to make an outline of the headline in the text input. Until now I haven't understood which "parts" of markdown I have to extend and how. Thank you in advance for your help and best regards Nerade ---------------------------------------------------------------------------- -- Dive into the World of Parallel Programming! The Go Parallel Website, sponsored by Intel and developed in partnership with Slashdot Media, is your hub for all things parallel software development, from weekly thought leadership blogs to news, videos, case studies, tutorials and more. Take a look and join the conversation now. http://goparallel.sourceforge.net _______________________________________________ Python-markdown-discuss mailing list Pyt...@li... https://lists.sourceforge.net/lists/listinfo/python-markdown-discuss |