σ Šη\c@@sͺdZddlmZddlmZddlmZddlmZddlm Z m Z m Z dd l Z d efd „ƒYZ d efd „ƒYZd d„Zd S(un Fenced Code Extension for Python Markdown ========================================= This extension adds Fenced Code Blocks to Python-Markdown. >>> import markdown >>> text = ''' ... A paragraph before a fenced code block: ... ... ~~~ ... Fenced code block ... ~~~ ... ''' >>> html = markdown.markdown(text, extensions=['fenced_code']) >>> print html

A paragraph before a fenced code block:

Fenced code block
    
Works with safe_mode also (we check this because we are using the HtmlStash): >>> print markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace')

A paragraph before a fenced code block:

Fenced code block
    
Include tilde's in a code block and wrap with blank lines: >>> text = ''' ... ~~~~~~~~ ... ... ~~~~ ... ~~~~~~~~''' >>> print markdown.markdown(text, extensions=['fenced_code'])

    ~~~~
    
Language tags: >>> text = ''' ... ~~~~{.python} ... # Some python code ... ~~~~''' >>> print markdown.markdown(text, extensions=['fenced_code'])
# Some python code
    
Optionally backticks instead of tildes as per how github's code block markdown is identified: >>> text = ''' ... ````` ... # Arbitrary code ... ~~~~~ # these tildes will not close the block ... `````''' >>> print markdown.markdown(text, extensions=['fenced_code'])
# Arbitrary code
    ~~~~~ # these tildes will not close the block
    
If the codehighlite extension and Pygments are installed, lines can be highlighted: >>> text = ''' ... ```hl_lines="1 3" ... line 1 ... line 2 ... line 3 ... ```''' >>> print markdown.markdown(text, extensions=['codehilite', 'fenced_code'])
line 1
    line 2
    line 3
    
Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). Project website: Contact: markdown@freewisdom.org License: BSD (see ../docs/LICENSE for details) Dependencies: * [Python 2.4+](http://python.org) * [Markdown 2.0+](http://packages.python.org/Markdown/) * [Pygments (optional)](http://pygments.org) i(tabsolute_import(tunicode_literalsi(t Extensioni(t Preprocessor(t CodeHilitetCodeHiliteExtensiontparse_hl_linesNtFencedCodeExtensioncB@seZd„ZRS(cC@s-|j|ƒ|jjdt|ƒdƒdS(u7 Add FencedBlockPreprocessor to the Markdown instance. ufenced_code_blocku>normalize_whitespaceN(tregisterExtensiont preprocessorstaddtFencedBlockPreprocessor(tselftmdt md_globals((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pytextendMarkdownds   (t__name__t __module__R(((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyRbsR cB@sReZejdejejBejBƒZdZdZ d„Z d„Z d„Z RS(uT (?P^(?:~{3,}|`{3,}))[ ]* # Opening ``` or ~~~ (\{?\.?(?P[a-zA-Z0-9_+-]*))?[ ]* # Optional {, and lang # Optional highlight lines, single- or double-quote-delimited (hl_lines=(?P"|')(?P.*?)(?P=quot))?[ ]* }?[ ]*\n # Optional closing } (?P.*?)(?<=\n) (?P=fence)[ ]*$u
%s
u class="%s"cC@s,tt|ƒj|ƒt|_i|_dS(N(tsuperR t__init__tFalsetchecked_for_codehilitetcodehilite_conf(R R ((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyRys c C@sΚ|jsKx3|jjD]%}t|tƒr|j|_PqqWt|_ndj|ƒ}x`|j j |ƒ}|rΉd}|j dƒr£|j |j dƒ}n|jrOt |j dƒd|jddd|jd dd |jd dd |jd dd|j dƒpdd|jdddt|j dƒƒƒ}|jƒ}n%|j||j|j dƒƒf}|jjj|dtƒ}d||jƒ |||jƒf}q]Pq]|jdƒS(u6 Match and store Fenced Code Blocks in the HtmlStash. u uulangucodetlinenumsulinenumsit guess_langu guess_langt css_classu css_clasststyleupygments_styletlangt noclassesu noclassesthl_linesuhl_linestsafeu%s %s %sN(RtmarkdowntregisteredExtensionst isinstanceRtconfigRtTruetjointFENCED_BLOCK_REtsearchtgrouptLANG_TAGRtNoneRthilitet CODE_WRAPt_escapet htmlStashtstoretstarttendtsplit( R tlinestextttexttmRt highlitertcodet placeholder((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pytruns8    %*cC@sL|jddƒ}|jddƒ}|jddƒ}|jddƒ}|S( u basic html escaping u&u&uu>u"u"(treplace(R ttxt((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR,©s ( RRtretcompilet MULTILINEtDOTALLtVERBOSER%R+R(RR9R,(((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR ms  *cC@s td|ƒS(Ntconfigs(R(RA((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyt makeExtension²s(t__doc__t __future__RRtRR Rt codehiliteRRRR<RR R)RB(((sC/usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pytXs  E