Ñò éíÑXc@szddkZddkZd„Zdfd„ƒYZdefd„ƒYZdefd„ƒYZd efd „ƒYZdS( iÿÿÿÿNcCst|tƒp t|tƒS(s Check if it's string (t isinstancetunicodetstr(ts((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pytisStringst ProcessorcBseZdd„ZRS(cCs|o ||_ndS(N(tmarkdown(tselftmarkdown_instance((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__init__ sN(t__name__t __module__tNoneR (((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyRst TreeprocessorcBseZdZd„ZRS(s' Treeprocessors are run on the ElementTree object before serialization. Each Treeprocessor implements a "run" method that takes a pointer to an ElementTree, modifies it as necessary and returns an ElementTree object. Treeprocessors must extend markdown.Treeprocessor. cCsdS(s" Subclasses of Treeprocessor should implement a `run` method, which takes a root ElementTree. This method can return another ElementTree object, and the existing root ElementTree will be replaced, or it can modify the current tree and return None. N((Rtroot((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pytruns(R R t__doc__R(((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyR s tInlineProcessorcBsheZdZd„Zd„Zd„Zd„Zdd„Zed„Z d„Z dd „Z d „Z RS( sJ A Treeprocessor that traverses a tree, applying inline patterns. cCsati|_ti|_dt|iƒt|iƒ|_titi dƒ|_ ||_dS(Nis ([0-9]{4})( RtINLINE_PLACEHOLDER_PREFIXt$_InlineProcessor__placeholder_prefixtETXt$_InlineProcessor__placeholder_suffixtlent$_InlineProcessor__placeholder_lengthtretcompiletINLINE_PLACEHOLDERt _InlineProcessor__placeholder_re(Rtmd((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyR 's   #cCs*dt|iƒ}ti|}||fS(s Generate a placeholder s%04d(Rt stashed_nodesRR(Rttypetidthash((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__makePlaceholder/s cCsH|ii||ƒ}|o|idƒ|iƒfSd|dfSdS(sö Extract id from data string, start from index Keyword arguments: * data: string * index: index, from which we start search Returns: placeholder id and string index, after the found placeholder. iN(RtsearchtgrouptendR (Rtdatatindextm((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__findPlaceholder5s cCs&|i|ƒ\}}||i|<|S(s Add node to stash (t!_InlineProcessor__makePlaceholderR(RtnodeRt placeholderR((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt __stashNodeGs icCs‡t|tiƒppd}xg|t|iiƒjoI|i|iii|ƒ|||ƒ\}}}|p|d7}qqWn|S(s Process string with inline patterns and replace it with placeholders Keyword arguments: * data: A line of Markdown text * patternIndex: The index of the inlinePattern to start with Returns: String with placeholders. ii(RRt AtomicStringRtinlinePatternst_InlineProcessor__applyPatterntvalue_for_index(RR%t patternIndext startIndextmatched((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__handleInlineMs cCs±|o|i}d|_n|i}d|_|i||ƒ}| o3||j o&|iƒi|ƒ}|i|ƒnd}|iƒx|D]}|i||ƒq“WdS(s4 Process placeholders in Element.text or Element.tail of Elements popped from self.stashed_nodes. Keywords arguments: * node: parent node * subnode: processing node * isText: bool variable, True - it's text, False - it's tail Returns: None iN( ttextR ttailt%_InlineProcessor__processPlaceholderst getchildrenR&tremovetreversetinsert(RR*tsubnodetisTextR5t childResulttpostnewChild((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__processElementTextds     c sº‡‡fd†}g‰d}x•|o|i|i|ƒ}|djoM|i||ƒ\}}||ijoú|ii|ƒ}|djo|||!} || ƒnt|ƒp‰x™|g|iƒD]m} | io+| iiƒo|i || t ƒqn| i o(| i iƒo|i | | ƒq:qÍqÍWn||ƒ|}q!|}ˆi |ƒq±|t tƒ} |||| !ƒ| }q!||} || ƒd}q!WˆS(sH Process string with placeholders and generate ElementTree tree. Keyword arguments: * data: string with placeholders instead of ElementTree elements. * parent: Element, which contains processing inline data Returns: list with ElementTree elements with applied inline patterns. csr|ogˆo6ˆdioˆdi|7_qj|ˆd_qnˆioˆi|7_qn|ˆ_ndS(Niÿÿÿÿ(R6R5(R5(tresulttparent(s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pytlinkTexts iiÿÿÿÿt(tfindRt!_InlineProcessor__findPlaceholderRtgetRR8R6tstript$_InlineProcessor__processElementTexttFalseR5tappendRtprefix( RR%RCRDt strartIndexR&Rt phEndIndexR*R5tchildR$((RCRBs;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__processPlaceholders…sD              c Csw|iƒi||ƒ}|| }|p|tdfS|i|ƒ}|djo1|tt|ƒ|it|iƒƒƒdfSt |ƒpt |i t i ƒpƒx€|g|iƒD]g}t |ƒpT|i o |i|i |dƒ|_ n|io|i|i|ƒ|_q#q¼q¼Wq/n|i||iƒƒ} d||idƒ| |iƒdftdfS(s¨ Check if the line fits the pattern, create the necessary elements, add it to stashed_nodes. Keyword arguments: * data: the text to be processed * pattern: the pattern to be checked * patternIndex: index of current pattern * startIndex: string index, from which we starting search Returns: String with placeholders instead of ElementTree elements. iis%s%s%s%siÿÿÿÿN(tgetCompiledRegExptmatchRKt handleMatchR tTrueRtspantgroupsRRR5RR-R8t_InlineProcessor__handleInlineR6t_InlineProcessor__stashNodeRR#( RtpatternR%R1R2RStleftDataR*RPR+((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyt__applyPatternÆs,  1        c Csžh|_|g}x…|o}|iƒ}g}x¡|iƒD]“}|ioet|itiƒ oN|i}d|_|i|i |ƒ|ƒ}||7}|i ||fƒn|iƒo|i |ƒq;q;WxÀ|D]¸\}}|ioti i |i|ƒ|_nd} xz|D]r} | i oti i | i |ƒ| _ n| ioti i | i| ƒ| _n|i| | ƒ| d7} qWqÙWqW|S(sCApply inline patterns to a parsed Markdown tree. Iterate over ElementTree, find elements with inline tag, apply inline patterns and append newly created Elements to tree. If you don't want process your data with inline paterns, instead of normal string, use subclass AtomicString: node.text = markdown.AtomicString("data won't be processed with inline patterns") Arguments: * markdownTree: ElementTree object, representing Markdown tree. Returns: ElementTree object with applied inline patterns. iiN(RtpopR8R5RRR-R R7RXRLtinlinepatternsthandleAttributesR6R;( Rttreetstackt currElementt insertQueueRPR5tlsttelementtiR@((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyRòsD    !         ( R R RR R)RGRYRXRURJR7R/R(((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyR"s      ! A ,tPrettifyTreeprocessorcBs eZdZd„Zd„ZRS(s& Add linebreaks to the html document. cCsd}ti|iƒo¿|idjo¯|i p|iiƒ o1t|ƒo$ti|diƒo ||_nx2|D]*}ti|iƒo|i|ƒq}q}W|i p|iiƒ o ||_qØn|i p|iiƒ o ||_ndS(s5 Recursively add linebreaks to ElementTree children. s tcodetpreiN(scodeRi(Rt isBlockLevelttagR5RIRt_prettifyETreeR6(RtelemRfte((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyRl.s#$ cCsj|i|ƒ|idƒ}xG|D]?}|i p|iiƒ o d|_q#d|i|_q#WdS(s, Add linebreaks to ElementTree root object. tbrs s %sN(Rlt getiteratorR6RI(RRtbrsRo((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyR>s  (R R RRlR(((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyRg+s (RRRRR RRg(((s;/usr/lib/python2.6/site-packages/markdown/treeprocessors.pyts   ÿ