3 \@sxdZddlmZddlmZddlmZddlmZddlm Z dd l Z Gd d d eZ Gd d d eZ ifddZ d S)a Admonition extension for Python-Markdown ======================================== Adds rST-style admonitions. Inspired by [rST][] feature with the same name. The syntax is (followed by an indented block with the contents): !!! [type] [optional explicit title] Where `type` is used as a CSS class name of the div. If not present, `title` defaults to the capitalized `type`, so "note" -> "Note". rST suggests the following `types`, but you're free to use whatever you want: attention, caution, danger, error, hint, important, note, tip, warning A simple example: !!! note This is the first line inside the box. Outputs:

Note

This is the first line inside the box

You can also specify the title and CSS class of the admonition: !!! custom "Did you know?" Another line here. Outputs:

Did you know?

Another line here.

[rST]: http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions By [Tiago Serafim](http://www.tiagoserafim.com/). )absolute_import)unicode_literals) Extension)BlockProcessor)etreeNc@seZdZdZddZdS)AdmonitionExtensionz+ Admonition extension for Python-Markdown. cCs&|j||jjjdt|jddS)z& Add Admonition to Markdown instance. admonition_beginN)registerExtensionparserblockprocessorsaddAdmonitionProcessor)selfmd md_globalsr+build/lib/markdown/extensions/admonition.pyextendMarkdown6s  z"AdmonitionExtension.extendMarkdownN)__name__ __module__ __qualname____doc__rrrrrr 3sr c@s6eZdZdZdZejdZddZddZ dd Z d S) rr zadmonition-titlez%(?:^|\n)!!!\ ?([\w\-]+)(?:\ "(.*?)")?cCsB|j|}|jj|p@|jd|jo@|o@|jddj|jdkS)N classr) lastChildREsearch startswith tab_lengthgetfind CLASSNAME)rparentblocksiblingrrrtestEs  zAdmonitionProcessor.testc Cs|j|}|jd}|jj|}|r8||jdd}|j|\}}|r|j|\}}tj|d} | j dd|j |f|rtj| d} || _ | j d|j n|} |j j| ||r|jd|dS)Nrrdivrz%s %sp)rpopr r!enddetabget_class_and_titler SubElementsetr&textCLASSNAME_TITLEr parseChunkinsert) rr'blocksr)r(mtheRestklasstitler+r,rrrrunKs$     zAdmonitionProcessor.runcCs@|jdj|jd}}|dkr,|j}n |dkr8d}||fS)Nrrr)grouplower capitalize)rmatchr:r;rrrr0hs  z'AdmonitionProcessor.get_class_and_titleN) rrrr&r4recompiler r*r<r0rrrrr?s  rcCs t|dS)N)configs)r )rCrrr makeExtensionusrD)r __future__rrrrrrutilrrAr rrDrrrr)s      6