
    Mh5                        d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlZddlZddlmZ ddlmZ ddlmZmZmZmZ ddlm	Z dd	lmZ  ed
 ej                            d          dd         D                       dk     rddlmZ n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' ddl(m)Z) ddl*m+Z+ ddl,m-Z- d Z. G d de-          Z/dS )zHTML Exporter class    N)Path)AnyDictOptionalTuple)BeautifulSoup)jupyter_path)BoolUnicodedefaultvalidate)r   )Configc              #   4   K   | ]}t          |          V  d S N)int).0xs     X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/nbconvert/exporters/html.py	<genexpr>r      s(      ;;AQ;;;;;;    .   )r   r   r   )contextfilter)pass_context)split_template_path)NotebookNode)Highlight2HTML)IPythonRendererMarkdownWithMath)WidgetsDataTypeFilter)iso639_1   )TemplateExporterc                    t          d          }g }d}|D ]}t          j        |          D ]\  }}}d|v rd|v rt          t	          |          dz  d          5 }t          j        |                                          d         }	ddd           n# 1 swxY w Y   |	| k    s| |	                    d          v r,|	                    |	           |	}
t	          |          dz  |	z  }t          |          d	k    rd
|  d}t          |          t          |          dk    rd|  d| d}t          |          |
|fS )a  
    Find a JupyterLab theme location by name.

    Parameters
    ----------
    theme_name : str
        The name of the labextension theme you want to find.

    Raises
    ------
    ValueError
        If the theme was not found, or if it was not specific enough.

    Returns
    -------
    theme_name: str
        Full theme name (with scope, if any)
    labextension_path : Path
        The path to the found labextension on the system.
    labextensionsNzpackage.jsonthemeszutf-8)encodingname/r   zCould not find lab theme ""r"   z Found multiple themes matching "z": z<. Please be more specific about which theme you want to use.)r	   oswalkopenr   jsonloadsreadsplitappendlen
ValueError)
theme_namepathsmatching_themes
theme_pathpathdirpathdirnames	filenamesfobjlabext_namefull_theme_namemsgs               r   find_lab_themerA   %   s   * ))EOJ H H,.GDMM 	H 	H(GXy**x8/C/C $w--.87KKK Bt"&*TYY[["9"9&"AKB B B B B B B B B B B B B B B *,,
k>O>OPS>T>T0T0T#**;777&1O!%g!9K!GJ	H ?q  8:888oo
?aIz I Io I I I 	 ooJ&&s   -BBBc                       e Zd ZdZdZ edd                              d          Z edd	                              d          Z	 ed
d                              d          Z
 edd                              d          Z edd          Z edd                              d          Z edd                              d          Z edd                              d          Z edd                              d          Z ed          d             Z ed          d             Z edd                              d          Z edd                              d          Z edd                              d          Z edd                               d          Zd!Z ei d"                              d          Ze fd#            Z ed$d%                              d          Z ed&          d'             Ze d(             Z! fd)Z"	 d1d+e#d,e$e%e&e'f                  d-e'd.e(e&e%e&e'f         f         f fd/Z) fd0Z* xZ+S )2HTMLExportera'  
    Exports a basic HTML document.  This exporter assists with the export of
    HTML.  Inherit from it if you are writing your own HTML template and need
    custom preprocessors/filters.  If you don't need custom preprocessors/
    filters, just change the 'template_file' config option.
    HTML   ¶z+The text used as the text for anchor links.)helpT)configFz*If anchor links should be included or not.zGhttps://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.jszW
        URL to load require.js from.

        Defaults to loading from cdnjs.
        z]https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_CHTML-full,SafezT
        URL to load Mathjax from.

        Defaults to loading from cdnjs.
        zIhttps://cdnjs.cloudflare.com/ajax/libs/mermaid/10.7.0/mermaid.esm.min.mjszV
        URL to load MermaidJS from.

        Defaults to loading from cdnjs.
        zAhttps://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.jszS
        URL to load jQuery from.

        Defaults to loading from cdnjs.
        zhttps://unpkg.com/zURL base for Jupyter widgets zFull URL for Jupyter widgets*z-Semver range for Jupyter widgets HTML managerfile_extensionc                     dS )Nz.html selfs    r   _file_extension_defaultz$HTMLExporter._file_extension_default   s    wr   template_namec                     dS )NlabrL   rM   s    r   _template_name_defaultz#HTMLExporter._template_name_default   s    ur   lightzwTemplate specific theme(e.g. the name of a JupyterLab CSS theme distributed as prebuilt extension for the lab template)zWhether the HTML in Markdown cells and cell outputs should be sanitized.This should be set to True by nbviewer or similar tools.z=Whether the svg to image data attribute encoding should occurz;Whether or not to embed images as base64 in markdown cells.	text/htmlzOptions to be passed to the pygments lexer for highlighting markdown code blocks. See https://pygments.org/docs/lexers/#available-lexers for available options.c                     t          dg diddid          }t                      j        r<t                      j                                        }|                    |           |}|S )Ndisplay_data_priority)
