3 \4 @sdZddlmZddlmZddlmZddlmZddlZdd ZGd d d ej Z Gd d d e Z Gddde Z Gddde Z dS)a POST-PROCESSORS ============================================================================= Markdown also allows post-processors, which are similar to preprocessors in that they need to implement a "run" method. However, they are run after core processing. )absolute_import)unicode_literals)util)odictNcKs,tj}t||d<t|d<t|d<|S)z0 Build the default postprocessors for Markdown. Zraw_htmlZamp_substituteunescape)r OrderedDictRawHtmlPostprocessorAndSubstitutePostprocessorUnescapePostprocessor) md_instancekwargspostprocessorsr$build/lib/markdown/postprocessors.pybuild_postprocessorss    rc@seZdZdZddZdS) Postprocessora Postprocessors are run after the ElementTree it converted back into text. Each Postprocessor implements a "run" method that takes a pointer to a text string, modifies it as necessary and returns a text string. Postprocessors must extend markdown.Postprocessor. cCsdS)z Subclasses of Postprocessor should implement a `run` method, which takes the html document as a single text string and returns a (possibly modified) string. Nr)selftextrrrrun&szPostprocessor.runN)__name__ __module__ __qualname____doc__rrrrrrs rc@s(eZdZdZddZddZddZdS) r z# Restore raw html to the document. cCsxt|jjjD]}|jjj|\}}|jjrv| rvt|jjjdkrT|j|}n"t|jjjdkrnd}n|jj }|j |r|s|jj r|j d|jjj ||d}|j |jjj ||}qW|S)z2 Iterate over html stash and restore "safe" html. escaperemovez

%s

 ) rangemarkdown htmlStash html_counter rawHtmlBlockssafeModestrlowerrhtml_replacement_text isblocklevelreplaceget_placeholder)rrihtmlsaferrrr3s   zRawHtmlPostprocessor.runcCs0|jdd}|jdd}|jdd}|jddS) z Basic html escaping &z&z>"z")r()rr+rrrrFs   zRawHtmlPostprocessor.escapecCs:tjd|}|r6|jddd kr&dStj|jdSd S) Nz^\<\/?([^ >]+)rr!?@%TF)r1r2r3r4)rematchgroupr isBlockLevel)rr+mrrrr'Ms  z!RawHtmlPostprocessor.isblocklevelN)rrrrrrr'rrrrr 0sr c@seZdZdZddZdS)r z Restore valid entities cCs|jtjd}|S)Nr-)r(rAMP_SUBSTITUTE)rrrrrrZszAndSubstitutePostprocessor.runN)rrrrrrrrrr Wsr c@s6eZdZdZejdejejfZ ddZ ddZ dS)r z Restore escaped chars z %s(\d+)%scCstjt|jdS)Nr)rint2strintr7)rr9rrrrdszUnescapePostprocessor.unescapecCs|jj|j|S)N)REsubr)rrrrrrgszUnescapePostprocessor.runN) rrrrr5compilerSTXETXr=rrrrrrr _sr )r __future__rrrrrr5r Processorrr r r rrrr s     '