Ñò éíÑXc@s‚dZddkZddkZddklZlZddkZeidjoddklZ n ddk Z dZ de dd e d d e d Z d Z d Z dZdZdZdZeio dZndZe e dZde dZe e dZde dZdZdZdZdZdZdZdZd„Zei d ƒZ!d!„Z"d"d<d#„ƒYZ#e#Z$d$e#fd%„ƒYZ%d&e#fd'„ƒYZ&d(e&fd)„ƒYZ'd*e#fd+„ƒYZ(d,e&fd-„ƒYZ)d.e#fd/„ƒYZ*d0e#fd1„ƒYZ+d2e+fd3„ƒYZ,d4e+fd5„ƒYZ-d6e-fd7„ƒYZ.d8e#fd9„ƒYZ/d:e#fd;„ƒYZ0dS(=sƒ INLINE PATTERNS ============================================================================= Inline patterns such as *emphasis* are handled by means of auxiliary objects, one per pattern. Pattern objects must be instances of classes that extend markdown.Pattern. Each pattern object uses a single regular expression and needs support the following methods: pattern.getCompiledRegExp() # returns a regular expression pattern.handleMatch(m) # takes a match object and returns # an ElementTree element or just plain text All of python markdown's built-in patterns subclass from Pattern, but you can add additional patterns that don't. Also note that all the regular expressions used by inline must capture the whole block. For this reason, they all start with '^(.*)' and end with '(.*)!'. In case with built-in expression Pattern takes care of adding the "^(.*)" and "(.*)!". Finally, the order in which regular expressions are applied is very important - e.g. if we first replace http://.../ links with tags and _then_ try to replace inline html, we would end up with a mess. So, we apply the expressions in the following order: * escape and backticks have to go before everything else, so that we can preempt any markdown patterns by escaping them. * then we handle auto-links (must be done before inline html) * then we handle inline HTML. At this point we will simply replace all inline HTML strings with a placeholder and add the actual HTML to a hash. * then inline images (must be done before links) * then bracketed links, first regular then reference-style * finally we apply strong and emphasis iÿÿÿÿN(turlparset urlunparses3.0(tentitiess[^\]\[]*s\[(s(\[is\])*s)\]s(?\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*?)\12)?\)s\!s\s*\((<.*?>|([^\)]*))\)s\s*\[([^\]]*)\]s((^| )(\*|_)( |$))s<((?:f|ht)tps?://[^>]*)>s<([^> \!]*@[^> ]*)>s"(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)s(&[\#a-zA-Z0-9]*;)s \ns $cCsT|idƒo|idƒp |idƒo|idƒo |dd!S|SdS(s#Remove quotes from around a string.t"t'iiÿÿÿÿN(t startswithtendswith(tstring((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pytdequote^s   s\{@([^\}]*)=([^\}]*)}cs‡fd†}ti||ƒS(sDSet values of an element based on attribute definitions ({@id=123}).cs2ˆi|idƒ|idƒiddƒƒdS(Niis t (tsettgrouptreplace(tmatch(tparent(s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pytattributeCallbackjs(tATTR_REtsub(ttextRR((Rs;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pythandleAttributeshstPatterncBs5eZdZdd„Zd„Zd„Zd„ZRS(s*Base class that inline patterns subclass. cCsF||_tid|tiƒ|_t|_|o ||_ndS(s– Create an instant of an inline pattern. Keyword arguments: * pattern: A regular expression that matches a pattern s^(.*?)%s(.*?)$N(tpatterntretcompiletDOTALLt compiled_retFalset safe_modetmarkdown(tselfRtmarkdown_instance((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyt__init__ws  cCs|iS(s' Return a compiled regular expression. (R(R((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pytgetCompiledRegExpˆscCsdS(sÌReturn a ElementTree element from the given match. Subclasses should override this method. Keyword arguments: * m: A re match object containing a match of the pattern. N((Rtm((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyt handleMatchŒs cCs |iiS(s+ Return class name, to define pattern type (t __class__t__name__(R((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyttype˜sN(R$t __module__t__doc__tNoneRR R"R%(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRts    tSimpleTextPatterncBseZdZd„ZRS(s0 Return a simple text of group(2) of a Pattern. cCs(|idƒ}|tijodS|S(Ni(R RtINLINE_PLACEHOLDER_PREFIXR((RR!R((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR" s(R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR)žstSimpleTagPatterncBs eZdZd„Zd„ZRS(s[ Return element of type `tag` with a text attribute of group(3) of a Pattern. cCsti||ƒ||_dS(N(RRttag(RRR,((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR¬scCs+tii|iƒ}|idƒ|_|S(Ni(RtetreetElementR,R R(RR!tel((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"°s(R$R&R'RR"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR+¦s tSubstituteTagPatterncBseZdZd„ZRS(s2 Return a eLement of type `tag` with no children. cCstii|iƒS(N(RR-R.R,(RR!((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"¸s(R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR0¶stBacktickPatterncBs eZdZd„Zd„ZRS(s9 Return a `` element containing the matching text. cCsti||ƒd|_dS(Ntcode(RRR,(RR((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR¾scCs:tii|iƒ}ti|idƒiƒƒ|_|S(Ni(RR-R.R,t AtomicStringR tstripR(RR!R/((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"Âs!(R$R&R'RR"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR1¼s tDoubleTagPatterncBseZdZd„ZRS(sfReturn a ElementTree element nested in tag2 nested in tag1. Useful for strong emphasis etc. cCsU|iidƒ\}}tii|ƒ}tii||ƒ}|idƒ|_|S(Nt,i(R,tsplitRR-R.t SubElementR R(RR!ttag1ttag2tel1tel2((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"Îs (R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR5Èst HtmlPatterncBseZdZd„ZRS(s1 Store raw inline html and return a placeholder. cCs.|idƒ}t}|iii|ƒ}|S(Ni(R tTrueRt htmlStashtstore(RR!trawhtmltinlinet place_holder((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"Øs(R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR=Öst LinkPatterncBs eZdZd„Zd„ZRS(s- Return a link element from the given match. cCsÉtiidƒ}|idƒ|_|idƒ}|idƒ}|oE|ddjo|dd!}n|id |i|iƒƒƒn|id d ƒ|o t|ƒ}|id |ƒn|S( Ntaii i it), we whitelist known safe url formats. Most urls contain a network location, however some are known not to (i.e.: mailto links). Script urls do not contain a location. Additionally, for `javascript:...`, the scheme would be "javascript" but some aliases will appear to `urlparse()` to have no scheme. On top of that relative links (i.e.: "foo/bar.html") have no scheme. Therefore we must check "path", "parameters", "query" and "fragment" for any literal colons. We don't check "scheme" for colons because it *should* never have any and "netloc" must allow the form: `username:password@host:port`. RHtmailtotnewsit:N(RRR>RtsafeModeR( Rturltlocless_schemestschemetnetloctpathtparamstquerytfragmenttsafe_urltpart((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRJós"   (R$R&R'R"RJ(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRDßs t ImagePatterncBseZdZd„ZRS(s, Return a img element from the given match. cCstiidƒ}|idƒiƒ}|oZ|d}|ddjo"|ddjo|dd!}n|id|i|ƒƒn|idd ƒt|ƒdjo'|id td i |dƒƒƒnti ot |id ƒ|ƒ}n|id ƒ}|id |ƒ|S(Ntimgi iRFiÿÿÿÿt>itsrcRHRIR italt( RR-R.R R7R RJtlenRtjointENABLE_ATTRIBUTESR(RR!R/t src_partsR\ttruealt((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"s "' (R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRYstReferencePatterncBs eZdZd„Zd„ZRS(s6 Match to a stored reference and return link element. cCsŽ|idƒo|idƒiƒ}n|idƒiƒ}||iijodS|ii|\}}|idƒ}|i|||ƒS(Ni i(R tlowerRt referencesR(tmakeTag(RR!tidRGRIR((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR",scCsStiidƒ}|id|i|ƒƒ|o|id|ƒn||_|S(NRERGRI(RR-R.R RJR(RRGRIRR/((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRf;s  (R$R&R'R"Rf(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRc*s tImageReferencePatterncBseZdZd„ZRS(s5 Match to a stored reference and return img element. cCsZtiidƒ}|id|i|ƒƒ|o|id|ƒn|id|ƒ|S(NRZR\RIR](RR-R.R RJ(RRGRIRR/((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRfHs (R$R&R'Rf(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRhFstAutolinkPatterncBseZdZd„ZRS(sC Return a link Element given an autolink (``). cCsJtiidƒ}|id|idƒƒti|idƒƒ|_|S(NRERGi(RR-R.R R R3R(RR!R/((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"Ss(R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRiQstAutomailPatterncBseZdZd„ZRS(sT Return a mailto link Element given an automail link (``). c Csïtiidƒ}|idƒ}|idƒo|tdƒ}nd„}g}|D]}||t|ƒƒqY~}tidi|ƒƒ|_ d|}dig} |D]}| ti dt|ƒq±~ ƒ}|i d|ƒ|S(NREismailto:cSs@tii|ƒ}|odti|fSdti|fSdS(s=Return entity definition by code, or the code if not defined.s%s%s;s%s#%d;N(thtmlentitydefstcodepoint2nametgetRtAMP_SUBSTITUTE(R2tentity((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRlcsRHs#%d;RG( RR-R.R RR^tordR3R_RRnR ( RR!R/temailRlt_[1]tlettertlettersRKt_[2]((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyR"]s -  .(R$R&R'R"(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyRjYs((1R'RRRRtsystversionthtmlRRkt NOBRACKETtBRKtNOIMGt BACKTICK_REt ESCAPE_REt EMPHASIS_REt STRONG_REt STRONG_EM_REtSMART_EMPHASISt EMPHASIS_2_REtLINK_REt IMAGE_LINK_REt REFERENCE_REtIMAGE_REFERENCE_REt NOT_STRONG_REt AUTOLINK_REt AUTOMAIL_REtHTML_REt ENTITY_REt LINE_BREAK_REtLINE_BREAK_2_RERRRRRt BasePatternR)R+R0R1R5R=RDRYRcRhRiRj(((s;/usr/lib/python2.6/site-packages/markdown/inlinepatterns.pyt*s^    &    (  4