§
    Ó¼Ñbo2  ã                   óâ   — 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 dd	lmZ dd
lmZ dZn# e$ r dZY nw xY wd„ Z G d„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zd„ ZdS )aº  
CodeHilite Extension for Python-Markdown
========================================

Adds code/syntax highlighting to standard Python-Markdown code blocks.

See <https://Python-Markdown.github.io/extensions/code_hilite>
for documentation.

Original code Copyright 2006-2008 [Waylan Limberg](http://achinghead.com/).

All changes Copyright 2008-2014 The Python Markdown Project

License: [BSD](https://opensource.org/licenses/bsd-license.php)

é   )Ú	Extensioné   )ÚTreeprocessor)ÚparseBoolValueé    )Ú	highlight)Úget_lexer_by_nameÚguess_lexer)Úget_formatter_by_name)ÚClassNotFoundTFc                 ó˜   — | sg S 	 t          t          t          |                      ¦   «         ¦  «        ¦  «        S # t          $ r g cY S w xY w)zÄSupport our syntax for emphasizing certain lines of code.

    expr should be like '1 2' to emphasize lines 1 and 2 of a code block.
    Returns a list of ints, the line numbers to emphasize.
    )ÚlistÚmapÚintÚsplitÚ
ValueError)Úexprs    ú@/usr/lib/python3/dist-packages/markdown/extensions/codehilite.pyÚparse_hl_linesr       sZ   € ð ð Øˆ	ðÝ•C�˜TŸZšZ™\œ\Ñ*Ô*Ñ+Ô+Ð+øÝð ð ð Øˆ	ˆ	ˆ	ðøøøs   †3: ºA	ÁA	c                   ó&   — e Zd ZdZd„ Zdd„Zd„ ZdS )Ú
CodeHilitea	  
    Determine language of source code, and pass it on to the Pygments highlighter.

    Usage:
        code = CodeHilite(src=some_code, lang='python')
        html = code.hilite()

    Arguments:
    * src: Source string or any object with a .readline attribute.

    * lang: String name of Pygments lexer to use for highlighting. Default: `None`.

    * guess_lang: Auto-detect which lexer to use. Ignored if `lang` is set to a valid
      value. Default: `True`.

    * use_pygments: Pass code to pygments for code highlighting. If `False`, the code is
      instead wrapped for highlighting by a JavaScript library. Default: `True`.

    * pygments_formatter: The name of a Pygments formatter or a formatter class used for
      highlighting the code blocks. Default: `html`.

    * linenums: An alias to Pygments `linenos` formatter option. Default: `None`.

    * css_class: An alias to Pygments `cssclass` formatter option. Default: 'codehilite'.

    * lang_prefix: Prefix prepended to the language. Default: "language-".

    Other Options:
    Any other options are accepted and passed on to the lexer and formatter. Therefore,
    valid options include any options which are accepted by the `html` formatter or
    whichever lexer the code's language uses. Note that most lexers do not have any
    options. However, a few have very useful options, such as PHP's `startinline` option.
    Any invalid options are ignored without error.

    Formatter options: https://pygments.org/docs/formatters/#HtmlFormatter
    Lexer Options: https://pygments.org/docs/lexers/

    Additionally, when Pygments is enabled, the code's language is passed to the
    formatter as an extra option `lang_str`, whose value being `{lang_prefix}{lang}`.
    This option has no effect to the Pygments's builtin formatters.

    Advanced Usage:
        code = CodeHilite(
            src = some_code,
            lang = 'php',
            startinline = True,      # Lexer option. Snippet does not start with `<?php`.
            linenostart = 42,        # Formatter option. Snippet starts on line 42.
            hl_lines = [45, 49, 50], # Formatter option. Highlight lines 45, 49, and 50.
            linenos = 'inline'       # Formatter option. Avoid alignment problems.
        )
        html = code.hilite()

    c                 óÀ  — || _         |                     dd ¦  «        | _        |                     dd¦  «        | _        |                     dd¦  «        | _        |                     dd¦  «        | _        |                     dd¦  «        | _        d	|vr|                     d
