IHc@sdZddddfZdZddkZddkZddkZddklZlZl Z l Z l Z l Z l Z lZeZed Zeie eae d Ztietieeitd Zd ZeZdZd ZddfddffZheifd6eieifd6Z dZ!dZ"dZ#e#dZ$ddddddddd d!d"d#d$d%d&d'd(d)d*gZ%d+Z&ei'd,d-fei'd.d/fei'd0d1fgZ(ei'd2d-fei'd.d/fei'd0d1fei'd3d4fgZ)d5Z*d6fd7YZ+d8fd9YZ,d:fd;YZ-d<fd=YZ.d>fd?YZ/d@fdAYZ0dBfdCYZ1dDe0fdEYZ2e2Z3dFe1fdGYZ4e4Z5dHe1fdIYZ6e6Z7dJe1fdKYZ8e8Z9dLZ:dMe:dNdOe:dPdOe:dQZ;dRZ<dSZ=dTZ>dUZ?dVZ@dWZAdXZBeo dYZCndZZCd[ZDd\ZEe<e;d]ZFe<e;d^ZGd_e;d]ZHe<e;d`ZId_e;d`ZJdaZKdbZLdcZMddZNdeZOdfZPdgZQdhfdiYZReRZSdjeRfdkYZTdleRfdmYZUdneUfdoYZVdpeRfdqYZWdreUfdsYZXdteRfduYZYdveRfdwYZZdxeRfdyYZ[dzeRfd{YZ\d|e\fd}YZ]d~eRfdYZ^deRfdYZ_eTe?Z`eTeKZaeWe=ZbeWe>ZceUeAdZdeUeDdZeeUe@dZfeUeCdZgeXeBdZheXeEdZieVePdZjeVeQdZkeZeFZleZeGZme[eHZne]eJZoe\eIZpeYeNZqeYeOZre^eLZse_eMZtdfdYZudfdYZvdevfdYZwewZxdfdYZydfdYZzdZ{dZ|dfdYZ}e}Z~dfdYZeegeeedZgedZdfdYZde"ZdZedjo0eZe oeidneendS(s1.7iiisrc-2s $Rev: 72 $iN(t getLoggert StreamHandlert FormattertDEBUGtINFOtWARNtERRORtCRITICALtMARKDOWNs%%(name)s-%(levelname)s: "%(message)s"cCsti||dS(s. A wrapper method for logging debug messages. N(tloggertlog(tlevelttext((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytmessage5sis[HTML_REMOVED]u֐u߿uⴰu⵿sutf-8sutf-16cCsct|t}xMt|D]A}|o|i|p|}|i|o|i|SqW|S(N(t isinstancetunicodetBOMStdecodet startswithtlstrip(R tencodingtconverttbom((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt removeBOMTs spython markdown.pytqaodmasdkwaspemass%dajkqlsmdqpakldnzsdflstptdivt blockquotetprettabletdltoltultscripttnoscripttformtfieldsettiframetmathtinstdelthrshr/tstylecCs,|tjp|ddjo|ddjS(Nithit 0123456789(tBLOCK_LEVEL_ELEMENTS(ttag((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt isBlockLevelos t&s&ts>s&(?!\#)s"s"cCsx|pdS|d}t|t p|i odSx7tD]+\}}||jo||jodSqAWdSdS(Nitrtltltr(tNoneRRtisalphatRTL_BIDI_RANGES(R tchtmintmax((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt getBidiTypes   tDocumentcBsqeZdZdZdZd dZdZdZdZ dZ e dZ d Z d ZRS( cCs d|_dS(NR4(tbidi(tself((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt__init__scCs(||_t|_||_h|_dS(N(tdocumentElementtTruetisDocumentElementtparenttentities(R>tchild((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt appendChilds   cCs|o ||_ndS(N(R=(R>R=((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytsetBidiscCs:t|}||_|o|i|i|n|S(N(tElementtdocRFtcreateTextNode(R>R.ttextNodetel((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt createElements   cCst|}||_|S(N(tTextNodeRI(R>R tnode((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRJs  cCs2||ijot||i|tentity((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytcreateEntityReferencescCst|}||_|S(N(tCDATARI(R>R RO((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt createCDATAs  cCs |iiS(N(R@ttoxml(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRUscCsD|o t}nt}x&|D]\}}|i||}qW|S(N(t%ENTITY_NORMALIZATION_EXPRESSIONS_SOFTt ENTITY_NORMALIZATION_EXPRESSIONStsub(R>R tavoidDoubleNormalizingtregexpstregexpt substitution((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytnormalizeEntitiess  cCs|ii|S(N(R@tfind(R>ttest((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR^scCs|iid|_dS(N(R@tunlinkR5(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR`s N(t__name__t __module__R?RFRGR5RMRJRRRTRUtFalseR]R^R`(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR<s         RScBs)eZdZdZdZdZRS(tcdatacCs ||_dS(N(R (R>R ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?scCsdS(N((R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pythandleAttributesscCsd|idS(Ns (R (R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRUs(RaRbttypeR?ReRU(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRSs  RHcBsteZdZdZdZdZdZdZdZdZ dZ d Z d d Z d Z RS( telementcCs:||_g|_h|_g|_d|_t|_dS(N(tnodeNamet attributestattribute_valuest childNodesR5R=RcRB(R>R.((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?s      cCsJ|o?|i}|i p |io||_|ii|qFndS(N(R=RBRCRG(R>R=t orig_bidi((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRGs   cCs?x/|iD]$}|idjo|iq q Wd|_dS(NRg(RkRfR`R5(R>RE((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR`s  cCs5||ijo|ii|n||i|tattrtvalue((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt setAttributescCs |ii||||_dS(N(RktinsertRC(R>tpositionRE((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt insertChild scCs|ii|dS(N(Rktremove(R>RE((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt removeChild scCs3|ii|}|i||i||dS(N(RktindexRuRs(R>toldChildtnewChildRr((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt replaceChilds cCs|ii|||_dS(N(RkRmRC(R>RE((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRFscCsdS(N((R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyResicCsjg}x]|iD]R}||o|i|n|idjo||i||d7}qqW|S(s; Returns a list of descendants that pass the test function Rgi(RkRmRfR^(R>R_tdeptht matched_nodesRE((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR^s  "cCs to"x|iD]}|iqWnd}|idjo|d7}n|idjo|d7}nd}|ip|idjo|d 7}x!|iD]}||i7}qW|id jo|d7}n|idjo|d7}n|d |i7}n |d 7}|d|i7}|idjo_|iidpH|io |i}n |ii}|djo|i ddqqnxJ|i D]?}|i|}|ii |dt }|d||f7}qW||7}|idjo|d7}n|S(Ntth1th2th3th4s tlis RR2Rss/>R1R Rth5th6tdirR3RYs %s="%s"sbr (R}R~RR(sli(s blockquote( RslisulRR}R~RRRR( Rsbr slisulRR}R~RR( tENABLE_ATTRIBUTESRkReRhRURjthas_keyR=RIRpRiR]RA(R>REtbuffert childBufferR=RnRo((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRU&sR              (RaRbRfR?RGR`RpRsRuRyRFReR^RU(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRHs        RNcBsAeZdZeidZdZdZdZdZ RS(R s\{@([^\}]*)=([^\}]*)}cCs ||_dS(N(Ro(R>R ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?hscCs)|ii|id|iddS(Nii(RCRptgroup(R>tmatch((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytattributeCallbackkscCs"|ii|i|i|_dS(N(t attrRegExpRXRRo(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyReoscCs|i}|iit||itpq|iidjo|idd}q|iidjo1|iid|jod|idd}qn|i i |}|S(NRs s Ris ( RoRCRGR;RtHTML_PLACEHOLDER_PREFIXRhtreplaceRkRIR](R>R ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRUrs ( RaRbRftretcompileRR?RReRU(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRNcs    RPcBs)eZdZdZdZdZRS(t entity_refcCs ||_dS(N(RQ(R>RQ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?scCsdS(N((R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRescCsd|idS(NR0t;(RQ(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRUs(RaRbRfR?ReRU(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRPs  tTextPreprocessorcBseZdZdZRS(s` TextPreprocessors are run before the text is broken into lines. Each TextPreprocessor implements a "run" method that takes a pointer to a text string of the document, modifies it as necessary and returns either the same pointer or a pointer to a new string. TextPreprocessors must extend markdown.TextPreprocessor. cCsdS(N((R>R ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytruns(RaRbt__doc__R(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs t PreprocessorcBseZdZdZRS(sK Preprocessors are run after the text is broken into lines. Each preprocessor implements a "run" method that takes a pointer to a list of lines of the document, modifies it as necessary and returns either the same pointer or a pointer to a new list. Preprocessors must extend markdown.Preprocessor. cCsdS(N((R>tlines((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs tHtmlBlockPreprocessorcBs;eZdZdZdZdZdZdZRS(s7Removes html blocks from the source text and stores it.cCs'|didddidiS(NiR2t i(Rtsplittlower(R>tblock((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt _get_left_tagscCs"|it| dd!iS(Nii(trstriptlenR(R>tleft_tagR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt_get_right_tagscCs|djp|dd jotSd||jotS|djo|djotS||djo|dd jotStSdS( NRit?t@t%t/s--iR1(RRR(RARc(R>Rt right_tag((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt _equal_tagsscCs |djS(NR)shr/(R)shr/((R>R.((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt _is_onelinerscCsNg}|id}g}d}d}t}x|D]}|ido|d}n|p:|ido|i|}|i||}t|p|dd jp|i|q4n|i|o|i|iq4n|ddjod }|i||}n|i i d o9|i ||o&|i|i i |iq4q|i|it}q4n|i|q4|i|i|i||}|i ||o2t}|i|i i di|g}q4q4W|o3|i|i i di||idndi|S( Ns R|s iR1t!RRRs--R2(RRRR(RRcRRRR/RmRtstripRtendswithRtstashtstoreRAtjoin(R>R t new_blockstitemsRRtin_tagR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRsX  "(RaRbRRRRRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs     tHeaderPreprocessorcBseZdZdZRS(sj Replaces underlined headers with hashed headers to avoid the nead for lookahead later. cCsPd}xC|dt|jo+|d}||ipq n||ido|i|ddn|dt|jo||do||ddd jo||di}|dt|jo*d||i||Rtit underline((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR$s& (RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRstLinePreprocessorcBs/eZdZeidZdZdZRS(s>Deals with HR lines (needs to be done before processing lists)s^(> )+cCsxtt|D]~}d}|ii||}|o|id}n|i||t|o$||iiddt||tsafe( trangeRt blockquote_retsearchRt_isLineRRRA(R>RRtprefixtm((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRFs(cCs|idodSdig}|D]}|ip ||q&q&~}t|djodSxMdddgD]8}ti|i|}|o|idodSqxWdSd S( s5Determines if a block should be replaced with an
s iR|itisline1tisline2tisline3iN(RRtisspaceRtREtregExpRR(R>Rt_[1]txR tpatternR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyROs; (RaRbRRRRRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRAs tReferencePreprocessorcBseZdZdZRS(sU Removes reference definitions from the text and stores them for later use. cCsUg}xH|D]@}tidi|}|o|idii}|idi}|p |id|f|i|Rtnew_texttlineRtidtt((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRds" &&"'(RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR_ss[^\]\[]*s\[(s(\[is\])*s)\]s(?\)s\!s\s*\[([^\]]*)\]s( \* )s<(http://[^>]*)>s<([^> \!]*@[^> ]*)>s(\<[a-zA-Z/][^\>]*\>)s(&[\#a-zA-Z0-9]*;)s \ns $tPatterncBseZdZdZRS(cCs)||_tid|ti|_dS(Ns ^(.*)%s(.*)$(RRRtDOTALLt compiled_re(R>R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?s cCs|iS(N(R(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytgetCompiledRegExps(RaRbR?R(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs tSimpleTextPatterncBseZdZRS(cCs|i|idS(Ni(RJR(R>RRI((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt handleMatchs(RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRstSimpleTagPatterncBseZdZdZRS(cCsti||||_dS(N(RR?R.(R>RR.((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?scCs5|i|i}|i|i|id|S(Ni(RMR.RFRJR(R>RRIRL((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbR?R(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs tSubstituteTagPatterncBseZdZRS(cCs|i|iS(N(RMR.(R>RRI((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRstBacktickPatterncBseZdZdZRS(cCsti||d|_dS(Ntcode(RR?R.(R>R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?scCsA|i|i}|idi}|i|i||S(Ni(RMR.RRRFRJ(R>RRIRLR ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbR?R(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs tDoubleTagPatterncBseZdZRS(cCsf|iid\}}|i|}|i|}|i||i|i|id|S(Nt,i(R.RRMRFRJR(R>RRIttag1ttag2tel1tel2((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs  (RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRst HtmlPatterncBseZdZRS(cCs4|id}t}|ii|}|i|S(Ni(RRARRRJ(R>RRItrawhtmltinlinet place_holder((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRst LinkPatterncBseZdZRS(cCs|id}|i|i|id|idid}|o|id|din|iddt|djo=ddi|di}t |}|id |n|S( Ntaii t"threfiR|ittitle( RMRFRJRRRpRRRtdequote(R>RRIRLtpartsR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs (RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRst ImagePatterncBseZdZRS(cCs|id}|idi}|o|id|dn|iddt|djo'|idtdi|dntoL|i|id }|i ||i |i }|i i |n|id }|id ||S( Ntimgi tsrciR|iRRitalt(RMRRRpRRRRRJRFReRoRkRt(R>RRIRLt src_partsR ttruealt((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR$s '   (RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR"stReferencePatterncBseZdZdZRS(cCs|ido|idi}n|idi}|ii|pdS|i|\}}|id}|i||||S(Ni i(RRRRR5tmakeTag(R>RRIRRRR ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR:scCsT|id}|id||o|id|n|i|i||S(NRRR(RMRpRFRJ(R>RRR RIRL((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRIs (RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR8s tImageReferencePatterncBseZdZRS(cCsN|id}|id||o|id|n|id||S(NRRRR(RMRp(R>RRR RIRL((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRTs (RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRRstAutolinkPatterncBseZdZRS(cCsK|id}|id|id|i|i|id|S(NRRi(RMRpRRFRJ(R>RRIRL((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR_s(RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR]stAutomailPatterncBseZdZRS(c Cs|id}|id}|ido|td}nx4|D],}|idt|}|i|qIWd|}dig}|D]}|dt|q~}|id||S(NRismailto:s#%dR|s&#%d;R( RMRRRRRtordRFRRp( R>RRIRLtemailtletterRQtmailtoR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRgs 4(RaRbR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyReststrongtems strong,emsbr t PostprocessorcBseZdZdZRS(s Postprocessors are run before the dom it converted back into text. Each Postprocessor implements a "run" method that takes a pointer to a NanoDom document, modifies it as necessary and returns a NanoDom document. Postprocessors must extend markdown.Postprocessor. There are currently no standard post-processors, but the footnote extension uses one. cCsdS(N((R>tdom((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs tTextPostprocessorcBseZdZdZRS(s, TextPostprocessors are run after the dom it converted back into text. Each TextPostprocessor implements a "run" method that takes a pointer to a text string, modifies it as necessary and returns a text string. TextPostprocessors must extend markdown.TextPostprocessor. cCsdS(N((R>R ((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRstRawHtmlTextPostprocessorcBs#eZdZdZdZRS(cCsdS(N((R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?scCsxt|iiD]}|ii|\}}|iog| o_t|iidjo|i|}qt|iidjo d}qt}n|i dt ||d}|i t ||}qW|S(NtescapeRtR|s

%s

s ( RRt html_countert rawHtmlBlockstsafeModetstrRRtHTML_REMOVED_TEXTRtHTML_PLACEHOLDER(R>R RthtmlR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs   cCsF|idd}|idd}|idd}|iddS( s Basic html escaping R0s&R1s<R2s>Rs"(R(R>R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(RaRbR?RR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs  t HtmlStashcBs#eZdZdZedZRS(suThis class is used for stashing HTML objects that we extract in the beginning and replace with place-holders.cCsd|_g|_dS(Ni(RR(R>((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?s cCs6|ii||ft|i}|id7_|S(s^Saves an HTML segment for later reinsertion. Returns a placeholder string that needs to be inserted into the document. @param html: an html segment @param safe: label an html segment as safe for safemode @param inline: label a segmant as inline html @returns : a placeholder string i(RRmRR(R>RRt placeholder((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs  (RaRbRR?RcR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR s t BlockGurucBs&eZddZdZdZRS(ic Cs+g}d}d}x|D]}|i o| o|||fS|i o~|ow|d7}x>t|t|D]&}||io||} PqyqyWP|| } | o|idqqPn||} | o|i| |d7}qq|||fSqW|d7}|||fS(sFunctional magic to help determine boundaries of indented blocks. @param lines: an array of strings @param fn: a function that returns a substring of a string if the string matches the necessary criteria @param allowBlank: specifies whether it's ok to have blank lines between matching functions @returns: a list of post processes items and the unused remainder of the original listiiiR|(RRRRm( R>Rtfnt allowBlankRtitemRRtjtnexttpart((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt _findHeads8          cCs3tidi|}|o|idSdSdS(s/ An auxiliary method to be passed to _findHead ttabbediN(RRRRR5(R>RR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt detabbed_fn8scCs|i||iddS(NR i(RR(R>R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt detectTabbedAs(RaRbRRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR s < cCstii|ddS(sPrint an error string to stderrs N(tsyststderrtwrite(tstring((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt print_errorGscCsT|ido|idp |ido|ido |dd!S|SdS(s% Removes quotes from around a string Rt'iiN(RR(R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRLs   t CorePatternscBsceZdZh dd6dd6dd6dd6d d 6d d 6d d6dd6dd6dd6ZdZRS(sLThis class is scheduled for removal as part of a refactoring effort.s(#*)([^#]*)(#*)theaders&(\ ?\ ?\ ?)\[([^\]]*)\]:\s*([^ ]*)(.*)s reference-defs([-]*)$|^([=]*)t containslines[ ]{0,3}[\d]*\.\s+(.*)Rs[ ]{0,3}[*+-]\s+(.*)R s(\**)Rs(\-*)Rs(\_*)Rs((\t)|( ))(.*)Rs> ?(.*)tquotedcCsjh|_x>|iiD]-}tid|i|ti|i|tkey((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?ps  (RaRbRR R?(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR^s tMarkdowncBseZdZdgdedZdZdZdZdZ dddZ dZ d Z d Z d Zd Zd ZdZdZddZdZddZdZeZRS(sS Markdown formatter class for creating an html document from Markdown text cCs||_|dj ottdn||_t|_g|_d|_d|_ t g|_ t t tg|_g|_tg|_g|_ttttttttttttt t!t"t#t$t%t&t't(g|_)|i*d|d||i+dS(sCreates a new Markdown instance. @param source: The text in Markdown format. Depreciated! @param extensions: A list if extensions. @param extension-configs: Configuration setting for extensions. @param safe_mode: Disallow raw html. sThe `source` arg of Markdown.__init__() is depreciated and will be removed in the future. Use `instance.convert(source)` instead.iR|t extensionstconfigsN(,tsourceR5R RRR t blockGurutregisteredExtensionststripTopLevelTagstdocTypetHTML_BLOCK_PREPROCESSORttextPreprocessorstHEADER_PREPROCESSORtLINE_PREPROCESSORtREFERENCE_PREPROCESSORt preprocessorstpostprocessorstRAWHTMLTEXTPOSTPROCESSORttextPostprocessorst prePatternstDOUBLE_BACKTICK_PATTERNtBACKTICK_PATTERNtESCAPE_PATTERNtREFERENCE_PATTERNtLINK_ANGLED_PATTERNt LINK_PATTERNtIMAGE_LINK_PATTERNtIMAGE_REFERENCE_PATTERNtAUTOLINK_PATTERNtAUTOMAIL_PATTERNtLINE_BREAK_PATTERN_2tLINE_BREAK_PATTERNt HTML_PATTERNtENTITY_PATTERNtNOT_STRONG_PATTERNtSTRONG_EM_PATTERNtSTRONG_EM_PATTERN_2tSTRONG_PATTERNtSTRONG_PATTERN_2tEMPHASIS_PATTERNtEMPHASIS_PATTERN_2tinlinePatternstregisterExtensionstreset(R>R'R%textension_configst safe_mode((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?sN             cCs|p h}nx|D]}d|}yt|}Wnttd||fqX|i|o||}ng}|i|}|i|tqWdS(Ntmdx_s2couldn't load extension %s (looking for %s module)(t __import__R RRt makeExtensiontextendMarkdowntglobals(R>R%R&texttextension_module_nametmoduletconfigs_for_extt extension((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRLs   cCs|ii|dS(s# This gets called by the extension N(R)Rm(R>RY((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytregisterExtensionscCsh|_t|_|it_|it_|it_|it_|it_|it _|it _|it _|i t _ x|i D]}|iqWdS(sLResets all state variables so that we can start with a new text.N(RR t htmlStashR,RR/R0RBRCR9R=R3RR)RM(R>RY((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRMs            cCst|_|iid|_|ii|iid|iidd|ii|i|i}|iddidd}|d7}|i t }|i d|_ x&|i D]}|i|i |_ qWg}xN|i D]C}|ido |i|i||g}q|i|qW|i|i||ii|iidx!|iD]}|i|iqnW|iS( saTransforms the Markdown text into a XHTML body document @returns: A NanoDom Document tspans tclasstmarkdowns s s R(R<RIRMt top_elementRFRJRpR'Rt expandtabst TAB_LENGTHRRR1RRt_processSectionRmR2(R>R tprepRRt postprocessor((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt _transforms4       ic Cs}xv|onh|id6|id6|id6|id6}xTddddgD]@}ti|i|d}|o|||||dSqKW|oF|i|d\}}|i|||dd ||d}nr|i|d \} }t | o(| di d o|i || n"| o|i || ||n|o |di o|d}qqWdS( sProcess a section of a source document, looking for high level structural elements like lists, block quotes, code segments, html blocks, etc. Some those then get stripped of their high level markup (e.g. get unindented) and the lower-level markup is processed recursively. @param parent_elem: A NanoDom element to which the content will be added @param lines: a list of lines @param inList: a level @returns: NoneR RRRiNcSs9tidi|p"tidi|p |i S(R R(RRRR(R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt_sit looseListcSs |i S((R(R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRfjsR(t _processUListt _processOListt _processQuotet_processCodeBlockRRRt _linesUntilRbRRt_processHeadert_processParagraphR( R>t parent_elemRtinListRgt processFnR[Rtstartt paragraph((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRb.s2      ! cCstidi|d}|ort|id}|iid|}|i|xD|i|idi D]}|i|qxWnt t ddS(NRiish%disWe've got a problem header!( RRRRRRIRMRFt _handleInlineRR R(R>RoRsRR R+R((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRmxs cCs|idi|}|idjo|p|i o |}n |iid}|i|x|D]}|i|qjWdS(Ns RR(RtRRhRkRIRMRF(R>RoRsRpRgtlistRLR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRns  cCs#|i|||dddddS(NtlistexprR R.(t _processList(R>RoRRp((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRhscCs#|i|||dddddS(NRvRR.(Rw(R>RoRRp((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRisc CsS|ii|}|i|d}g}d} d} x|D]} d} | ip| d7} d} x>t| t|D]&} || io|| }Pq}q}WPtidi|p.tidi|ptidi|o+|| i | i| p|}q>qPnxdddgD]}ti|i| }|on|d jo'|i |i dg| d7} n,|djo|| i |i dn| d7} Pq-q-W|| i | | d7} q>W| d7} xJ|D]B} |iid}|i||i || |dd |qW|i ||| |d S( s{Given a list of document lines starting with a list item, finds the end of the list, breaks it up, and recursively processes each list item and the remainder of the text file. @param parent_elem: A dom element to which the content will be added @param lines: a list of lines @param inList: a level @returns: NoneiiiR RRiRRgN(sulsol( RIRMRFRRRRRRRmRRb(R>RoRRpRvR.R RgRRRRtlooseRRtexprRR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRwsZ             !cCsOd}x4|D]"}|d7}||oPq q W|d7}|| ||fS(s A utility function to break a list of lines upon the first line that satisfied a condition. The condition argument should be a predicate function. ii((R>Rt conditionRR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRls   c Cs*g}d}t}x|D]}tidi|}|o*|i|id|d7}t}q| o.|idjo|i||d7}q| o4|idjo!|i||d7}t}qPqW|ii d} |i | |i | |||i ||||dS(sGiven a list of document lines starting with a quote finds the end of the quote, unindents it and recursively processes the body of the quote and the remainder of the text file. @param parent_elem: DOM element to which the content will be added @param lines: a list of lines @param inList: a level @returns: None iRiR|RN( RcRRRRmRRRARIRMRFRb( R>RoRRptdequotedRt blank_lineRRR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRjs,        c Cs|ii|\}}|iid}|iid}|i||i|di|id}|i|ii||i|||dS(sGiven a list of document lines starting with a code block finds the end of the block, puts it into the dom verbatim wrapped in ("
") and recursively processes the
           the remainder of the text file.

           @param parent_elem: DOM element to which the content will be added
           @param lines: a list of lines
           @param inList: a level
           @returns: NoneRRs
N(	R(RRIRMRFRRRJRb(	R>RoRRptdetabbedttheRestRRR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRk*s

cCs>|g}x|t|ijod}x|t|jo||}t|ttfog|i||i||}|o@|d8}|i|x&|D]}|i|d|qWqn|d7}q+W|d7}qWxTtt|D]@}||}t|ttfo|i	i
|||RtpatternIndexRRRtresultty((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRtBs2	
	
	

 
c
Cs|ii|}|pdS|i||i}t|to|idjox|iD]}t|t	o|i
|i|d}|o||gjoq`n|i|ii
|}|i|xo|D]c}	t|	ttfo7t|	djo |i||ii|	q@q|i||	qWqLq`q`WqXn|o!|id||idfSdSdS(s Given a pattern name, this function checks if the line
        fits the pattern, creates the necessary elements, and returns
        back a list consisting of NanoDom elements and/or strings.
        
        @param line: the text to be processed
        @param pattern: the pattern to be checked

        @returns: the appropriate newly created NanoDom element if the
                  pattern matches, None otherwise.
        RRiiiN(scodespre(RRR5RRIRRHRhRkRNRtRotreverseRvRuRRRRsRJtgroupsR(
R>RRRRRORERRrR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRns8


	(
c
Cs|dj	o
||_n|ipdSyt|i|_Wn!tj
ottddSXx&|iD]}|i|i|_qmW|i}|i	}|i
o|idd!d}nx |iD]}|i|}qW|i
|iS(sPReturn the document in XHTML format.

        @returns: A serialized XHTML body.usBUnicodeDecodeError: Markdown only accepts unicode or ascii  input.iis
N(R5R'RtUnicodeDecodeErrorR
RR-RReRUR*RR4R+(R>R'tppRItxml((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyRs(






cCsT|idjo
d}n*dt|i|iiddf}d|i|fS(s> Report info about instance. Markdown always returns unicode. s*in which no source text has been assinged.s1which contains %d chars and %d line(s) of source.s
isAn instance of "%s" %sN(R'R5Rtcountt	__class__(R>tstatus((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt__str__s

&N(RaRbRR5RcR?RLRZRMReRbRmRnRhRiRwRlRjRkRtRRRt__unicode__(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR$|s.B				5I					U		'	,	E#		c
Csti|ttd||p
d}nti|ddd|}|i}|it||}t	||d|}|o3ti|dd|}	|	i
||	intii
|i
|dS(Nsinput file: %ssutf-8tmodetrRROtw(t
console_hndlrtsetLevelR
RtcodecstopentreadtcloseRR^RRtstdouttencode(
tinputtoutputR%Rtmessage_thresholdRt
input_fileRRtoutput_file((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pytmarkdownFromFiles



c
Csttd|g}h}x|D]}|id}|djo|i|q$|| }|i|g}||dd!idD]}	||	idq~}
g}|
D]%\}	}||	i|ifq~}
|
||9	t	ExtensioncBs/eZhdZdZdZdZRS(cCs
||_dS(N(tconfig(R>R&((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR?#scCs+|ii|o|i|dSdSdS(NiR|(RR(R>R#((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt	getConfig&scCs9g}|iiD]}|||i|dfq~S(Ni(RR!(R>RR#((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt
getConfigInfo,scCs||i|dR#Ro((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt	setConfig/s(RaRbR?RRR(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyR!s		s
Python 2.3 or higher required for advanced command line options.
For lower versions of Python use:

      %s INPUT_FILE > OUTPUT_FILE
    
cCsytd}Wn\ttidjo6htidd6dd6td6td6gd6dd	6StGHdSnX|id
d}|i	dd
dddddd|i	dddd	dd|i	dddtdddddddd|i	d d!dddt
dddd"|i	d#d$dddtdd%dd&|i	d'dddtdddd(|i	d)d*dd+dddd,dd-|i\}}t|djp|i
dS|d.}|ip
g|_nh|d6|id6|id6|id6|id6|id	6S(/NtoptparseiiRRRRR%Rtusages%prog INPUTFILE [options]s-fs--filetdesttfilenamethelpswrite output to OUTPUT_FILEtmetavartOUTPUT_FILEs-es
--encodings#encoding for input and output filess-qs--quiettdefaulttactiontstore_consttconsti<tverbosessuppress all messagess-vs	--verbosesprint info messagess-ss--safet	SAFE_MODEs<same mode ('replace', 'remove' or 'escape'  user's HTML tag)s--noisysprint debug messagess-xs--extensionRmsload extension EXTENSIONt	EXTENSIONi(RQRRtargvR5RRctOPTPARSE_WARNINGtOptionParsert
add_optionRRt
parse_argst
print_helpR%RRRR(RtparsertoptionstargsR((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyt
parse_options;sZ	









t__main__(tversiontversion_infot__revision__RRRtloggingRRRRRRRRtMESSAGE_THRESHOLDR	RRt	formattertsetFormattert
addHandlerR
RaRARtSMART_EMPHASISRR7tBOM_UTF8tBOM_UTF16_LEtBOM_UTF16_BERRtEXECUTABLE_NAME_FOR_USAGERRR-R/RRWRVR;R<RSRHRNRPRRRR,RR.RR/RR0t	NOBRACKETtBRKtNOIMGtBACKTICK_REtDOUBLE_BACKTICK_REt	ESCAPE_REtEMPHASIS_REt	STRONG_REtSTRONG_EM_REt
EMPHASIS_2_REtSTRONG_2_REtSTRONG_EM_2_REtLINK_REtLINK_ANGLED_REt
IMAGE_LINK_REtREFERENCE_REtIMAGE_REFERENCE_REt
NOT_STRONG_REtAUTOLINK_REtAUTOMAIL_REtHTML_REt	ENTITY_REt
LINE_BREAK_REtLINE_BREAK_2_RERtBasePatternRRRRRRRRRRRRR8RDR7R6RGRHRIRJRERFRAR@R;R:R<R=R9RBRCR>R?RRRR3R	RRRRRR$R5RcRR^RRRRaRtexit(((s7/usr/lib/python2.6/site-packages/webhelpers/markdown.pyts$:
	


			

		;
_	!			/&
			M			m
	: