\@sdZddlmZddlmZddlmZddlmZddlm Z dd l Z Gd d d eZ Gd d d eZ iddZ 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@s"eZdZdZddZdS)AdmonitionExtensionz+ Admonition extension for Python-Markdown. cCs3|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 3s r c@sOeZdZdZdZejdZddZddZ dd Z d S) rr zadmonition-titlez%(?:^|\n)!!!\ ?([\w\-]+)(?:\ "(.*?)")?cCs_|j|}|jj|p^|jd|jo^|o^|jddj|jdkS)N classr) lastChildREsearch startswith tab_lengthgetfind CLASSNAME)rparentblocksiblingrrrtestEszAdmonitionProcessor.testc Cs"|j|}|jd}|jj|}|rS||jdd}n|j|\}}|r|j|\}}tj|d} | j dd|j |f|rtj| d} || _ | j d|j qn|} |j j| ||r|jd|ndS)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|dkrUd}n||fS)Nrrr)grouplower capitalize)rmatchr:r;rrrr0hs %   z'AdmonitionProcessor.get_class_and_titleN) rrrr&r4recompiler r*r<r0rrrrr?s   rcCs td|S)Nconfigs)r )rCrrr makeExtensionusrD)r __future__rrrrrrutilrrAr rrDrrrr)s  6