d ¦  «        |d	<   d|vr|                     dd¦  «        |d<   d|vrd|d<   d|d<   || _        d S )NÚlangÚ
guess_langTÚuse_pygmentsÚlang_prefixú	language-Úpygments_formatterÚhtmlÚlinenosÚlinenumsÚcssclassÚ	css_classÚ
codehiliteÚwrapcodeFÚfull)ÚsrcÚpopr   r   r   r   r   Úoptions)Úselfr'   r)   s      r   Ú__init__zCodeHilite.__init__g   så   € ØˆŒØ—K’K ¨Ñ-Ô-ˆŒ	Ø!Ÿ+š+ l°DÑ9Ô9ˆŒØ#ŸKšK¨¸Ñ=Ô=ˆÔØ"Ÿ;š; }°kÑBÔBˆÔØ")§+¢+Ð.BÀFÑ"KÔ"KˆÔà˜GÐ#Ð#Ø!(§¢¨Z¸Ñ!>Ô!>ˆG�IÑØ˜WÐ$Ð$Ø")§+¢+¨k¸<Ñ"HÔ"HˆG�JÑØ˜WÐ$Ð$à"&ˆG�JÑàˆ�‰àˆŒˆˆó    Tc                 óò  — | j                              d¦  «        | _         | j        €|r|                      ¦   «          t          �r+| j        �r#	 t          | j        fi | j        ¤Ž}nc# t          $ rV 	 | j	        rt          | j         fi | j        ¤Ž}nt          di | j        ¤Ž}n!# t          $ r t          di | j        ¤Ž}Y nw xY wY nw xY w| j        s|j        d         | _        | j        › | j        › �}t          | j        t          ¦  «        r:	 t!          | j        fi | j        ¤Ž}n5# t"          $ r t!          di | j        ¤Ž}Y nw xY w | j        dd|i| j        ¤Ž}t%          | j         ||¦  «        S | j                              dd¦  «        }|                     d	d
¦  «        }|                     dd¦  «        }|                     dd¦  «        }g }| j        r3|                     d                     | j        | j        ¦  «        ¦  «         | j        d         r|                     d¦  «         d}|r(d                     d                     |¦  «        ¦  «        }d                     | j        d         ||¦  «        S )a7  
        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.: <span class="k">).

        returns : A string of html.

        ú
NÚtextr   r   Úlang_strú&ú&amp;ú<ú&lt;ú>ú&gt;ú"z&quot;z{}{}r    r!   Ú z class="{}"ú z)<pre class="{}"><code{}>{}
</code></pre>
r"   )r/   )r   © )r'   Ústripr   Ú_parseHeaderÚpygmentsr   r	   r)   r   r   r
   Úaliasesr   Ú
isinstancer   Ústrr   r   r   ÚreplaceÚappendÚformatÚjoin)r*   ÚshebangÚlexerr0   Ú	formatterÚtxtÚclassesÚ	class_strs           r   ÚhilitezCodeHilite.hilite{   sÙ  € ð ”8—>’> $Ñ'Ô'ˆŒàŒ9Ð ÐØ×ÒÑÔÐåñ )	˜Ô)ñ )	ð	FÝ)¨$¬)ÐDÐD°t´|ÐDÐD��øÝð Fð Fð FðFØ”ð JÝ +¨D¬HÐ EÐ E¸¼Ð EÐ E˜˜å 1Ð IÐ I¸D¼LÐ IÐ I˜øøÝ!ð Fð Fð FÝ-ÐEÐE¸¼ÐEÐE�E�E�EðFøøøøøðFøøøð ”9ð -à!œM¨!Ô,�”	ØÔ*Ð7¨D¬IÐ7Ð7ˆHÝ˜$Ô1µ3Ñ7Ô7ð WðNÝ 5°dÔ6MÐ ^Ð ^ÐQUÔQ]Ð ^Ð ^�I�IøÝ$ð Nð Nð NÝ 5Ð MÐ MÀÄÐ MÐ M�I�I�IðNøøøð 4˜DÔ3ÐVÐV¸XÐVÈÌÐVÐV�	Ý˜TœX u¨iÑ8Ô8Ð8ð ”(×"Ò" 3¨Ñ0Ô0ˆCØ—+’+˜c 6Ñ*Ô*ˆCØ—+’+˜c 6Ñ*Ô*ˆCØ—+’+˜c 8Ñ,Ô,ˆCØˆGØŒyð KØ—’˜vŸ}š}¨TÔ-=¸t¼yÑIÔIÑJÔJÐJØŒ|˜IÔ&ð +Ø—’˜zÑ*Ô*Ð*ØˆIØð DØ)×0Ò0°·²¸'Ñ1BÔ1BÑCÔC�	Ø@×GÒGØ”˜ZÔ(ØØñô ð sH   ÁA& Á&
CÁ10B"Â!CÂ"C Â=CÂ?C Ã CÃCÄD% Ä%EÅEc                 óä  — ddl }| j                             d¦  «        }|                     d¦  «        }|                     d|j        ¦  «        }|                     |¦  «        }|rÇ	 |                     d¦  «                             ¦   «         | _	        n# t          $ r
 d| _	        Y nw xY w|                     d¦  «        r|                     d|¦  «         | j        d         €|                     d¦  «        r
