o
    f'hab9  ã                   @   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
 ddlmZ e ej e ¡ d¡ej e 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)Ú
directivesÚ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   úC/usr/lib/python3/dist-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 OptionszŒFor 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Ú	overridesz�Specify 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)   Y   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.cssz	blank.gifziepngfix.htcc                 G   s”   t jj| g|¢R Ž  d | _|  ¡  | jjj}d| jjj }| j	 
| j| j||dœ ¡ | jjjs7| 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_themeÚdocumentÚsettingsr9   r$   Ú
stylesheetÚappendÚs5_stylesheet_templater%   Údisable_current_slideÚadd_metaÚ	s5_footerÚ	s5_headerÚsection_countÚtheme_files_copied)r-   Úargsr9   r:   r   r   r   r)   ™   s(   
ÿ
þÿ


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d|jf | _|jr6tj 	tj 
|j¡d|j¡}tj |¡s5t |¡ ndS d}|rºt |¡D ]}|| jkrIqA|  |||¡rY|| jv rYd||< qA|r]n]tj 	|| j¡}tj |¡r¨t|ƒ�}| ¡ }	W d  ƒ n1 s~w   Y  |	D ]}
|
 ¡ }
|
r¤|
 d¡s¤t|
ƒ}||v r�d}n| |¡  nq…d}nd}|s¸t| jƒ}| |¡ d}|s<t|ƒt| jƒkrãt| jƒ}| ¡ D ]}| |¡ qÌt 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%s/%sÚuiNFé   ú#TzTheme files not found: %sz, c                 S   s   g | ]}d | ‘qS )z%rr   )Ú.0Úfr   r   r   Ú
<listcomp>õ   s    z/S5HTMLTranslator.copy_theme.<locals>.<listcomp>)r>   r?   r   r   rH   r<   Ú_destinationr
   r   r   Údirnamer   ÚmakedirsÚlistdirÚbase_theme_fileÚ	copy_fileÚrequired_theme_filesÚisfileÚopenÚ	readlinesÚstripÚ
startswithrA   Údefault_themeÚlenÚlistÚkeysÚremover   r   )r-   r?   r   Útheme_pathsÚrequired_files_copiedr    r   rO   rU   ÚlinesÚlineÚrequiredr   r   r   rJ   ¶   sr   
ÿ
€

€

ÿ
€€

á 
ÿÿûzS5HTMLTranslator.copy_themez~$|\.bak$|#$|\.cvsignore$c           
   	   C   s  t j ||¡}t j ||¡}|| jv rdS d| j|< t j |¡rw| j |¡r(dS | jj}t j 	|¡r=|j
s=|j |¡ dS t|dƒ}| ¡ }| ¡  t|dƒ}	| t jd¡}|	 | d|| d¡d…  t ¡ ¡¡¡ |	 ¡  |j |¡ dS t j |¡rdS dS )z�
        Copy file `name` from `source_dir` to `dest_dir`.
        Return 1 if the file exists in either `source_dir` or `dest_dir`.
        rL   NÚrbÚwbú/s
   ui/defaultzui/)r
   r   r   rH   rX   Úfiles_to_skip_patternÚsearchr>   r?   Úexistsr   Úrecord_dependenciesÚaddrY   ÚreadÚcloseÚreplaceÚsepÚwriteÚrfindÚencodeÚsysÚgetfilesystemencoding)
r-   r   Ú
source_dirÚdest_dirÚsourcer    r?   Úsrc_fileÚsrc_dataÚ	dest_filer   r   r   rV   ù   s8   


ö

ÿÿÿzS5HTMLTranslator.copy_filec                 C   s~  | j  | j| jd| jji g¡ | j | j¡ | j 	d| j
| jj ¡ | j 	d| j
| jj ¡ | jrF| jdkr?| 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Úlangr   ÚmathjaxrL   Ú z<h1 class="title">z<h1>)ÚheaderÚtitleÚfooterz<div class="presentation">
ÚslideÚslide0)ÚclassesÚidsÚdivz</div>
éÿÿÿÿ) Úhead_prefixÚextendÚdoctypeÚhead_prefix_templater?   Úlanguage_codeÚhtml_prologrA   ÚmetaÚinsertÚcontent_typeÚoutput_encodingÚheadÚmath_headerÚmath_outputr@   Ú	html_headÚfragmentÚbodyr   rF   rE   Ú
html_titlerq   Úlayout_templateÚbody_prefixÚstarttagrG   Úbody_suffixÚ	html_bodyÚbody_pre_docinfoÚdocinfo)r-   Únoder�   rƒ   r‚   Úlayoutr   r   r   Údepart_document  sH   

ÿÿ
þÿÿÿ
þz S5HTMLTranslator.depart_documentc                 C   sH   | j  ¡ }| j d¡ | j | j|d … ¡ | j d¡ | j|d …= d S )Nz<h2>z</h2>)ÚcontextÚpoprE   rA   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™   rA   rF   )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©   rL   rˆ   Úsection)ÚCLASSr„   )rG   r™   rA   Ú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 )NrL   é   zh%sr€   z</%s>
)Ú
isinstanceÚparentr   r«   r­   Úinitial_header_levelr™   rA   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/   r0   rB   rC   r›   r]   rU   Údirect_theme_filesÚindirect_theme_filesrW   r)   r=   rJ   ÚreÚcompilerj   rV   r¤   r¨   rª   r¯   r´   r·   r   r   r   r   r*   ^   s2    	
A "r*   )Ú__doc__Ú__docformat__rv   r
   rº   r   r   r   r   Údocutils.writersr   Údocutils.parsers.rstr   Úrelative_pathr   r   ÚgetcwdÚ_datadirÚ__file__r   r   r   r;   r*   r   r   r   r   Ú<module>   s    þ
;