
    $g,                    B   d Z ddlmZ ddlZddlZddlZddlmZm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 erdd
lmZ ddlmZ  G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de
          ZdS )zkThis module holds helpers responsible for augmentations to the Markdown sub-documents produced by handlers.    )annotationsN)TYPE_CHECKINGAny)	Extension)CodeHiliteExtension)Treeprocessor)Markup)	HighlightHighlightExtension)Element)Markdownc                  T     e Zd ZdZ ed          Zd fdZ	 ddddd	d fdZ xZS )Highlightera  Code highlighter that tries to match the Markdown configuration.

    Picking up the global config and defaults works only if you use the `codehilite` or
    `pymdownx.highlight` (recommended) Markdown extension.

    -   If you use `pymdownx.highlight`, highlighting settings are picked up from it, and the
        default CSS class is `.highlight`. This also means the default of `guess_lang: false`.

    -   Otherwise, if you use the `codehilite` extension, settings are picked up from it, and the
        default CSS class is `.codehilite`. Also consider setting `guess_lang: false`.

    -   If neither are added to `markdown_extensions`, highlighting is enabled anyway. This is for
        backwards compatibility. If you really want to disable highlighting even in *mkdocstrings*,
        add one of these extensions anyway and set `use_pygments: false`.

    The underlying implementation is `pymdownx.highlight` regardless.
    )	css_class
guess_langdefault_langpygments_style	noclassesuse_pygmentslinenumslinenums_speciallinenums_stylelinenums_classextend_pygments_langlanguage_prefixcode_attr_on_pre
auto_titleauto_title_map
line_spansanchor_linenumsline_anchorspygments_lang_classstripnlmdr   c                    i }d _         |j        D ]z}t          |t                    r&|j        s|sd _         |                                } n>t          |t                    r(|s&d _         |                                }|d         |d<   {|                    dd           _         t                      j
        di  fd|                                D              dS )	zConfigure to match a `markdown.Markdown` instance.

        Arguments:
            md: The Markdown instance to read configs from.
        N	highlight
codehilitelang_prefixr   r   c                .    i | ]\  }}|j         v ||S  )_highlight_config_keys).0nameoptselfs      _/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/mkdocstrings/handlers/rendering.py
<dictcomp>z(Highlighter.__init__.<locals>.<dictcomp>U   s-    mmm)$QUQlIlIlD#IlIlIl    r*   )_highlighterregisteredExtensions
isinstancer   enabled
getConfigsr   pop
_css_classsuper__init__items)r/   r$   configext	__class__s   `   r0   r;   zHighlighter.__init__C   s     "$(,* 	B 	BC#122  6 $/!))#233 BF B$0!)),2=,A() **[+>>nnmmmmv||~~mmmnnnnnr2   NFT)inlinededentr   srcstrlanguage
str | Noner@   boolrA   r   bool | Nonekwargsr   returnc          	        t          |t                    r|                                }|rt          j        |          }|                    d| j                   | j        }||| _        	  t                      j	        ||fd|i|}|| _        n# || _        w xY w|r3| j
        dk    rdn|d         }	t          d|	 d| d|j         d	          S t          |          S )
a  Highlight a code-snippet.

        Arguments:
            src: The code to highlight.
            language: Explicitly tell what language to use for highlighting.
            inline: Whether to highlight as inline.
            dedent: Whether to dedent the code before highlighting it or not.
            linenums: Whether to add line numbers in the result.
            **kwargs: Pass on to `pymdownx.highlight.Highlight.highlight`.

        Returns:
            The highlighted code as HTML text, marked safe (not escaped for HTML).
        r   Nr@   r'    z<code class="z
 language-z">z</code>)r5   r	   unescapetextwraprA   
setdefaultr9   r   r:   r&   r3   text)r/   rB   rD   r@   rA   r   rH   old_linenumsresultr   r?   s             r0   r&   zHighlighter.highlightW   s   . c6"" 	!,,..C 	'/#&&C+t777}$DM	)&UWW&sHNNVNvNNF(DMMLDM(((( 	a #/<??VKEXI_)__x__6;___```f~~s   -B 	B)r$   r   N)rB   rC   rD   rE   r@   rF   rA   rF   r   rG   rH   r   rI   rC   )	__name__
__module____qualname____doc__	frozensetr+   r;   r&   __classcell__r?   s   @r0   r   r      s         & 'Y	
 2o o o o o o.  $+
  $+ + + + + + + + + + + +r2   r   c                  F     e Zd ZU dZdZded<   	 d fdZddZddZ xZ	S )IdPrependingTreeprocessorz:Prepend the configured prefix to IDs of all HTML elements.mkdocstrings_idsrC   	id_prefixr$   r   c                X    t                                          |           || _        dS )zInitialize the object.

        Arguments:
            md: A `markdown.Markdown` instance.
            id_prefix: The prefix to add to every ID. It is prepended without any separator.
        N)r:   r;   r]   )r/   r$   r]   r?   s      r0   r;   z"IdPrependingTreeprocessor.__init__   s(     	"r2   rootr   rI   Nonec                B    | j         r|                     |           d S d S rR   )r]   _prefix_idsr/   r_   s     r0   runzIdPrependingTreeprocessor.run   s0    > 	#T"""""	# 	#r2   c                0   t          |          }t          |          D ]u}|dz  }|                     |           |                    d          }|                    d          x}rw|j        dk    rN|sLt          j        |          }|                    d| j        |z              |	                    |dz   |           n|                    d| j        |z              |r>|
                    d          r)|                    dd| j        z   |dd          z              |                    d          x}r|                    d| j        |z              |j        dk    r5|                    d          }|r|                    d| j        |z              wd S )	N   hrefida#r-   labelfor)lenreversedrb   gettagcopydeepcopysetr]   insert