d	| j        d<   t          |                     d
¦  «        ¦  «        | j        d
<   n|                     d|¦  «         d                     |¦  «                             d¦  «        | _        dS )aH  
        Determines language of a code block from shebang line and whether the
        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 line 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 identification 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.

        Also parses optional list of highlight lines, like:

            :::python hl_lines="1 3"
        r   Nr.   aœ  
            (?:(?:^::+)|(?P<shebang>^[#]!)) # Shebang or 2 or more colons
            (?P<path>(?:/\w+)*[/ ])?        # Zero or 1 path
            (?P<lang>[\w#.+-]*)             # The language
            \s*                             # Arbitrary whitespace
            # Optional highlight lines, single- or double-quote-delimited
            (hl_lines=(?P<quot>"|')(?P<hl_lines>.*?)(?P=quot))?
            r   Úpathr    rE   TÚhl_lines)Úrer'   r   r(   ÚcompileÚVERBOSEÚsearchÚgroupÚlowerr   Ú
IndexErrorÚinsertr)   r   rD   r;   )r*   rO   ÚlinesÚflÚcÚms         r   r<   zCodeHilite._parseHeader¶   sa  € ð$ 	ˆ	ˆ	ˆ	ð ”—’˜tÑ$Ô$ˆà�YŠY�q‰\Œ\ˆà�JŠJð ð ”*ñô ˆð �HŠH�R‰LŒLˆØð 	 ð!ØŸGšG F™OœO×1Ò1Ñ3Ô3�”	�	øÝð !ð !ð !Ø �”	�	�	ð!øøøà�wŠw�v‰Œð $à—’˜Q Ñ#Ô#Ð#ØŒ|˜IÔ&Ð.°1·7²7¸9Ñ3EÔ3EÐ.à*.�”˜YÑ'å'5°a·g²g¸jÑ6IÔ6IÑ'JÔ'JˆDŒL˜Ñ$Ð$ð �LŠL˜˜BÑÔÐà—9’9˜UÑ#Ô#×)Ò)¨$Ñ/Ô/ˆŒˆˆs   Á',B ÂB(Â'B(N)T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r+   rK   r<   r:   r,   r   r   r   0   sR   € € € € € ð4ð 4ðlð ð ð(9ð 9ð 9ð 9ðv50ð 50ð 50ð 50ð 50r,   r   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚHiliteTreeprocessorz' Highlight source code in code blocks. c                 óŠ   — |                      dd¦  «        }|                      dd¦  «        }|                      dd¦  «        }|S )zUnescape code.r4   r3   r6   r5   r2   r1   )rA   )r*   r/   s     r   Úcode_unescapez!HiliteTreeprocessor.code_unescapeô   sB   € à�|Š|˜F CÑ(Ô(ˆØ�|Š|˜F CÑ(Ô(ˆð �|Š|˜G SÑ)Ô)ˆØˆr,   c           	      óò  — |                      d¦  «        }|D ]Þ}t          |¦  «        dk    rÉ|d         j        dk    r¸| j                             ¦   «         }t          |                      |d         j        ¦  «        f| j        j	        | 
                    dd¦  «        dœ|¤Ž}| j        j                             |                     ¦   «         ¦  «        }|                     ¦   «          d|_        ||_        Œßd	S )
z* Find code blocks and store in htmlStash. Úprer   r   ÚcodeÚpygments_styleÚdefault)Ú
tab_lengthÚstyleÚpN)ÚiterÚlenÚtagÚconfigÚcopyr   rb   r/   Úmdrh   r(   Ú	htmlStashÚstorerK   Úclear)r*   ÚrootÚblocksÚblockÚlocal_configre   Úplaceholders          r   ÚrunzHiliteTreeprocessor.runý   sô   € à—’˜5Ñ!Ô!ˆØð 	)ð 	)ˆEÝ�5‰zŒz˜QŠˆ 5¨¤8¤<°6Ò#9Ð#9Ø#œ{×/Ò/Ñ1Ô1�Ý!Ø×&Ò& u¨Q¤x¤}Ñ5Ô5ðà#œwÔ1Ø&×*Ò*Ð+;¸YÑGÔGðð ð #ð	ð �ð #œgÔ/×5Ò5°d·k²k±m´mÑDÔD�à—’‘”�ð  �”	Ø(�”
øð	)ð 	)r,   N)r[   r\   r]   r^   rb   ry   r:   r,   r   r`   r`   ñ   s8   € € € € € Ø1Ð1ðð ð ð)ð )ð )ð )ð )r,   r`   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚCodeHiliteExtensionz6 Add source code highlighting to markdown codeblocks. c           	      óB  — d dgddgddgddgdd	gdd
gddgddgdœ| _         |                     ¦   «         D ]i\  }}|| j         v r|                      ||¦  «         Œ%t          |t          ¦  «        r#	 t          |d¬¦  «        }n# t          $ r Y nw xY w|dg| j         |<   Œjd S )Nz=Use lines numbers. True|table|inline=yes, False=no, None=autoTz,Automatic language detection - Default: Truer$   z6Set class name for wrapper <div> - Default: codehiliterg   z>Pygments HTML Formatter Style (Colorscheme) - Default: defaultFz8Use inline styles instead of CSS classes - Default falsez[Use Pygments to Highlight code blocks. Disable if using a JavaScript library. Default: Truer   zQPrefix prepended to the language when use_pygments is false. Default: "language-"r   zBUse a specific formatter for Pygments highlighting.Default: "html")r!   r   r#   rf   Ú	noclassesr   r   r   )Úpreserve_noner8   )rn   ÚitemsÚ	setConfigr?   r@   r   r   )r*   ÚkwargsÚkeyÚvalues       r   r+   zCodeHiliteExtension.__init__  s-  € ð ØXðZàØIðKà&ð0ð1ð  )ð BðCð  ð*ð+ð "ð-ð.ð
 Øcðð $*ð$5ð#%ð-ð ˆŒð8 !Ÿ,š,™.œ.ð 	/ð 	/‰JˆC�Ø�d”kÐ!Ð!Ø—’˜s EÑ*Ô*Ð*Ð*õ ˜e¥SÑ)Ô)ð ðå .¨uÀDÐ IÑ IÔ I˜˜øÝ%ð ð ð Ø˜ðøøøà$)¨2 ;�”˜CÑ Ð ð	/ð 	/s   Á0BÂ
BÂBc                 ó¸   — t          |¦  «        }|                      ¦   «         |_        |j                             |dd¦  «         |                     | ¦  «         dS )z/ Add HilitePostprocessor to Markdown instance. rK   é   N)r`   Ú
getConfigsrn   ÚtreeprocessorsÚregisterÚregisterExtension)r*   rp   Úhiliters      r   ÚextendMarkdownz"CodeHiliteExtension.extendMarkdown@  sU   € å% bÑ)Ô)ˆØŸšÑ*Ô*ˆŒØ
Ô×"Ò" 7¨H°bÑ9Ô9Ð9à
×Ò˜TÑ"Ô"Ð"Ð"Ð"r,   N)r[   r\   r]   r^   r+   r‹   r:   r,   r   r{   r{     s9   € € € € € Ø@Ð@ð)/ð )/ð )/ðV#ð #ð #ð #ð #r,   r{   c                  ó   — t          di | ¤ŽS )Nr:   )r{   )r�   s    r   ÚmakeExtensionr�   I  s   € ÝÐ(Ð( Ð(Ð(Ð(r,   N)r^   r8   r   r‡   r   Úutilr   r=   r   Úpygments.lexersr	   r
   Úpygments.formattersr   Úpygments.utilr   ÚImportErrorr   r   r`   r{   r�   r:   r,   r   ú<module>r“      st  ððð ð" Ð Ð Ð Ð Ð Ø *Ð *Ð *Ð *Ð *Ð *Ø !Ð !Ð !Ð !Ð !Ð !ðØ"Ð"Ð"Ð"Ð"Ð"Ø>Ð>Ð>Ð>Ð>Ð>Ð>Ð>Ø9Ð9Ð9Ð9Ð9Ð9Ø+Ð+Ð+Ð+Ð+Ð+Ø€H€HøØð ð ð Ø€H€H€Hðøøøðð ð ð {0ð {0ð {0ð {0ð {0ñ {0ô {0ð {0ðB)ð )ð )ð )ð )˜-ñ )ô )ð )ðB4#ð 4#ð 4#ð 4#ð 4#˜)ñ 4#ô 4#ð 4#ðn)ð )ð )ð )ð )s   –3 ³=¼=