ó
    "nj¿4  ã                  ó  • S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
JrJr  \
(       a	  SS	KJs  Jr   SS
KJr  SSKJrJr  SSKJr  SSKJr  SrSS jr " S S5      r " S S\5      r " S S\5      rS rg	! \ a    Sr N3f = f)z¨
Adds code/syntax highlighting to standard Python-Markdown code blocks.

See the [documentation](https://Python-Markdown.github.io/extensions/code_hilite)
for details.
é    )Úannotationsé   )Ú	Extensioné   )ÚTreeprocessor)ÚparseBoolValue)ÚTYPE_CHECKINGÚCallableÚAnyN)Ú	highlight)Úget_lexer_by_nameÚguess_lexer)Úget_formatter_by_name)ÚClassNotFoundTFc                óˆ   • U (       d  / $  [        [        [        U R                  5       5      5      $ ! [         a    / s $ f = f)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 integers, the line numbers to emphasize.
)ÚlistÚmapÚintÚsplitÚ
ValueError)Úexprs    Ú@/usr/lib/python3/dist-packages/markdown/extensions/codehilite.pyÚparse_hl_linesr   *   s=   € ö Øˆ	ðÜ”Cœ˜TŸZ™Z›\Ó*Ó+Ð+øÜó ØŠ	ðús   ‹&2 ²AÁ Ac                  ó:   • \ rS rSrSrSS jrS	S
S jjrSS jrSrg)Ú
CodeHiliteé:   aÉ  
Determine language of source code, and pass it on to the Pygments highlighter.

Usage:

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

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

Keyword arguments:
    lang (str): String name of Pygments lexer to use for highlighting. Default: `None`.
    guess_lang (bool): Auto-detect which lexer to use.
        Ignored if `lang` is set to a valid value. Default: `True`.
    use_pygments (bool): Pass code to Pygments for code highlighting. If `False`, the code is
        instead wrapped for highlighting by a JavaScript library. Default: `True`.
    pygments_formatter (str): The name of a Pygments formatter or a formatter class used for
        highlighting the code blocks. Default: `html`.
    linenums (bool): An alias to Pygments `linenos` formatter option. Default: `None`.
    css_class (str): An alias to Pygments `cssclass` formatter option. Default: 'codehilite'.
    lang_prefix (str): 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' builtin formatters.

Advanced Usage:

```python
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                óŽ  • Xl         UR                  SS 5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        S	U;  a  UR                  S
S 5      US	'   SU;  a  UR                  SS5      US'   SU;  a  SUS'   SUS'   X l        g )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__ÚCodeHilite.__init__s   sÀ   € ØŒØ '§¡¨F°DÓ 9ˆŒ	Ø '§¡¨L¸$Ó ?ˆŒØ")§+¡+¨n¸dÓ"CˆÔØ '§¡¨M¸;Ó GˆÔØ29·+±+Ð>RÐTZÓ2[ˆÔà˜GÓ#Ø!(§¡¨Z¸Ó!>ˆG�IÑØ˜WÓ$Ø")§+¡+¨k¸<Ó"HˆG�JÑØ˜WÓ$à"&ˆG�JÑàˆ�‰à�ó    c                óÌ  • U R                   R                  S5      U l         U R                  c  U(       a  U R                  5         [        (       aæ  U R
                  (       aÕ   [        U R                  40 U R                  D6nU R                  (       d  UR                  S   U l        U R                   U R                   3n[        U R                  [        5      (       a"   [!        U R                  40 U R                  D6nOU R                  " SSU0U R                  D6n[%        U R                   X$5      $ U R                   R'                  SS5      nUR'                  SS5      nUR'                  SS	5      nUR'                  S
S5      n/ nU R                  (       a5  UR)                  SR+                  U R                  U R                  5      5        U R                  S   (       a  UR)                  S5        SnU(       a   SR+                  SR-                  U5      5      nSR+                  U R                  S   UU5      $ ! [         au     U R                  (       a#  [        U R                   40 U R                  D6n GNû[        S0 U R                  D6n GN! [         a    [        S0 U R                  D6n  GN6f = ff = f! ["         a    [!        S0 U R                  D6n GNÂf = f)a  
Pass code to the [Pygments](https://pygments.org/) highlighter 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.

Ú
r   Úlang_strÚ&ú&amp;Ú<ú&lt;Ú>ú&gt;Ú"z&quot;z{}{}r%   r&   Ú z class="{}"Ú z)<pre class="{}"><code{}>{}
</code></pre>
r'   )Útext)r$   © )r,   Ústripr   Ú_parseHeaderÚpygmentsr    r   r.   r   r   r   Úaliasesr!   Ú
isinstancer#   Ústrr   r   r   ÚreplaceÚappendÚformatÚjoin)r/   ÚshebangÚlexerr5   Ú	formatterÚtxtÚclassesÚ	class_strs           r   ÚhiliteÚCodeHilite.hilite‡   sQ  € ð —8‘8—>‘> $Ó'ˆŒà�9‰9Ñ¦Ø×ÑÔçŠ8˜×)×)ð	FÜ)¨$¯)©)ÑD°t·|±|ÑD�ð —9—9à!ŸM™M¨!Ñ,�”	Ø×*Ñ*Ð+¨D¯I©I¨;Ð7ˆHÜ˜$×1Ñ1´3×7Ñ7ðNÜ 5°d×6MÑ6MÑ ^ÐQU×Q]ÑQ]Ñ ^‘Ið !×3Ò3ÑV¸XÐVÈÏÉÑV�	Ü˜TŸX™X uÓ8Ð8ð —(‘(×"Ñ" 3¨Ó0ˆCØ—+‘+˜c 6Ó*ˆCØ—+‘+˜c 6Ó*ˆCØ—+‘+˜c 8Ó,ˆCØˆGØ�y�yØ—‘˜vŸ}™}¨T×-=Ñ-=¸t¿y¹yÓIÔJØ�|‰|˜I×&Ø—‘˜zÔ*ØˆIÞØ)×0Ñ0°·±¸'Ó1BÓC�	Ø@×GÑGØ—‘˜ZÑ(ØØóð øôE ó FðFØ——Ü +¨D¯H©HÑ E¸¿¹Ñ E›ä 1Ñ I¸D¿L¹LÑ I›øÜ!ó FÜ-ÑE¸¿¹ÑE”EðFúðFûô %ó NÜ 5Ñ MÀÇÁÑ M“IðNúsB   Á" H> Ã! K  È>
J=É	1JÉ=JÊJ9Ê4J=Ê8J9Ê9J=Ë K#Ë"K#c                ó¼  • SSK nU R                  R                  S5      nUR                  S5      nUR	                  SUR
                  5      nUR                  U5      nU(       aª   UR                  S5      R                  5       U l	        UR                  S5      (       a  UR                  SU5        U R                  S   c%  UR                  S5      (       a  S	U R                  S'   [        UR                  S
5      5      U R                  S
'   OUR                  SU5        SR                  U5      R                  S5      U l        g! [         a
    SU l	         NÐf = f)aè  
Determines language of a code block from shebang line and whether the
said line should be removed or left in place. If the shebang 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   Nr4   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%   rK   TÚhl_lines)Úrer,   r   r-   ÚcompileÚVERBOSEÚsearchÚgroupÚlowerr   Ú
IndexErrorÚinsertr.   r   rJ   rA   )r/   rV   ÚlinesÚflÚcÚms         r   rB   ÚCodeHilite._parseHeaderÂ   s  € ó$ 	ð —‘—‘˜tÓ$ˆà�Y‰Y�q‹\ˆà�J‰Jð ð —*‘*óˆð �H‰H�R‹LˆÞð!ØŸG™G F›O×1Ñ1Ó3�”	ð �w‰w�v�‰à—‘˜Q Ô#Ø�|‰|˜IÑ&Ñ.°1·7±7¸9×3EÑ3Eà*.�—‘˜YÑ'ä'5°a·g±g¸jÓ6IÓ'JˆD�L‰L˜Ò$ð �L‰L˜˜BÔà—9‘9˜UÓ#×)Ñ)¨$Ó/ˆ�øô ó !Ø �–	ð!ús   Á&$E ÅEÅE)r   r   r!   r.   r#   r,   r    N)r,   rF   )T)rK   ÚboolÚreturnrF   )rd   ÚNone)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r0   rQ   rB   Ú__static_attributes__r@   r2   r   r   r   :   s   † ñ6ôpö(9÷v50r2   r   c                  ó8   • \ rS rSr% SrS\S'   S	S jrS
S jrSrg)ÚHiliteTreeprocessoréý   z&Highlight source code in code blocks. zdict[str, Any]Úconfigc                ór   • UR                  SS5      nUR                  SS5      nUR                  SS5      nU$ )zUnescape code.r9   r8   r;   r:   r7   r6   )rG   )r/   r?   s     r   Úcode_unescapeÚ!HiliteTreeprocessor.code_unescape  s9   € à�|‰|˜F CÓ(ˆØ�|‰|˜F CÓ(ˆð �|‰|˜G SÓ)ˆØˆr2   c           	     ó  • UR                  S5      nU Hé  n[        U5      S:X  d  M  US   R                  S:X  d  M)  U R                  R	                  5       nUS   R
                  nUc  MW  [        U R                  U5      4U R                  R                  UR                  SS5      S.UD6nU R                  R                  R                  UR                  5       5      nUR                  5         S	Ul        Xsl        Më     g)
z+Find code blocks and store in `htmlStash`. Úprer   r   ÚcodeNÚpygments_styleÚdefault)Ú
tab_lengthÚstyleÚp)ÚiterÚlenÚtagro   Úcopyr?   r   rq   Úmdrx   r-   Ú	htmlStashÚstorerQ   Úclear)r/   ÚrootÚblocksÚblockÚlocal_configr?   ru   Úplaceholders           r   ÚrunÚHiliteTreeprocessor.run  sÙ   € à—‘˜5Ó!ˆÛˆEÜ�5‹z˜Q� 5¨¡8§<¡<°6Õ#9Ø#Ÿ{™{×/Ñ/Ó1�Ø˜Q‘x—}‘}�Ø‘<ÙÜ!Ø×&Ñ& tÓ,ðà#Ÿw™w×1Ñ1Ø&×*Ñ*Ð+;¸YÓGñð #ñ	�ð #Ÿg™g×/Ñ/×5Ñ5°d·k±k³mÓD�à—‘”ð  �”	Ø(–
ò% r2   r@   N)r?   rF   rd   rF   )rƒ   zetree.Elementrd   re   )	rf   rg   rh   ri   rj   Ú__annotations__rq   rˆ   rk   r@   r2   r   rm   rm   ý   s   ‡ Ù1àÓô÷)r2   rm   c                  ó$   • \ rS rSrSrS rS rSrg)ÚCodeHiliteExtensioni#  z6Add source code highlighting to markdown code blocks. c           	     ó>  • S S/SS/SS/SS/SS	/SS
/SS/SS/S.U l          UR                  5        HX  u  p#X R                   ;   a  U R                  X#5        M'  [        U[        5      (       a   [        USS9nUS/U R                   U'   MZ     g ! [         a     N"f = f)NzOUse lines numbers. True|table|inline=yes, False=no, None=auto. Default: `None`.Tz/Automatic language detection - Default: `True`.r)   z9Set class name for wrapper <div> - Default: `codehilite`.rw   z@Pygments HTML Formatter Style (Colorscheme). Default: `default`.Fz;Use inline styles instead of CSS classes - Default `False`.z\Highlight code blocks with pygments. Disable if using a JavaScript library. Default: `True`.r"   zTPrefix prepended to the language when `use_pygments` is false. Default: `language-`.r$   zDUse a specific formatter for Pygments highlighting. Default: `html`.)r&   r   r(   rv   Ú	noclassesr    r!   r#   )Úpreserve_noner=   )ro   ÚitemsÚ	setConfigrE   rF   r   r   )r/   ÚkwargsÚkeyÚvalues       r   r0   ÚCodeHiliteExtension.__init__&  sè   € ð Ðgðð ÐGðð ÐYðð Ð]ðð ÐTðð Ðtðð Ðsðð Ð^ð#ñ-
ˆŒð4 	/à Ÿ,™,ž.‰JˆCØ—k‘kÓ!Ø—‘˜sÖ*ô ˜e¤S×)Ñ)ðä .¨uÀDÑ I˜ð %*¨2 ;�—‘˜CÓ ò )øô &ó Ùðús   Á/
BÂ
BÂBc                ó    • [        U5      nU R                  5       Ul        UR                  R	                  USS5        UR                  U 5        g)z0Add `HilitePostprocessor` to Markdown instance. rQ   é   N)rm   Ú
getConfigsro   ÚtreeprocessorsÚregisterÚregisterExtension)r/   r   Úhiliters      r   ÚextendMarkdownÚ"CodeHiliteExtension.extendMarkdownQ  s@   € ä% bÓ)ˆØŸ™Ó*ˆŒØ
×Ñ×"Ñ" 7¨H°bÔ9à
×Ñ˜TÕ"r2   )ro   N)rf   rg   rh   ri   rj   r0   r�   rk   r@   r2   r   rŒ   rŒ   #  s   † ÙAò)/õV#r2   rŒ   c                 ó   • [        S0 U D6$ )Nr@   )rŒ   )r’   s    r   ÚmakeExtensionr    Z  s   € ÜÑ( Ñ(Ð(r2   )r   rF   rd   z	list[int])rj   Ú
__future__r   r=   r   r™   r   Úutilr   Útypingr	   r
   r   Úxml.etree.ElementTreeÚetreeÚElementTreerC   r   Úpygments.lexersr   r   Úpygments.formattersr   Úpygments.utilr   ÚImportErrorr   r   rm   rŒ   r    r@   r2   r   Ú<module>r«      s…   ðñõ #å Ý *Ý !ß /Ñ /æß)Ð)ðÝ"ß>Ý9Ý+Ø€Hô
÷ }0ñ }0ôF#)˜-ô #)ôL4#˜)ô 4#ón)øði	 ó Ø‚Hðús   ¶A; Á;BÂB