z(application/vnd.jupyter.widget-view+jsonzapplication/javascriptrU   ztext/markdownzimage/svg+xmlztext/vnd.mermaidz
text/latexz	image/pngz
image/jpegz
text/plainenabledT)NbConvertBaseHighlightMagicsPreprocessor)r   superdefault_configcopymerge)rN   cc2	__class__s      r   r\   zHTMLExporter.default_config   s     , . . ." 1:4/@ 
 
& 77! 	',,..BHHQKKKAr   enz;Language code of the content, should be one of the ISO639-1language_codec                     | j         t          vr-| j                            d| j                    |d         j        S |d         S )NzW"%s" is not an ISO 639-1 language code. It has been replaced by the default value "en".traitvalue)rc   r!   logwarningdefault_value)rN   proposals     r   _valid_language_codez!HTMLExporter._valid_language_code   sQ    X--HB"  
 G$22  r   c           
      j   |                     di           }|                     di           }|                     di                                di                                dd          }t          d
d|| j        || j        | j        d| j        }t          |	                              |          S )z?Markdown to HTML filter respecting the anchor_link_text settingcellattachments	resourcesmetadatar9   rH   F)escapern   embed_imagesr9   anchor_link_textexclude_anchor_links)rendererrL   )getr   rr   rs   rt   lexer_optionsr   render)rN   contextsourcerm   rn   r9   ru   s          r   markdown2htmlzHTMLExporter.markdown2html   s     {{62&&hh}b11{{;++//
B??CCFBOO" 
#*!2!%!:
 
  
 
  22299&AAAr   c              #   n   K   t                                                      E d{V  d| j        fV  dS )zGet the default filters.Nr{   )r[   default_filtersr{   )rN   ra   s    r   r}   zHTMLExporter.default_filters   sI      77**,,,,,,,,, 2333333r   Nnbro   kwreturnc                 &   |j                             di           }|                    d|                    dd                    }| j                            dt          ||                     }|                     |          }t          | j        | |          }|                     d|           |                     d|            t                      j	        ||fi |\  }}t          |d	
          }	d}
|	                    d          D ]}d|j        d<   |
dz  }
|
r| j                            d|
           |	                    d          D ]}d|j        d<   |	                    d          D ]}d|j        d<   t          |	          |fS )zConvert from notebook node.language_infopygments_lexerr(   Nhighlight_code)r   parent)notebook_metadatar   ro   filter_data_typezhtml.parser)featuresr   zimg:not([alt])z/No description has been provided for this imagealtr"   z+Alternative text is missing on %s image(s).z%.jp-Notebook div.jp-Cell-inputWrapper0tabindexz%.jp-Notebook div.jp-OutputArea-output)rp   rv   filtersr   _init_resourcesr    _nb_metadataregister_filterr[   from_notebook_noder   selectattrsrg   rh   str)rN   r~   ro   r   langinfolexerr   r   htmlsoupmissing_altelemra   s               r   r   zHTMLExporter.from_notebook_node  s    ;???B77-x||FD/I/IJJ))nE$OOO
 
 ((33	0"/	
 
 
 	-~>>>/1ABBB4%''4RIIbIIiTM:::KK 011 	 	D QDJu1KK 	YHJKXXXKK GHH 	) 	)D%(DJz""KK GHH 	) 	)D%(DJz""4yy)##r   c                 v     fd}d }d fd	} fd}t                                          |          } j        |d<   ||d<   ||d<   ||d	<   ||d
<    j        |d<    j        |d<    j        |d<    j        |d<    j        |d<    j        |d<    j	        |d<    j
        |d<    j        |d<    j        |d<   |S )Nc                     j         }d|j                            ||           d         z  }t          j        |          S )N"<style type="text/css">
%s</style>r   environmentloader
get_source
markupsafeMarkup)r(   envcoderN   s      r   resources_include_cssz;HTMLExporter._init_resources.<locals>.resources_include_css(  s@    "C<
@U@UVY[_@`@`ab@cdD$T***r   c           
         t          |           \  }}t          |dz            5 }|                                }d d d            n# 1 swxY w Y   t          j        |          D ]}dt          |                                           d}||v rt          j        |          d         }t          ||z  d          5 }t          j
        |                                          }	|	                    dd                              d          }
|                    |d	| d
|
 d          }d d d            n# 1 swxY w Y   d|z  }t          j        |          S )Nz	index.csszurl()r   rb   
