o $a*@sDdZddlZddlmZddlmZmZmZmZm Z m Z ddl m Z ddl mZddlmZddlmZmZdd lmZdd lmZmZdd lmZdd lmZdd lmZee Z!GdddeZ"dddZ#dddZ$dddZ%dZ&dZ'Gdddej(Z)deddfddZ*ded eddfd!d"Z+dedee,effd#d$Z-dS)%z sphinx.builders.epub3 ~~~~~~~~~~~~~~~~~~~~~ Build epub3 files. Originally derived from epub.py. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N)path)AnyDictList NamedTupleSetTuple) package_dir)Sphinx) _epub_base)ENUMConfig)__)loggingxmlname_checker)copy_asset_file) format_date) make_filenamec@s*eZdZUeed<eed<eeed<dS)NavPointtextrefurichildrenN)__name__ __module__ __qualname__str__annotations__rrrr7/usr/lib/python3/dist-packages/sphinx/builders/epub3.pyrs rltrrtl) horizontalverticalr"r!z vertical-rlz horizontal-tb)r"r!zzUcseZdZdZdZedZdZe e ddZ e Z eZdZdd d Zdeffd d Zdeedd ffdd ZdeeeefdeefddZdeedefddZdddZZS) Epub3Builderz Builder that outputs epub3 files. It creates the metainfo files content.opf, nav.xhtml, toc.ncx, mimetype, and META-INF/container.xml. Afterwards, all necessary files are zipped to an epub file. epubzThe ePub file is in %(outdir)s.F templatesepub3TreturnNcCs<|||||||dS)z/Create the metainfo files and finally the epub.N)get_tocbuild_mimetypebuild_container build_contentbuild_navigation_doc build_toc build_epubselfrrr handle_finishLs zEpub3Builder.handle_finishcs|jj}t}t|jj|d<t|jj|d<t ||d<t ||d<tt d|d<t|jj |d<|jj |d<|S) zaCreate a dictionary with all metadata for the content.opf file properly escaped. description contributorpage_progression_directionibook_scroll_axisz%Y-%m-%dT%H:%M:%SZdateversion epub_version)configepub_writing_modesupercontent_metadatahtmlescapeepub_descriptionepub_contributorPAGE_PROGRESSION_DIRECTIONSgetIBOOK_SCROLL_AXISrr7r8)r0 writing_modemetadata __class__rrr<Vs  zEpub3Builder.content_metadatadocnamescsJt||jj}t||jd<|j|jd<|j|jd<d|jd<dS)Ntheme_writing_modehtml_taguse_meta_charsetTskip_ua_compatible) r;prepare_writingr9r:THEME_WRITING_MODESrB globalcontextrJrK)r0rHrDrFrrrMfs   zEpub3Builder.prepare_writingnavnodescCs>g}|tddgd}|D]}|dsq|ddd}||jvr%q|d|jjkr.qt|d|dg}|d|krP||dj|||q|d|dkrj|d7}|dj|||q|d|kr|dt|kr||dt|ksx|d}|dj|||qt d |djS) acCreate the toc navigation structure. This method is almost same as build_navpoints method in epub.py. This is because the logical navigation structure of epub3 is not different from one of epub2. The difference from build_navpoints method is templates which are used when generating navigation documents. rrr#levelz+Should never reach here. It might be a bug.) appendrsplit ignored_filesr9 epub_tocdepthpoprlen RuntimeError)r0rPnavstackrSnodefilenavpointrrr build_navlistos:        zEpub3Builder.build_navlistnavlistcCs6i}t|jj|d<t|jd|d<||d<|S)z_Create a dictionary with all metadata for the nav.xhtml file properly escaped. langtoc toc_localerb)r=r>r9 epub_language guide_titles)r0rbrErrrnavigation_doc_metadatas z$Epub3Builder.navigation_doc_metadatacCsttd|jjdkr%|jj|jj|ddd}||g}| |n|j }| |}t t |jd|j||d|jvrI|jddSdS)z"Write the metainfo file nav.xhtml.zwriting nav.xhtml file...defaultF)prune_toctrees includehiddenz nav.xhtml_tz nav.xhtmlN)loggerinforr9 epub_tocscopeenvget_and_resolve_doctreeroot_doc get_refnodes toc_add_filesrefnodesrarrjoin template_diroutdirrhfilesrV)r0doctreertrbrrrr,s      z!Epub3Builder.build_navigation_doc)r'N)rrr__doc__namerepilogsupported_remote_imagesrrur rvDOCTYPEdoctypeHTML_TAGrJrKr1rr<rrrMrrrrarhr, __classcell__rrrFrr#:s  " * r#appr'cCs|jjdkrdS|jjsttdt|jj s"ttd|jj s-ttd|jj s8ttd|jj sCttd|jj sNttd|jjsYttd|jjsdttd |jjsottd |jjs|ttd dSdS) Nr$zHconf value "epub_language" (or "language") should not be empty for EPUB3z2conf value "epub_uid" should be XML NAME for EPUB3zGconf value "epub_title" (or "html_title") should not be empty for EPUB3z6conf value "epub_author" should not be empty for EPUB3z;conf value "epub_contributor" should not be empty for EPUB3z;conf value "epub_description" should not be empty for EPUB3z9conf value "epub_publisher" should not be empty for EPUB3zIconf value "epub_copyright" (or "copyright")should not be empty for EPUB3z:conf value "epub_identifier" should not be empty for EPUB3z2conf value "version" should not be empty for EPUB3)builderr{r9rfrlwarningrrmatchepub_uid epub_title epub_authorr@r?epub_publisherepub_copyrightepub_identifierr7rrrrvalidate_config_valuess. rr9c Cspg}|jD]-}t|tr||ifqz |\}}|||fWqty2ttd|Yqw||_dS)z?This converts string styled epub_css_files to tuple styled one.zinvalid css_file: %r, ignoredN)epub_css_files isinstancerrV Exceptionrlrr)rr9rentryfilenameattrsrrrconvert_epub_css_filess    rcCs|t|dddd|ddd|ddd|did|d d dd|d d dd|d ddd|dddd|dddd|ddd|ddd|ddd|ddd|ddd|dgd|dgd|dddd|dgd|d d!d|d"d#d|d$d%d|d&d'd|d(d)d|d*d+d|d,d-dd|d.dd|d/dd|d0d1dtd1d2|jd3td4d5|d6td7d#d#d8S)9N epub_basenamecSs t|jSN)rprojectr/rrr zsetup..r8g@r$ epub_themeepub_theme_optionsrcS|jSr)rr/rrrrrcSrrauthorr/rrrrrrfcSs |jpdS)Nen)languager/rrrrrrcSrrrr/rrrrrrcSrr) copyrightr/rrrrrrunknown epub_schemerro epub_coverr epub_guideepub_pre_filesepub_post_filesrcSrr)html_css_files)r9rrrrrepub_exclude_filesrY epub_tocdupTrnriepub_fix_imagesFepub_max_image_widthrepub_show_urlsinlineepub_use_indexcSrr)html_use_indexr/rrrr rr?r@r:r!r"z config-initedi )priorityzbuilder-initedbuiltin)r7parallel_read_safeparallel_write_safe) add_builderr#add_config_valuer connectrrrrrrsetupsJ   r).rzr=osrtypingrrrrrrsphinxr sphinx.applicationr sphinx.buildersr sphinx.configr r sphinx.localer sphinx.utilrrsphinx.util.fileutilrsphinx.util.i18nrsphinx.util.osutilr getLoggerrrlrrArCrNr~r EpubBuilderr#rrrrrrrrs>           '