3 \@sdZddlmZddlmZddlmZddlmZmZddl m Z dd l Z Gd d d eZ Gd d d eZ GdddeZifddZd S)a Definition List Extension for Python-Markdown ============================================= Added parsing of Definition Lists to Python-Markdown. A simple example: Apple : Pomaceous fruit of plants of the genus Malus in the family Rosaceae. : An american computer company. Orange : The fruit of an evergreen tree of the genus Citrus. Copyright 2008 - [Waylan Limberg](http://achinghead.com) )absolute_import)unicode_literals) Extension)BlockProcessorListIndentProcessor)etreeNc@s4eZdZdZejdZejdZddZddZ dS) DefListProcessorz Process Definition Lists. z"(^|\n)[ ]{0,3}:[ ]{1,3}(.*?)(\n|$)z^[ ]{0,3}[^ :]cCst|jj|S)N)boolREsearch)selfparentblockr)build/lib/markdown/extensions/def_list.pytest#szDefListProcessor.testcCs|jd}|jj|}dd|d|jjdD}||jd}|jj|}|rb|d}} n|j|\}} |rd|j d|f}n |j d}|j |} | r| dkr|j d|dS| r| j dkrd } | j jd}|j| |j |} nd } | r@| j d kr@| } | rLt| rL| dj d krLt| drLd } n tj|d } x |D]} tj| d}| |_ qRW|jjj| tj| d }|jj||g|jjj| r|j d| dS)NrcSsg|]}|jr|jqSr)strip).0lrrr *sz(DefListProcessor.run.. z%s %srFp looselistlistdlrdddtr)popr r startsplitend NO_INDENT_REmatchdetabgroup lastChildinserttagtextremovelenr SubElementparserstateset parseBlocksreset)rrblocksZ raw_blockmZtermsrZ no_indentdtheRestsiblingr0rZtermrrrrrrun&sF           0      zDefListProcessor.runN) __name__ __module__ __qualname____doc__recompiler r$rr9rrrrr s   r c@s$eZdZdZdgZdgZddZdS)DefListIndentProcessorz5 Process indented children of definition list items. rrcCs tj|d}|jj||gdS)z< Create a new dd and parse the block with it as the parent. rN)r r.r/r2)rrrrrrr create_item`s z"DefListIndentProcessor.create_itemN)r:r;r<r= ITEM_TYPES LIST_TYPESrArrrrr@Zsr@c@seZdZdZddZdS)DefListExtensionz# Add definition lists to Markdown. cCs4|jjjdt|jd|jjjdt|jddS)z5 Add an instance of DefListProcessor to BlockParser. Z defindentz>indentZdeflistz>ulistN)r/blockprocessorsaddr@r )rmd md_globalsrrrextendMarkdownjs   zDefListExtension.extendMarkdownN)r:r;r<r=rIrrrrrDgsrDcCs t|dS)N)configs)rD)rJrrr makeExtensiontsrK)r= __future__rrrrErrutilr r>r r@rDrKrrrrs    =