r   asciiz	url(data:;base64,r   )rA   r-   r0   r+   listdirr   as_posix	mimetypes
guess_typebase64	b64encodereplacedecoder   r   )r(   _r8   filedataasset	local_url	mime_type	assetfilebase64_data
base64_strr   s               r   resources_include_lab_themezAHTMLExporter._init_resources.<locals>.resources_include_lab_theme-  s   *400MAzj;.// #4yy{{# # # # # # # # # # # # # # # J// e e<4;;#7#7#9#9<<<	$$ ) 4U ; ;A >I j50$77 e9&,&6y~~7G7G&H&H%0%8%8%D%D%K%KG%T%T
#||I7c97c7cV`7c7c7cdd	e e e e e e e e e e e e e e e =tCD$T***s$   AA
A
=A-D66D:	=D:	Fc                     j         }d|rdnd d|j                            ||           d          d}t          j        |          S )zLGet the resources include JS for a name. If module=True, import as ES modulez<script ztype="module"rH   z>
r   z	</script>r   )r(   moduler   r   rN   s       r   resources_include_jsz:HTMLExporter._init_resources.<locals>.resources_include_jsE  sW    "Cv6 ArvvcjF[F[\_aeFfFfghFivvvD$T***r   c                    j         }t          j        |           \  }}	 |j                            ||           d                             d          }n# t          $ r t          |           }j        D ]v}t          j
        j        |g|R  }t          j
                            |          r>t          |d          5 }|                                }	 ddd            n## 1 swxY w Y   wd| d|}	t          |	          Y nw xY wt!          j        |          }|                    dd                              d	          }d
| d| }
t)          j        |
          S )z)Get the resources include url for a name.r   utf8r   NzNo file z
 found in r   r   r   zdata:r   )r   r   r   r   r   encodeUnicodeDecodeErrorr   template_pathsr+   r9   joinexistsr-   r0   r4   r   r   r   r   r   r   )r(   r   r   r'   r   pieces
searchpathfilenamefr@   srcrN   s              r   resources_include_urlz;HTMLExporter._init_resources.<locals>.resources_include_urlK  s   "C"+"6t"<"<Ix* z,,S$77:AA&II% * * * -T22"&"5 * *J!w|J@@@@Hw~~h// "!(D11 "Q#$6688D!" " " " " " " " " " " " " " " " FTEEzEEC$S//)" "* #D))D<<s++227;;D3)33T33C$S)))s6   4A A(D>C!D!C%%D(C%)DDthemeinclude_cssinclude_lab_theme
include_jsinclude_urlrequire_js_urlmathjax_urlmermaid_js_url
jquery_urljupyter_widgets_base_urlwidget_renderer_urlhtml_manager_semver_rangeshould_sanitize_htmlrc   should_not_encode_svg)F)r[   r   r   r   r   r   r   r   r   r   sanitize_htmlrc   skip_svg_encoding)rN   ro   r   r   r   r   ra   s   `     r   r   zHTMLExporter._init_resources'  s?   	+ 	+ 	+ 	+ 	+
	+ 	+ 	+0	+ 	+ 	+ 	+ 	+ 	+	* 	* 	* 	* 	*4 GG++I66	!Z	'#8	- )D	%&"6	,#8	- &*&9	"##'#3	- &*&9	"#"&/	,040M	,-+/+C	'(151O	-.,0,>	()%)%7	/"-1-C	)*r   r   ),__name__
__module____qualname____doc__export_from_notebookr   tagrs   r
   rt   r   r   r   r   r   r   r   r   rO   rS   r   r   r   rr   output_mimetypeTraitletsDictrw   propertyr\   rc   r   rk   r   r{   r}   r   r   r   r   r   r   r   r   __classcell__)ra   s   @r   rC   rC   [   sf         "wt*WXXX\\ ]    4,XYYY]] ^   WQ   
cc  'g   
cc  WS  N K   
cc   'w#A     	cc  "'"+IJJJNNVZN[[ 'A! ! !	cc  W   W_   G G   
cc 

 DG   
cc  M   
cc 
 4Q  	cc  "O!M
\   
cc      X4 GP  	cc  Xo! ! ! B B ]B"4 4 4 4 4 GK!$ !$!$+3DcN+C!$RU!$	sDcN"	#!$ !$ !$ !$ !$ !$FN N N N N N N N Nr   rC   )0r   r   r.   r   r+   pathlibr   typingr   r   r   r   jinja2r   bs4r   jupyter_core.pathsr	   	traitletsr
   r   r   r   r   traitlets.configr   tuple__version__r1   r   r   jinja2.loadersr   nbformatr   nbconvert.filters.highlightr   "nbconvert.filters.markdown_mistuner   r   'nbconvert.filters.widgetsdatatypefilterr    nbconvert.utils.iso639_1r!   templateexporterr#   rA   rC   rL   r   r   <module>r      s#    
       				       - - - - - - - - - - - -            + + + + + + 6 6 6 6 6 6 6 6 6 6 6 6 + + + + + + # # # # # #5;;+11#66rr:;;;;;iGG$$$$$$$444444 . . . . . . ! ! ! ! ! ! 6 6 6 6 6 6 P P P P P P P P I I I I I I - - - - - - . . . . . .3' 3' 3'lZ Z Z Z Z# Z Z Z Z Zr   