
    $gX                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl	Z	 e	j
        d          Zdd	d
ddZ e	j
        d          Z e	j
        d          Zd Zd Z G d de          Z G d de          Zd ZdS )a  
B64.

An extension for Python Markdown.
Given an absolute base path, this extension searches for image tags,
and if the images are local, will embed the images in base64.

MIT license.

Copyright (c) 2014 - 2017 Isaac Muse <isaacmuse@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )	Extension)Postprocessor   )utilNz^/[A-Za-z]{1}:/.*z	image/pngz
image/jpegz	image/gifzimage/svg+xml))z.png)z.jpgz.jpeg)z.gif)z.svgaV  (?xus)
    (?:
        (?P<avoid>
            <\s*(?P<script_name>script|style)[^>]*>.*?</\s*(?P=script_name)\s*> |
            (?:(\r?\n?\s*)<!--[\s\S]*?-->(\s*)(?=\r?\n)|<!--[\s\S]*?-->)
        )|
        (?P<open><\s*(?P<tag>img))
        (?P<attr>(?:\s+[\w\-:]+(?:\s*=\s*(?:"[^"]*"|'[^']*'))?)*)
        (?P<close>\s*(?:\/?)>)
    )
    z(?xus)
    (?P<attr>
        (?:
            (?P<name>\s+src\s*=\s*)
            (?P<path>"[^"]*"|'[^']*')
        )
    )
    c           	      z   |                      d          }	 t          j        |                      d          dd                   \  }}}}}}}	}
|	st          j        |          }|
r t          j                            |          }n=t          j                            t          j                            ||                    }t          j                            |          rt          j        	                    |          d         
                                }t          D ]}||v rt          |d          5 }d                    t          |         t          j        |                                                              d                    }ddd           n# 1 swxY w Y    nn# t$          $ r Y nw xY w|S )	z#Replace path with b64 encoded data.r   pathr   rbz src="data:{};base64,{}"asciiN)groupr   	parse_urlurl2pathosr   normpathjoinexistssplitextlower
file_typesopenformatbase64	b64encodereaddecode	Exception)m	base_pathlinkschemenetlocr   paramsqueryfragmentis_urlis_absolute	file_nameextb64_extfs                  L/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/b64.py	repl_pathr,   D   s    771::DMQ^\]\c\cdj\k\klmnplp\qMrMrJfeXv{ 	'=&&D 	H((..II((i)F)FGGI7>>)$$ 		'""9--a06688C%  '>>i.. !;BB&w/",QVVXX66==gFF                 
 E "     Ks7   D F+ 7AFF+ F 	 F+ #F 	$F+ +
F87F8c                     |                      d          r|                      d          }na|                      d          }|t                              fd|                      d                    z  }||                      d          z  }|S )zReplace.avoidr   c                 $    t          |           S N)r,   )m2r   s    r+   <lambda>zrepl.<locals>.<lambda>j   s    yY/G/G     attrclose)r   RE_TAG_LINK_ATTRsub)r   r   tags    ` r+   replr9   c   s     	www  gggggfoo##$G$G$G$GQWYYYqwwwJr3   c                       e Zd ZdZd ZdS )B64PostprocessorzPost processor for B64.c                 ^    | j         d         t                              fd|          }|S )z0Find and replace paths with base64 encoded file.r   c                 $    t          |           S r0   )r9   )r   basepaths    r+   r2   z&B64Postprocessor.run.<locals>.<lambda>v   s    a):): r3   )configRE_TAG_HTMLr7   )selftextr>   s     @r+   runzB64Postprocessor.runr   s3     ;{+::::DAAr3   N)__name__
__module____qualname____doc__rC    r3   r+   r;   r;   o   s)        !!    r3   r;   c                   (     e Zd ZdZ fdZd Z xZS )B64ExtensionzB64 extension.c                 P    dddgi| _          t                      j        |i | dS )zInitialize.r   .z8Base path for b64 to use to resolve paths - Default: "."N)r?   super__init__)rA   argskwargs	__class__s      r+   rN   zB64Extension.__init__}   s=     #[\
 	$)&)))))r3   c                     t          |          }|                                 |_        |j                            |dd           |                    |            dS )z0Add base 64 tree processor to Markdown instance.b64   N)r;   
getConfigsr?   postprocessorsregisterregisterExtension)rA   mdrS   s      r+   extendMarkdownzB64Extension.extendMarkdown   sW     r""__&&

""3q111
T"""""r3   )rD   rE   rF   rG   rN   rZ   __classcell__)rQ   s   @r+   rJ   rJ   z   sM        * * * * *# # # # # # #r3   rJ   c                      t          | i |S )zReturn extension.)rJ   )rO   rP   s     r+   makeExtensionr]      s     ((((r3   )rG   markdownr   markdown.postprocessorsr    r   r   r   recompileRE_SLASH_WIN_DRIVEr   r@   r6   r,   r9   r;   rJ   r]   rH   r3   r+   <module>rd      sO   2       1 1 1 1 1 1       				  				RZ 455  #	 
 bj
  2:	 	   >	 	 	    }   # # # # #9 # # #*) ) ) ) )r3   