startswith)	r/   r_   indexel	href_attrid_attrnew_el	name_attrfor_attrs	            r0   rb   z%IdPrependingTreeprocessor._prefix_ids   s   D		4.. 	= 	=BQJER   vI&&,,&w 
;6S=== "]2..FJJtT^g%=>>>KK	62222 FF4'!9:::  EY11#66 EvsT^3imCDDDFF6NN*y ;vt~	9:::v  66%== =FF5$.8";<<<;	= 	=r2   )r$   r   r]   rC   r_   r   rI   r`   )
rS   rT   rU   rV   r-   __annotations__r;   rd   rb   rX   rY   s   @r0   r[   r[      s~         DDDNNNu# # # # # ## # # #= = = = = = = =r2   r[   c                  ^     e Zd ZU dZdZ ej        d          Zded<   	 d fdZ	ddZ
 xZS )HeadingShiftingTreeprocessorzMShift levels of all Markdown headings according to the configured base level.mkdocstrings_headingsz([Hh])([1-6])intshift_byr$   r   c                X    t                                          |           || _        dS )zInitialize the object.

        Arguments:
            md: A `markdown.Markdown` instance.
            shift_by: The number of heading "levels" to add to every heading.
        N)r:   r;   r   )r/   r$   r   r?   s      r0   r;   z%HeadingShiftingTreeprocessor.__init__   s(     	 r2   r_   r   rI   r`   c                    | j         sd S |                                D ]o}| j                            |j                  }|rLt          |d                   | j         z   }t          dt          |d                    }|d          | |_        pd S )N   rf      )r   iterregex	fullmatchrp   r   maxmin)r/   r_   rw   matchlevels        r0   rd   z HeadingShiftingTreeprocessor.run   s    } 	F))++ 	. 	.BJ((00E .E!H5As5!}}--!!H-e--	. 	.r2   )r$   r   r   r   r}   rS   rT   rU   rV   r-   recompiler   r~   r;   rd   rX   rY   s   @r0   r   r      s|         WW"DBJ'((EMMMl! ! ! ! ! !. . . . . . . .r2   r   c                  ^     e Zd ZU dZdZ ej        d          Zded<   	 d fdZ	ddZ
 xZS )_HeadingReportingTreeprocessorz9Records the heading elements encountered in the document.mkdocstrings_headings_listz	[Hh][1-6]list[Element]headingsr$   r   c                X    t                                          |           || _        d S rR   r:   r;   r   )r/   r$   r   r?   s      r0   r;   z'_HeadingReportingTreeprocessor.__init__   s&     r2   r_   r   rI   r`   c                f   | j         j        d         j        }|                                D ]}| j                            |j                  rct          j        |          }t          |          dk    r"|d         	                    d          |k    r|d= | j
                            |           d S )Ntocr   class)r$   treeprocessorspermalink_classr   r   r   rp   rq   rm   ro   r   append)r/   r_   r   rw   s       r0   rd   z"_HeadingReportingTreeprocessor.run   s    '07G))++ 	) 	)Bz##BF++ )Yr]] r77Q;;2b6::g#6#6/#I#I2$$R(((	) 	)r2   )r$   r   r   r   r}   r   rY   s   @r0   r   r      s~         CC'DBJ|$$Ex! ! ! ! ! !	) 	) 	) 	) 	) 	) 	) 	)r2   r   c                  "    e Zd ZdZdZdZd
