o
    Nix9                     @   s   d Z dZddlZddlZddlZddlZddlmZmZmZ ddl	m
Z
 eeje dejejedZdd	 ZG d
d de
jZG dd de
jZdS )z
S5/HTML Slideshow Writer.
reStructuredText    N)frontendnodesutils)	html4css1dummythemesc                 C   s0   t jt| }t j|std| |f |S )Nz(Theme directory not found: %r (path: %r))ospathjointhemes_dir_pathisdirdocutilsApplicationError)namer
    r   U/home/ubuntu/.local/lib/python3.10/site-packages/docutils/writers/s5_html/__init__.py
find_theme   s   
r   c                   @   s   e Zd Zejjddddgddddfd	d
gdddfddgdejdfddgdddfddgddgdddfddgddejd fd!d"gd#ddfd$d%gdejdfd&d'gd(ddff	f Zd)d*iZd+Z	d,Z
d-d. Zd/S )0WriterzS5 Slideshow Specific OptionszFor the S5/HTML writer, the --no-toc-backlinks option (defined in General Docutils Options above) is the default, and should not be changed.aB  Specify an installed S5 theme by name.  Overrides --theme-url.  The default theme name is "default".  The theme files will be copied into a "ui/<theme>" directory, in the same directory as the destination file (output HTML).  Note that existing theme files will not be overwritten (unless --overwrite-theme-files is used).z--themedefaultz<name>	theme_url)r   metavar	overrideszSpecify an S5 theme URL.  The destination file (output HTML) will link to this theme; nothing will be copied.  Overrides --theme.z--theme-urlz<URL>theme)r   r   z{Allow existing theme files in the ``ui/<theme>`` directory to be overwritten.  The default is not to overwrite theme files.z--overwrite-theme-files
store_true)action	validatorzfKeep existing theme files in the ``ui/<theme>`` directory; do not overwrite any.  This is the default.z--keep-theme-filesoverwrite_theme_filesstore_false)destr   z@Set the initial view mode to "slideshow" [default] or "outline".z--view-mode	slideshowoutlinez<mode>)choicesr   r   zONormally hide the presentation controls in slideshow mode. This is the default.z--hidden-controlsT)r   r   r   z^Always show the presentation controls in slideshow mode.  The default is to hide the controls.z--visible-controlshidden_controlszMEnable the current slide indicator ("1 / 15").  The default is to disable it.z--current-slidez:Disable the current slide indicator.  This is the default.z--no-current-slidecurrent_slidetoc_backlinksr   zs5_html writer)writerszhtml writerszhtml4css1 writerc                 C   s   t j|  t| _d S N)r   r   __init__S5HTMLTranslatortranslator_classselfr   r   r   r(   X   s   
zWriter.__init__N)__name__
__module____qualname__r   r   settings_specr   validate_booleansettings_default_overridesconfig_sectionconfig_section_dependenciesr(   r   r   r   r   r   "   sh    

.r   c                   @   s   e Zd ZdZdZdZdZ	 dZ	 dZ	 dZ		 e	e Z
	 dd	 Zd
d Zdd ZedZdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r)   a  <!-- configuration parameters -->
<meta name="defaultView" content="%(view_mode)s" />
<meta name="controlVis" content="%(control_visibility)s" />
<!-- style sheet links -->
<script src="%(path)s/slides.js" type="text/javascript"></script>
<link rel="stylesheet" href="%(path)s/slides.css"
      type="text/css" media="projection" id="slideProj" />
<link rel="stylesheet" href="%(path)s/outline.css"
      type="text/css" media="screen" id="outlineStyle" />
<link rel="stylesheet" href="%(path)s/print.css"
      type="text/css" media="print" id="slidePrint" />
<link rel="stylesheet" href="%(path)s/opera.css"
      type="text/css" media="projection" id="operaFix" />
zA
<style type="text/css">
#currentSlide {display: none;}
</style>
z<div class="layout">
<div id="controls"></div>
<div id="currentSlide"></div>
<div id="header">
%(header)s
</div>
<div id="footer">
%(title)s%(footer)s
</div>
</div>
r   __base__)z
slides.csszoutline.cssz	print.cssz	opera.cssz	slides.js)zs5-core.csszframing.cssz
pretty.cssc              
   G   s   t jj| g|R   d | _z|   W n tjy- } z| jj	| W Y d }~nd }~ww | jj
j}d| jj
j }| j| j| j||d  | jj
jsT| j| j | jd g | _g | _d| _d | _d S )N)visiblehidden)r
   	view_modecontrol_visibilityz)<meta name="version" content="S5 1.1" />
r   )r   HTMLTranslatorr(   theme_file_pathsetup_themer   r   documentreporterwarningsettingsr8   r#   
stylesheetappends5_stylesheet_templater$   disable_current_slidemeta	s5_footer	s5_headersection_counttheme_files_copied)r,   argser8   r9   r   r   r   r(      s2   



zS5HTMLTranslator.__init__c                 C   s:   | j jjr|   d S | j jjr| j jj| _d S td)Nz&No theme specified for S5/HTML writer.)r=   r@   r   
copy_themer   r;   r   r   r+   r   r   r   r<      s   

