+
    f0i4                       R t ^ RIHt ^RIHt ^RIHt ^RIHt ^ RI	H
t
HtHt ]
'       d
   ^ RIHu Ht  ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt RtR R lt ! R R4      t ! R R]4      t ! R R]4      tR tR#   ] d    Rt L6i ; i)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                    V ^8  d   QhRRRR/# )   exprstrreturnz	list[int] )formats   "d/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/markdown/extensions/codehilite.py__annotate__r   *   s            c                    V '       g   . #  \        \        \        V P                  4       4      4      #   \         d    . u # i ; i)zSupport 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)r   s   &r   parse_hl_linesr   *   s=     	CTZZ\*++ 	s   &3 AAc                  B    ] tR t^:tRtR R ltR
R R lltR R ltRtR	# )
CodeHilitea  
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                   V ^8  d   QhRR/# )r   srcr   r   )r   s   "r   r   CodeHilite.__annotate__s   s      C r   c                	   Wn         VP                  R R4      V n        VP                  RR4      V n        VP                  RR4      V n        VP                  RR4      V n        VP                  RR4      V n        R	V9  d   VP                  R
R4      VR	&   RV9  d   VP                  RR4      VR&   RV9  d   RVR&   RVR&   W n        R# )langN
guess_langTuse_pygmentslang_prefix	language-pygments_formatterhtmllinenoslinenumscssclass	css_class
codehilitewrapcodeFfull)r"   popr%   r&   r'   r(   r*   options)selfr"   r4   s   &&,r   __init__CodeHilite.__init__s   s     'FD 9	 'L$ ?")++nd"C 'M; G29++>RTZ2[G#!(Z!>GIW$")++k<"HGJW$"&GJr   c                    V ^8  d   QhRRRR/# )r   shebangboolr   r   r   )r   s   "r   r   r#      s     9 9d 9c 9r   c                   V P                   P                  R4      V n         V P                  f   V'       d   V P                  4        \        '       d   V P
                  '       d    \        V P                  3/ V P                  B pT P                  '       g   TP                  ^ ,          T n        T P                   T P                   2p\        T P                  \        4      '       d#    \!        T P                  3/ T P                  B pMT P                  ! RRT/T P                  B p\%        T P                   Y$4      # V P                   P'                  RR4      pVP'                  RR4      pVP'                  RR4      pVP'                  R	R
4      p. pV P                  '       d6   VP)                  RP+                  V P                  V P                  4      4       V P                  R,          '       d   VP)                  R4       RpV'       d!   RP+                  RP-                  V4      4      pRP+                  V P                  R,          VV4      #   \         dx     T P                  '       d$   \        T P                   3/ T P                  B p EL\        R/ T P                  B p EL&  \         d    \        R/ T P                  B p  ELJi ; ii ; i  \"         d    \!        R/ T P                  B p ELi ; i)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.


lang_str&&amp;<&lt;>&gt;"z&quot;z{}{}r,   r-    z class="{}" z)<pre class="{}"><code{}>{}
</code></pre>
r.   )text)r+   r   )r"   stripr%   _parseHeaderpygmentsr'   r
   r4   r   r&   r   aliasesr(   
isinstancer*   r   r   r   r	   replaceappendr   join)r5   r9   lexerr=   	formattertxtclasses	class_strs   &&      r   hiliteCodeHilite.hilite   s]    88>>$'998)))	F)$))Dt||D 999!MM!,	**+DII;7H$11377N 5d6M6M ^QUQ]Q] ^I !33VXVV	TXXu88 ((""30C++c6*C++c6*C++c8,CGyyyv}}T-=-=tyyIJ||I&&z*I)00'1BC	@GGZ( E  FF +DHH E E 1 IDLL I! F-EEEFF % N 5 M MINsH   & I + K KJ,1 J,J,, KKKK K<;K<c                   V ^8  d   QhRR/# )r   r   Noner   )r   s   "r   r   r#      s     50 50d 50r   c                   ^ RI pV P                  P                  R4      pVP                  ^ 4      pVP	                  RVP
                  4      pVP                  V4      pV'       d    VP                  R4      P                  4       V n	        VP                  R4      '       d   VP                  ^ V4       V P                  R,          f'   VP                  R4      '       d   RV P                  R&   \        VP                  R	4      4      V P                  R	&   MVP                  ^ V4       RP                  V4      P                  R4      V n        R#   \         d    RT n	         Li ; i)
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"
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,   r9   Thl_lines)rer"   r   r3   compileVERBOSEsearchgrouplowerr%   
IndexErrorinsertr4   r   rO   rH   )r5   r\   linesflcms   &     r   rI   CodeHilite._parseHeader   s   $ 	 t$YYq\JJ  ** HHRL!GGFO113	 wwvQ#||I&.17793E3E*.Y''5aggj6I'JDLL$ LLB99U#))$/  ! 	!s   '$E E%$E%)r&   r%   r(   r4   r*   r"   r'   N)T)	__name__
__module____qualname____firstlineno____doc__r6   rU   rI   __static_attributes__r   r   r   r    r    :   s    6p(9v50 50r   r    c                  >    ] tR t^t$ RtR]R&   R R ltR R ltRtR	# )
HiliteTreeprocessorz&Highlight source code in code blocks. zdict[str, Any]configc                    V ^8  d   QhRRRR/# )r   rG   r   r   r   )r   s   "r   r    HiliteTreeprocessor.__annotate__  s      # # r   c                r    VP                  RR4      pVP                  RR4      pVP                  RR4      pV# )zUnescape code.rA   r@   rC   rB   r?   r>   )rM   )r5   rG   s   &&r   code_unescape!HiliteTreeprocessor.code_unescape  s9    ||FC(||FC( ||GS)r   c                    V ^8  d   QhRRRR/# )r   rootzetree.Elementr   rX   r   )r   s   "r   r   rs     s     ) ) )$ )r   c                   VP                  R4      pV F  p\        V4      ^8X  g   K  V^ ,          P                  R8X  g   K/  V P                  P	                  4       pV^ ,          P
                  pVf   Kb  \        V P                  V4      3RV P                  P                  RVP                  RR4      /VB pV P                  P                  P                  VP                  4       4      pVP                  4        RVn        Wsn        K  	  R# )	z+Find code blocks and store in `htmlStash`. precodeN
