
    ͆h	                    6   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  \
(       a  S SKJr  S SKJrJr   S SKJr  Sr\R&                  " \5      r " S
 S5      r " S S5      r\" S \" SS5       5       5      r " S S\5      rg! \ a    S	r NRf = f)    )annotationsN)
HTMLParser)TYPE_CHECKING)Page)
AnchorLinkTableOfContents)lunrTFc                  d    \ rS rSrSrSS jrSS jrSS jrSS jr        SS jr	SS jr
S	rg
)SearchIndex   zm
Search index is a collection of pages and sections (heading
tags and their following content are sections).
c                    / U l         Xl        g N_entriesconfig)selfr   s     Z/opt/services/DDDS/venv/lib/python3.13/site-packages/mkdocs/contrib/search/search_index.py__init__SearchIndex.__init__   s    $&    c                    U H:  nUR                   U:X  a  Us  $ U R                  UR                  U5      nUc  M8  Us  $    g)z`
Given a table of contents and HTML ID, iterate through
and return the matched item in the TOC.
N)id_find_toc_by_idchildren)r   tocid_toc_item
toc_item_rs        r   r   SearchIndex._find_toc_by_id#   sH    
 H{{c!--h.?.?EJ%!!  r   c                    UR                  SS5      n[        R                  " SSUR                  5       5      nU R                  R                  XUS.5        g)z:A simple wrapper to add an entry, dropping bad characters.     z[ \t\n\r\f\v]+)titletextlocationN)replaceresubstripr   append)r   r#   r$   locs       r   
_add_entrySearchIndex._add_entry0   sB    ||Hc*vv'djjl;uLMr   c                   [        5       nUR                  c   eUR                  UR                  5        UR                  5         UR                  nU R
                  S   S:X  a  UR                  R                  S5      OSnU R                  UR                  XCS9  U R
                  S   S;   a0  UR                   H  nU R                  XQR                  U5        M!     gg)zv
Create a set of entries in the index for a page. One for
the page itself and then one for each of its' heading
tags.
Nindexingfull
 r#   r$   r+   )r0   sections)ContentParsercontentfeedcloseurlr   stripped_htmlrstripr,   r#   datacreate_entry_for_sectionr   )r   pageparserr9   r$   sections         r   add_entry_from_context"SearchIndex.add_entry_from_context7   s     ||'''DLL! hh 59KK
4Kv4Uv##**40[]djjt=;;z"&::!;;--gxxE ' ;r   c                    U R                  X!R                  5      nU R                  S   S:X  a  SR                  UR                  5      OSnUb(  U R                  UR                  XSUR                  -   S9  gg)zt
Given a section on the page, the table of contents and
the absolute url for the page create an entry in the
index.
r/   r0   r"   r2   Nr3   )r   r   r   joinr$   r,   r#   r9   )r   r@   r   abs_urlr   r$   s         r   r=   $SearchIndex.create_entry_for_sectionQ   se     ''ZZ8)-Z)@F)Jsxx%PROO(..t8<<AWOX  r   c                @   U R                   U R                  S.n[        R                  " USS[        S9nU R                  S   S;   Ga   [
        R                  R                  [
        R                  R                  [
        R                  R                  [        5      5      S5      n[        R                  " SU/[        R                  [        R                  [        R                  S	S
9nUR                  U5      u  pVU(       dF  [        R                  " U5      US'   [        R                  " USSS9n[         R#                  S5        U$ [         R%                  SU 35         U$ U R                  S   S:X  an  [*        (       aN  [-        SSU R                   U R                  S   S9nUR/                  5       US'   [        R                  " USSS9nU$ [         R%                  S5        U$ ! [&        [(        4 a#  n[         R%                  SU 35         SnAU$ SnAff = f)zPython to json conversion.)docsr   T),:)	sort_keys
separatorsdefaultprebuild_index)Tnodezprebuild-index.jsrO   zutf-8)stdinstdoutstderrencodingindex)rK   rL   z,Pre-built search index created successfully.z)Failed to pre-build search index. Error: Npythonr%   )r#   r$   lang)reffields	documents	languagesa  Failed to pre-build search index. The 'python' method was specified; however, the 'lunr.py' library does not appear to be installed. Try installing it with 'pip install lunr'. If you are using any language other than English you will also need to install 'lunr[languages]'.)r   r   jsondumpsstrospathrD   dirnameabspath__file__
subprocessPopenPIPEcommunicateloadslogdebugwarningOSError
ValueError	haslunrpyr	   	serialize)	r   
page_dictsr<   script_pathpidxerrelunr_idxs	            r   generate_search_index!SearchIndex.generate_search_index_   s   "mmt{{C
zz*UXY;;'(N:M ggllGGOOBGGOOH$=>@S $$[)$//%??%??$ ==.*.**S/Jw'::jDZXDIILM. + KK"KC5 QR* % [[)*h6y","mm"kk&1	 '/&8&8&:
7#zz*T  Z ) Z( MGsKLL& )Ms   
D G* G* *H:HHr   NreturnNone)r   
str | Nonery   zAnchorLink | None)r#   r{   r$   r]   r+   r]   ry   rz   )r>   r   ry   rz   )r@   ContentSectionr   r   rE   r]   ry   rz   ry   r]   )__name__
__module____qualname____firstlineno____doc__r   r   r,   rA   r=   rv   __static_attributes__ r   r   r   r      sL    
NF4Y%Y,;YFIY	Y,r   r   c                  @    \ rS rSrSr   S       SS jjrS rSrg)	r|      za
Used by the ContentParser class to capture the information we
need when it is parsing the HTML.
Nc                <    U=(       d    / U l         X l        X0l        g r   r$   r   r#   )r   r$   r   r#   s       r   r   ContentSection.__init__   s     JB	
r   c                    U R                   UR                   :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r   r   )r   others     r   __eq__ContentSection.__eq__   s<    yyEJJ&\477ehh+>\4::QVQ\Q\C\\r   )r   r$   r#   )NNN)r$   zlist[str] | Noner   r{   r#   r{   ry   rz   )r~   r   r   r   r   r   r   r   r   r   r   r|   r|      sC     "& 	  	
 
]r   r|   c              #  ,   #    U  H
  nS U 3v   M     g7f)hNr   ).0xs     r   	<genexpr>r      s     2kqWks         c                  b   ^  \ rS rSrSrS	U 4S jjrS
S jrSS jrSS jr\	SS j5       r
SrU =r$ )r5      z
Given a block of HTML, group the content under the preceding
heading tags which can then be used for creating an index
for that section.
c                ^   > [         TU ]  " U0 UD6  / U l        S U l        SU l        / U l        g )NF)superr   r<   r@   is_header_tag_stripped_html)r   argskwargs	__class__s      r   r   ContentParser.__init__   s3    $)&)*,	.2")+r   c                    U[         ;  a  gSU l        [        5       U l        U R                  R                  U R                  5        U H"  nUS   S:X  d  M  US   U R                  l        M$     g)z&Called at the start of every HTML tag.NTr   r   r   )_HEADER_TAGSr   r|   r@   r<   r*   r   )r   tagattrsattrs       r   handle_starttagContentParser.handle_starttag   s]     l" "%'		&DAw$"&q' r   c                (    U[         ;  a  gSU l        g)z$Called at the end of every HTML tag.NF)r   r   )r   r   s     r   handle_endtagContentParser.handle_endtag   s     l""r   c                   U R                   R                  U5        U R                  c  gU R                  (       a  XR                  l        gU R                  R
                  R                  UR                  S5      5        g)z)Called for the text contents of each tag.Nr1   )r   r*   r@   r   r#   r$   r;   )r   r<   s     r   handle_dataContentParser.handle_data   s[    ""4(<<
 
 !%LLLL$$T[[%67r   c                8    SR                  U R                  5      $ )Nr1   )rD   r   )r   s    r   r:   ContentParser.stripped_html   s    yy,,--r   )r   r<   r   r@   rx   )r   r]   r   zlist[tuple[str, str | None]]ry   rz   )r   r]   ry   rz   )r<   r]   ry   rz   r}   )r~   r   r   r   r   r   r   r   r   propertyr:   r   __classcell__)r   s   @r   r5   r5      s0    ,* #8& . .r   r5   )
__future__r   r[   loggingr^   r'   rc   html.parserr   typingr   mkdocs.structure.pagesr   mkdocs.structure.tocr   r   r	   rm   ImportError	getLoggerr~   rh   r   r|   tupleranger   r5   r   r   r   <module>r      s    "   	 	  "  +@I !r rj] ]( 2eAqk22<.J <.e  Is   B BB