Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
proc
/
thread-self
/
root
/
usr
/
lib
/
python2.7
/
site-packages
/
markdown
/
extensions
/
File Content:
fenced_code.pyc
� �(�Sc @@ s� d Z d d l m Z d d l m Z d d l m Z d d l m Z d d l m Z m Z m Z d d l Z d e f d � � YZ d e f d � � YZ d d � Z d 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 <p>A paragraph before a fenced code block:</p> <pre><code>Fenced code block </code></pre> Works with safe_mode also (we check this because we are using the HtmlStash): >>> print markdown.markdown(text, extensions=['fenced_code'], safe_mode='replace') <p>A paragraph before a fenced code block:</p> <pre><code>Fenced code block </code></pre> Include tilde's in a code block and wrap with blank lines: >>> text = ''' ... ~~~~~~~~ ... ... ~~~~ ... ~~~~~~~~''' >>> print markdown.markdown(text, extensions=['fenced_code']) <pre><code> ~~~~ </code></pre> Language tags: >>> text = ''' ... ~~~~{.python} ... # Some python code ... ~~~~''' >>> print markdown.markdown(text, extensions=['fenced_code']) <pre><code class="python"># Some python code </code></pre> 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']) <pre><code># Arbitrary code ~~~~~ # these tildes will not close the block </code></pre> 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']) <pre><code><span class="hilight">line 1</span> line 2 <span class="hilight">line 3</span> </code></pre> Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/). Project website: <http://packages.python.org/Markdown/extensions/fenced_code_blocks.html> 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 ( t absolute_import( t unicode_literalsi ( t Extensioni ( t Preprocessor( t CodeHilitet CodeHiliteExtensiont parse_hl_linesNt FencedCodeExtensionc B@ s e Z d � Z RS( c C@ s- | j | � | j j d t | � d � d S( u7 Add FencedBlockPreprocessor to the Markdown instance. u fenced_code_blocku >normalize_whitespaceN( t registerExtensiont preprocessorst addt FencedBlockPreprocessor( t selft mdt md_globals( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyt extendMarkdownd s ( t __name__t __module__R ( ( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR b s R c B@ sR e Z e j d e j e j Be j B� Z d Z d Z d � Z d � Z d � Z RS( uT (?P<fence>^(?:~{3,}|`{3,}))[ ]* # Opening ``` or ~~~ (\{?\.?(?P<lang>[a-zA-Z0-9_+-]*))?[ ]* # Optional {, and lang # Optional highlight lines, single- or double-quote-delimited (hl_lines=(?P<quot>"|')(?P<hl_lines>.*?)(?P=quot))?[ ]* }?[ ]*\n # Optional closing } (?P<code>.*?)(?<=\n) (?P=fence)[ ]*$u <pre><code%s>%s</code></pre>u class="%s"c C@ s, t t | � j | � t | _ i | _ d S( N( t superR t __init__t Falset checked_for_codehilitet codehilite_conf( R R ( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR y s c C@ s� | j sK x3 | j j D]% } t | t � r | j | _ Pq q Wt | _ n d j | � } x`| j j | � } | r�d } | j d � r� | j | j d � } n | j rOt | j d � d | j d d d | j d d d | j d d d | j d d d | j d � pd d | j d d d t | j d � � �} | j � } n% | j | | j | j d � � f } | j j j | d t �} d | | j � | | | j � f } q] Pq] | j d � S( u6 Match and store Fenced Code Blocks in the HtmlStash. u u u langu codet linenumsu linenumsi t guess_langu guess_langt css_classu css_classt styleu pygments_stylet langt noclassesu noclassest hl_linesu hl_linest safeu %s %s %sN( R t markdownt registeredExtensionst isinstanceR t configR t Truet joint FENCED_BLOCK_REt searcht groupt LANG_TAGR t NoneR t hilitet CODE_WRAPt _escapet htmlStasht storet startt endt split( R t linest extt textt mR t highlitert codet placeholder( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyt run s8 %*c C@ sL | j d d � } | j d d � } | j d d � } | j d d � } | S( u basic html escaping u &u &u <u <u >u >u "u "( t replace( R t txt( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR, � s ( R R t ret compilet MULTILINEt DOTALLt VERBOSER% R+ R( R R9 R, ( ( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyR m s *c C@ s t d | � S( Nt configs( R ( RA ( ( sC /usr/lib/python2.7/site-packages/markdown/extensions/fenced_code.pyt makeExtension� s ( t __doc__t __future__R R t R R R t codehiliteR R R R<