tab_lengthstylepygments_styledefaultp)iterlentagrq   copyrG   r    ru   mdr|   r3   	htmlStashstorerU   clear)r5   rx   blocksblocklocal_configrG   r{   placeholders   &&      r   runHiliteTreeprocessor.run  s    5!E5zQ58<<6#9#{{//1Qx}}<!&&t,#ww11 '**+;YG #	 #gg//55dkkmD  	(
% r   r   N)	ri   rj   rk   rl   rm   __annotations__ru   r   rn   r   r   r   rp   rp      s    1) )r   rp   c                  &    ] tR tRtRtR tR tRtR# )CodeHiliteExtensioni#  z6Add source code highlighting to markdown code blocks. c                	Z   R RR.RRR.RRR.R	R
R.RRR.RRR.RRR.RRR./V n          VP                  4        F]  w  r#W P                   9   d   V P                  W#4       K(  \        V\        4      '       d    \        VRR7      pVR.V P                   V&   K_  	  R#   \         d     L$i ; i)r-   NzOUse lines numbers. True|table|inline=yes, False=no, None=auto. Default: `None`.r&   Tz/Automatic language detection - Default: `True`.r/   r0   z9Set class name for wrapper <div> - Default: `codehilite`.r~   r   z@Pygments HTML Formatter Style (Colorscheme). Default: `default`.	noclassesFz;Use inline styles instead of CSS classes - Default `False`.r'   z\Highlight code blocks with pygments. Disable if using a JavaScript library. Default: `True`.r(   r)   zTPrefix prepended to the language when `use_pygments` is false. Default: `language-`.r*   r+   zDUse a specific formatter for Pygments highlighting. Default: `html`.)preserve_nonerE   )rq   items	setConfigrL   r   r   r   )r5   kwargskeyvalues   &,  r   r6   CodeHiliteExtension.__init__&  s     g G Y ] T t s !^#-
4 	/ ,,.JCkk!s* eS)) .uD I %*2;C  ) & s   8BB*)B*c                    \        V4      pV P                  4       Vn        VP                  P	                  VR^4       VP                  V 4       R# )z0Add `HilitePostprocessor` to Markdown instance. rU   N)rp   
getConfigsrq   treeprocessorsregisterregisterExtension)r5   r   hiliters   && r   extendMarkdown"CodeHiliteExtension.extendMarkdownQ  s@    %b)*
""7Hb9
T"r   )rq   N)ri   rj   rk   rl   rm   r6   r   rn   r   r   r   r   r   #  s    A)/V#r   r   c                     \        R/ V B # )Nr   )r   )r   s   ,r   makeExtensionr   Z  s    (((r   )rm   
__future__r   rE   r   r   r   utilr   typingr   r   r   xml.etree.ElementTreeetreeElementTreerJ   r	   pygments.lexersr
   r   pygments.formattersr   pygments.utilr   ImportErrorr   r    rp   r   r   r   r   r   <module>r      s    #  * ! / /))">9+H
 }0 }0F#)- #)L4#) 4#n)i	  Hs   A> >	B
	B