zS5HTMLTranslator.setup_themec                 C   s  | j j}t|j}|g}i | _i }d|j | _|jstdt	j
t	j
|jd|j}t	j
|s8t	| d}|rt	|D ]}|| jkrIqA| |||rY|| jv rYd||< qA|r]n_t	j
|| j}t	j
|rt|dd}| }	W d   n1 sw   Y  |	D ]}
|
 }
|
r|
d	st|
}||v rd}n||  nqd}nd}|st| j}|| d}|s<t|t| jkrt| j}| D ]}|| qtd
ddd |D  dS )a  
        Locate & copy theme files.

        A theme may be explicitly based on another theme via a '__base__'
        file.  The default base theme is 'default'.  Files are accumulated
        from the specified theme, any base themes, and 'default'.
        zui/%szjOutput path not specified, you may need to copy the S5 theme files "by hand" or set the "--output" option.uiFTzutf-8)encodingN#zTheme files not found: %sz, c                 s   s    | ]}d | V  qdS )z%rNr   ).0fr   r   r   	<genexpr>   s    z.S5HTMLTranslator.copy_theme.<locals>.<genexpr>)r=   r@   r   r   rI   r;   outputr   r   r	   r
   r   dirnamer   makedirslistdirbase_theme_file	copy_filerequired_theme_filesisfileopen	readlinesstrip
startswithrB   default_themelenlistkeysremove)r,   r@   r
   theme_pathsrequired_files_copiedr   r   rQ   rW   lineslinerequiredr   r   r   rL      st   







 
zS5HTMLTranslator.copy_themez~$|\.bak$|#$|\.cvsignore$c           
   
   C   s2  t j||}t j||}|| jv rdS d| j|< t j|r| j|r(dS | jj}t j	|r=|j
s=|j| dS t|d}| }W d   n1 sQw   Y  t|d$}	|t jd}|	|d||dd t  W d   n1 sw   Y  |j| dS t j|rdS dS )z
        Copy file `name` from `source_dir` to `dest_dir`.
        Return True if the file exists in either `source_dir` or `dest_dir`.
        TNrbwb/s
   ui/defaultzui/)r	   r
   r   rI   rZ   files_to_skip_patternsearchr=   r@   existsr   record_dependenciesaddr[   readreplacesepwriterfindencodesysgetfilesystemencoding)
r,   r   
source_dirdest_dirsourcer   r@   src_filesrc_data	dest_filer   r   r   rX      s:   


zS5HTMLTranslator.copy_filec                 C   sd  | j | j| jd| jji g | j| j | jd d  | j	 | _	| j
r9| jdkr2| j	| j
 n| j| j
 | j| j	dd   | j| j d| j}d| j}d| jdd}| j|||d }| j| | jd | j| d	gd
gdd | js| jd | jdd | j| jdd  | j | j | j | jd d   d S )Nlangmathjax    z<h1 class="title">z<h1>)headertitlefooterz<div class="presentation">
slideslide0)classesidsdivz</div>
r   )head_prefixextenddoctypehead_prefix_templater@   language_codehtml_prologrB   rE   headmath_headermath_outputrA   	html_headfragmentbodyr   rG   rF   
html_titlerr   layout_templatebody_prefixstarttagrH   body_suffixinsert	html_bodybody_pre_docinfodocinfo)r,   noder   r   r   layoutr   r   r   depart_document  sF   



z S5HTMLTranslator.depart_documentc                 C   sH   | j  }| jd | j| j|d   | jd | j|d = d S )Nz<h2>z</h2>)contextpoprF   rB   r   r   )r,   r   startr   r   r   depart_footer;  s
   
zS5HTMLTranslator.depart_footerc                 C   sJ   | j  }dg}|| j|d   |d | j|d = | j| d S )Nz<div id="header">

</div>
)r   r   r   r   rB   rG   )r,   r   r   r   r   r   r   depart_headerB  s   

zS5HTMLTranslator.depart_headerc                 C   sp   | j s	| jd |  j d7  _ |  jd7  _| jdkr*| j| j|ddd d S | j| j|ddd d S )Nr   r   r   section)CLASSr   )rH   r   rB   section_levelr   r,   r   r   r   r   visit_sectionJ  s   
zS5HTMLTranslator.visit_sectionc                 C   sn   t |jtjr.| j| j d }|dkrd}d| }| j| ||d | j	d|  d S t
j| | d S )Nr      zh%sr   z</%s>
)
isinstanceparentr   r   r   initial_header_levelr   rB   r   r   r   r:   visit_subtitle)r,   r   leveltagr   r   r   r   U  s   zS5HTMLTranslator.visit_subtitlec                 C   s   t j| | d S r'   )r   r:   visit_titler   r   r   r   r   `  s   zS5HTMLTranslator.visit_titleN)r-   r.   r/   rC   rD   r   r_   rW   direct_theme_filesindirect_theme_filesrY   r(   r<   rL   recompilerl   rX   r   r   r   r   r   r   r   r   r   r   r)   ]   s2    	
A!r)   )__doc____docformat__rw   r	   r   r   r   r   r   docutils.writersr   relative_pathr
   r   getcwdrT   __file__r   r   r   r:   r)   r   r   r   r   <module>   s   
;