dZd	S )ParagraphStrippingTreeprocessorz0Unwraps the <p> element around the whole output.mkdocstrings_strip_paragraphFr_   r   rI   Element | Nonec                    | j         r>t          |          dk    r+|d         j        dk    r|j        |d         _        |d         S d S )Nrf   r   p)striprm   rp   rc   s     r0   rd   z#ParagraphStrippingTreeprocessor.run   sE    : 	#d))q..T!W[C-?-?(DGK7Ntr2   N)r_   r   rI   r   )rS   rT   rU   rV   r-   r   rd   r*   r2   r0   r   r      s8        ::)DE     r2   r   c                  ,     e Zd ZdZd
 fdZdd	Z xZS )MkdocstringsInnerExtensionzhExtension that should always be added to Markdown sub-documents that handlers request (and *only* them).r   r   c                V    t                                                       || _        dS )zInitialize the object.

        Arguments:
            headings: A list that will be populated with all HTML heading elements encountered in the document.
        Nr   )r/   r   r?   s     r0   r;   z#MkdocstringsInnerExtension.__init__  s&     	 r2   r$   r   rI   r`   c                   |                     |            |j                            t          |d          t          j        d           |j                            t          |d          t
          j        d           |j                            t          || j                  t          j        d           |j                            t          |          t          j        d           dS )	zdRegister the extension.

        Arguments:
            md: A `markdown.Markdown` instance.
        r      )priorityrK      rf   gGz?N)	registerExtensionr   registerr   r-   r[   r   r   r   )r/   r$   s     r0   extendMarkdownz)MkdocstringsInnerExtension.extendMarkdown  s     	T"""
""(Q//(- 	# 	
 	
 	

 	""%b"--%* 	# 	
 	
 	

 	""*2t}==*/ 	# 	
 	
 	

 	""+B//+0 	# 	
 	
 	
 	
 	
r2   )r   r   )r$   r   rI   r`   )rS   rT   rU   rV   r;   r   rX   rY   s   @r0   r   r     sW        rr! ! ! ! ! !
 
 
 
 
 
 
 
r2   r   )rV   
__future__r   rq   r   rM   typingr   r   markdown.extensionsr   markdown.extensions.codehiliter   markdown.treeprocessorsr   
markupsafer	   pymdownx.highlightr
   r   xml.etree.ElementTreer   markdownr   r   r[   r   r   r   r   r*   r2   r0   <module>r      s   q q " " " " " "  				  % % % % % % % % ) ) ) ) ) ) > > > > > > 1 1 1 1 1 1       < < < < < < < < "------!!!!!!l l l l l) l l l^5= 5= 5= 5= 5= 5= 5= 5=p. . . . .= . . .<) ) ) ) )] ) ) )2    m   &
 &
 &
 &
 &
 &
 &
 &
 &
 &
r2   