
    ^h                         S r SSK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Jr  SSKJr  \
R                   " S5      SLr\R$                  S:H  r " S	 S
\5      rg)z$Export to PDF via a headless browser    N)util)Booldefault   )HTMLExporter
playwrightntc                      ^  \ rS rSrSrSr\" SSS9R                  SS9r\" SS	S9R                  SS9r	\
" S
5      S 5       r\
" S5      S 5       r\" SSS9R                  SS9rS rSU 4S jjrSrU =r$ )WebPDFExporter   zWriter designed to write to PDF files.

This inherits from :class:`HTMLExporter`. It creates the HTML using the
template machinery, and then run playwright to create a pdf.
zPDF via HTMLFzTWhether to allow downloading Chromium if no suitable version is found on the system.)helpT)configz
        Split generated notebook into multiple pages.

        If False, a PDF with one long page will be generated.

        Set to True to match behavior of LaTeX based PDF generator
        file_extensionc                     g)N.html selfs    T/home/james-whalen/.local/lib/python3.13/site-packages/nbconvert/exporters/webpdf.py_file_extension_default&WebPDFExporter._file_extension_default/   s        template_namec                     g)Nwebpdfr   r   s    r   _template_name_default%WebPDFExporter._template_name_default3   s    r   a  
        Disable chromium security sandbox when converting to PDF.

        WARNING: This could cause arbitrary code execution in specific circumstances,
        where JS in your notebook can execute serverside code! Please use with
        caution.

        ``https://github.com/puppeteer/puppeteer/blob/main@%7B2020-12-14T17:22:24Z%7D/docs/troubleshooting.md#setting-up-chrome-linux-sandbox``
        has more information.

        This is required for webpdf to work inside most container environments.
        c                   ^  U 4S jn[         R                  R                  5       n[        R                  " SSS9nU   UR                  UR                  S5      5        SSS5         S nUR                  XR" U5      5      R                  5       n[        R                  " UR                  5        U$ ! , (       d  f       NY= f! [        R                  " UR                  5        f = f)zRun playwright.c                   >#    TR                   (       a  S/O/ n SSKJn  TR
                  (       a+  [        R                  SSSS	/n[        R                  " U5        U" 5       R                  5       I Sh  vN nUR                  n UR                  S
S
S
US9I Sh  vN nUR                  5       I Sh  vN n	U	R!                  SS9I Sh  vN   U	R#                  S5      I Sh  vN   U	R%                  SU R&                   3SS9I Sh  vN   U	R#                  S5      I Sh  vN   SS0n
TR(                  (       dK  U	R+                  S5      I Sh  vN nUS   nUS   nU
R-                  [/        US5      [/        US5      S.5        U	R0                  " S0 U
D6I Sh  vN nUR3                  5       I Sh  vN   UR                  5       I Sh  vN   U$ ! [         a  nSn[	        U5      UeSnAff = f GN~ GNZ! [         a,  nSnUR                  5       I Sh  vN    [	        U5      UeSnAff = f GN~ GNj GNT GN2 GN N N N Nz7f)zRun main playwright script.z--no-sandboxr   )async_playwrightzhPlaywright is not installed to support Web PDF conversion. Please install `nbconvert[webpdf]` to enable.Nz-mr   installchromiumF)handle_siginthandle_sigtermhandle_sighupargszNo suitable chromium executable found on the system. Please use '--allow-chromium-download' to allow downloading one,or install it using `playwright install chromium`.print)mediad   zfile://networkidle)
wait_untilprint_backgroundTa  () => {
                    const rect = document.body.getBoundingClientRect();
                    return {
                    width: Math.ceil(rect.width) + 1,
                    height: Math.ceil(rect.height) + 1,
                    }
                }widthheighti@8  )r-   r.   r   )disable_sandboxplaywright.async_apir    ModuleNotFoundErrorRuntimeErrorallow_chromium_downloadsys
executable
subprocess
check_callstartr"   launch	Exceptionstopnew_pageemulate_mediawait_for_timeoutgotonamepaginateevaluateupdateminpdfclose)	temp_filer&   r    emsgcmdr   r"   browserpage
pdf_params
dimensionsr-   r.   pdf_datar   s                  r   main+WebPDFExporter.run_playwright.<locals>.mainJ   s=    '+';';N#D/A ++~~t\9jQ%%c*/17799J!**H/ ("'UY] !0 !  !))++D$$7$333'',,,))ginn%56=)QQQ'',,,,d3J== $(==$ 
 #7+#H-!!!$UH!5"%fh"7 "XX3
33H--/!!//###Ow ' /D  #3'Q./ :  /I 
 !oo'''"3'Q./ ,3,Q,$ 4!#s  I	G AI	5G36I	G9 G6G9 !I	4H25I	H5I	$H8%$I		H;
I	"H>#-I	IAI	II	4I5I	II	
G0G++G00I	6G9 9
H/H*HH**H//I	5I	8I	;I	>I	I	I	I	I	r   F)suffixdeletezutf-8Nc                     [         (       a  [        R                  " 5       O[        R                  " 5       n[        R                  " U5        UR                  U 5      $ )zRun an internal coroutine.)
IS_WINDOWSasyncioProactorEventLoopnew_event_loopset_event_looprun_until_complete)coroloops     r   run_coroutine4WebPDFExporter.run_playwright.<locals>.run_coroutine   sI     "z --/ //1  &&t,..t44r   )
concurrentfuturesThreadPoolExecutortempfileNamedTemporaryFilewriteencodesubmitresultosunlinkr@   )r   htmlrP   poolrG   r]   rO   s   `      r   run_playwrightWebPDFExporter.run_playwrightG   s    @	D !!446 //wuM	OODKK01 	&	5 {{=$y/BIIKH IIinn%) Y& IIinn%s   !B1'(C 1
B?"C$c                    > [         TU ]  " U4SU0UD6u  pBU R                  R                  S5        U R	                  U5      nU R                  R                  S5        SUS'   XR4$ )zConvert from a notebook node.	resourceszBuilding PDFzPDF successfully createdz.pdfoutput_extension)superfrom_notebook_nodeloginforl   )r   nbro   kwrj   rO   	__class__s         r   rr   !WebPDFExporter.from_notebook_node   sf    '4RS9SPRSn%&&t,01 )/	$%""r   r   )N)__name__
__module____qualname____firstlineno____doc__export_from_notebookr   tagr3   rA   r   r   r   r/   rl   rr   __static_attributes____classcell__)rw   s   @r   r   r      s     *"c 
cc 
 	 
cc    _   
cc  `D# #r   r   )r}   rV   concurrent.futuresr_   rh   r6   r4   rb   	importlibr   importlib_util	traitletsr   r   rj   r   	find_specPLAYWRIGHT_INSTALLEDr@   rU   r   r   r   r   <module>r      sV    *
   	  
  , # %//=TI WW_
_#\ _#r   