Xc@sdZddkZy eiZWnej o dZnXdd dYZdeiifdYZdeifd YZ hd Z dS( s CodeHilite Extension for Python-Markdown ======================================== Adds code/syntax highlighting to standard Python-Markdown code blocks. Copyright 2006-2008 [Waylan Limberg](http://achinghead.com/). Project website: Contact: markdown@freewisdom.org License: BSD (see ../docs/LICENSE for details) Dependencies: * [Python 2.3+](http://python.org/) * [Markdown 2.0+](http://www.freewisdom.org/projects/python-markdown/) * [Pygments](http://pygments.org/) iNit CodeHilitecBsDeZdZdeddZdZdZdZdZ RS(s Determine language of source code, and pass it into the pygments hilighter. Basic Usage: >>> code = CodeHilite(src = 'some text') >>> html = code.hilite() * src: Source string or any object with a .readline attribute. * linenos: (Boolen) Turn line numbering 'on' or 'off' (off by default). * css_class: Set class name of wrapper div ('codehilite' by default). Low Level Usage: >>> code = CodeHilite() >>> code.src = 'some text' # String or anything with a .readline attr. >>> code.linenos = True # True or False; Turns line numbering on or of. >>> html = code.hilite() t codehilitecCs(||_d|_||_||_dS(N(tsrctNonetlangtlinenost css_class(tselfRRR((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyt__init__7s   c CsE|iid|_|iy@ddkl}ddkl}l}l}ddk l }WnVt j oJ|i |i}|i o|i|}nd|i|f}|SXy||i}WnEtj o9y||i}Wqtj o|}qXnX|d|i d|i}||i||Sd S( s? Pass code to the [Pygments](http://pygments.pocoo.org/) highliter with optional line numbers. The output should then be styled with css to your liking. No styles are applied by default - only styling hooks (i.e.: ). returns : A string of html. s i(t highlight(tget_lexer_by_namet guess_lexert TextLexer(t HtmlFormatters$
%s
RtcssclassN(Rtstript_getLangtpygmentsR tpygments.lexersR R R tpygments.formattersR t ImportErrort_escapeRt_numberRRt ValueError( RR R R R R ttxttlexert formatter((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pythilite=s.    cCsL|idd}|idd}|idd}|idd}|S( s basic html escaping t&s&ts>t"s"(treplace(RR((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyRfs cCs|iddt}|id d}|id d}|idd}|i}d }x|D]}|d |7}qeW|d 7}|S(s Use
    for line numbering s t is    is    is  s"
      s
    1. %s
    2. s
    s s s (R t TAB_LENGTHt splitlines(RRtlinestline((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyRns  cCsddk}|iid}|id}|id|i}|i|}|oy|idi|_ Wnt j od|_ nX|ido|i d|n|ido t |_qn|i d|di|id|_dS( s Determines language of a code block from shebang lines and whether said line should be removed or left in place. If the sheband line contains a path (even a single /) then it is assumed to be a real shebang lines and left alone. However, if no path is given (e.i.: #!python or :::python) then it is assumed to be a mock shebang for language identifitation of a code fragment and removed from the code block prior to processing for code highlighting. When a mock shebang (e.i: #!python) is found, line numbering is turned on. When colons are found in place of a shebang (e.i.: :::python), line numbering is left in the current state - off by default. iNs is (?:(?:::+)|(?P[#]!)) # Shebang or 2 or more colons. (?P(?:/\w+)*[/ ])? # Zero or 1 path (?P[\w+-]*) # The language Rtpathtshebang(treRtsplittpoptcompiletVERBOSEtsearchtgrouptlowerRt IndexErrorRtinserttTrueRtjoinR(RR(R$tfltctm((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyRs" N( t__name__t __module__t__doc__RtFalseRRRRR(((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyR!s  )  tHiliteTreeprocessorcBseZdZdZRS(s% Hilight source code in code blocks. cCs|id}x|D]}|i}t|djo|didjovt|did|iddd|idd}|iii |i dt }|i d |_||_qqWd S( s* Find code blocks and store in htmlStash. tpreiitcodeRt force_linenosRtsafetpN( t getiteratort getchildrentlenttagRttexttconfigtmarkdownt htmlStashtstoreRR2tclear(RtroottblockstblocktchildrenR=t placeholder((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pytruns '   (R7R8R9RP(((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyR;stCodeHiliteExtensioncBs eZdZdZdZRS(s4 Add source code hilighting to markdown codeblocks. cCsNhtdgd6ddgd6|_x$|D]\}}|i||q*WdS(Ns#Force line numbers - Default: FalseR>Rs6Set class name for wrapper
    - Default: codehiliteR(R:RFt setConfig(Rtconfigstkeytvalue((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyRs  cCs2t|}|i|_|iid|ddS(s/ Add HilitePostprocessor to Markdown instance. Rt_beginN(R;RFttreeprocessorstadd(Rtmdt md_globalsthiliter((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pytextendMarkdowns  (R7R8R9RR\(((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyRQs cCs td|S(NRS(RQ(RS((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyt makeExtensions(( R9RGR"tAttributeErrorRRWt TreeprocessorR;t ExtensionRQR](((sB/usr/lib/python2.6/site-packages/markdown/extensions/codehilite.pyts