o $aJ9@sdZddlZddlZddlmZmZmZmZmZm Z m Z ddl m Z ddl mZmZmZddlmZmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd l m!Z!ddl"m#Z#m$Z$ddl%m Z m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.erddl/m0Z0ddl1m2Z2ddl3m4Z4e&5e6Z7hdZ8GdddeZ9GdddeZ:Gddde9Z;Gddde9ZGd#d$d$e9Z?e j@e jAe jBejCe jDd%ZEGd&d'd'e9ZFGd(d)d)e9ZGGd*d+d+e9ZHGd,d-d-e9ZIGd.d/d/e9ZJGd0d1d1e9ZKGd2d3d3e9ZLGd4d5d5eZMGd6d7d7ee9ZNGd8d9d9e9ZOGd:d;d;e9ZPdeeQeffd?d@ZRdS)Az sphinx.transforms ~~~~~~~~~~~~~~~~~ Docutils transforms used by Sphinx when reading documents. :copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. N) TYPE_CHECKINGAnyDict GeneratorListOptionalTuple)nodes)ElementNodeText) Transform Transformer)ContentsFilter) SmartQuotes)normalize_language_tag) smartchars)addnodes)Config)RemovedInSphinx60Warning)___)docutilslogging) new_document) format_date) NodeMatcherapply_source_workaroundis_smartquotable)Sphinx)StandardDomain)BuildEnvironment>todayreleaseversionc@s>eZdZdZed ddZed ddZedefd d Zd S)SphinxTransformzA base class of Transforms. Compared with ``docutils.transforms.Transform``, this class improves accessibility to Sphinx APIs. returnrcC|jjS)z)Reference to the :class:`.Sphinx` object.)envappselfr,Qs    z"SphinxTransformer.apply_transforms)r(r!r&N)r&N) r2r3r4r5r r/__annotations__r(rr9r> __classcell__r,r,r?r-r7Fs   r7c@&eZdZdZdZdeddfddZdS)DefaultSubstitutionszL Replace some substitutions if they aren't defined in the document. kwargsr&NcKs|tt|jj}|jtjD],}|d}||vr;|j|}|dkr2|s2t|jj p,t d|jj d}| t ||qdS)Nrefnamer"z %b %d, %Y)language)default_substitutionssetr/substitution_defstraverser substitution_referencer1r today_fmtrrH replace_selfr )r+rF to_handlerefrGtextr,r,r-applyks  zDefaultSubstitutions.applyr2r3r4r5default_priorityrrSr,r,r,r-rDdsrDc@rC)MoveModuleTargetszv Move module targets that are the first thing in a section to the section title. XXX Python specific rErFr&NcKsnt|jtjD]+}|dsq d|vr4|jjtjur4|j|dkr4|d|jddd<|j |q dS)Nidsismodr) listr/rLr targetparentr@sectionindexremover+rFnoder,r,r-rSs zMoveModuleTargets.applyrTr,r,r,r-rVysrVc@rC)HandleCodeBlocksz5 Several code block related transformations. rErFr&NcKs8|jtjD]}tdd|jDr||jqdS)Ncss|] }t|tjVqdSr8)r;r doctest_block).0childr,r,r- z)HandleCodeBlocks.apply..)r/rLr block_quoteallchildrenrOr`r,r,r-rSs zHandleCodeBlocks.applyrTr,r,r,r-rbrbc@rC) AutoNumberingzO Register IDs of tables, figures and literal_blocks to assign numbers. rErFr&NcKsT|jd}|jtjD]}||r'||dur'|dgkr'|j|q dS)NstdrW) r( get_domainr/rLr r is_enumerable_nodeget_numfig_titlenote_implicit_target)r+rFdomainrar,r,r-rSs    zAutoNumbering.applyrTr,r,r,r-rlrkrlc@rC)SortIdszA Sort section IDs so that the "id[0-9]+" one comes last. irFr&NcKs\|jtjD]$}t|ddkr+|dddr+|ddd|ddg|d<qdS)NrWrYrid)r/rLr r]len startswithr`r,r,r-rSs ""z SortIds.applyrTr,r,r,r-rsrkrs)z literal-blockz doctest-blockrawr^imagec@rC)ApplySourceWorkaroundz0 Update source and rawsource attributes rFr&NcKs.|jD]}t|tjtjfrt|qdSr8)r/rLr;r TextElementrxrr`r,r,r-rSs zApplySourceWorkaround.applyrTr,r,r,r-ryrkryc@rC)AutoIndexUpgraderz[ Detect old style (4 column based indices) and automatically upgrade to new style. rErFr&NcKs|jtjD]9}d|vr@tdd|dDr@td|d}tj||dt|dD]\}}t |dkr?|d|d|<q-qdS)Nentriescss|] }t|dkVqdS)N)ru)rdentryr,r,r-rfrgz*AutoIndexUpgrader.apply..zG4 column based index found. It might be a bug of extensions you use: %r)locationr~r8) r/rLrr^anyrloggerwarning enumerateru)r+rFramsgirr,r,r-rSs zAutoIndexUpgrader.applyrTr,r,r,r-r|rkr|c@rC)ExtraTranslatableNodesz! Make nodes translatable rzrFr&Nc sZ|jjfddtDsdSdtdtffdd }|j|D]}d|d<q$dS) Ncsg|] \}}|vr|qSr,r,)rdkv)targetsr,r- sz0ExtraTranslatableNodes.apply..rar&cst|tSr8)r;tuplera) target_nodesr,r-is_translatable_nodesz:ExtraTranslatableNodes.apply..is_translatable_nodeT translatable)r1gettext_additional_targetsTRANSLATABLE_NODESitemsr boolr/rL)r+rFrrar,)rrr-rSs zExtraTranslatableNodes.applyrTr,r,r,r-rrkrc@rC)UnreferencedFootnotesDetectorz9 Detect unreferenced footnotes and emit warnings rFr&Nc s|jjD]#dgkr qdd|jjvr'tjtddddddq|jjD]tfdd|jjDsFtjtd dddq,dS) Nnamesrz Footnote [%s] is not referenced.rQfootnote)typesubtyperc3s |] }|ddkVqdS)autoNr,)rdrQrr,r-rf sz6UnreferencedFootnotesDetector.apply..zFootnote [#] is not referenced.) r/ footnotes footnote_refsrrr autofootnotesrautofootnote_refsr+rFr,rr-rSs"    z#UnreferencedFootnotesDetector.applyrTr,r,r,r-rrkrc@rC)DoctestTransformz.Set "doctest" style to each doctest_block nodeirFr&NcKs&|jtjD] }|ddqdS)Nclassesdoctest)r/rLr rcappendr`r,r,r-rSszDoctestTransform.applyrTr,r,r,r-rrcsDeZdZdZdZdededdffdd Zdeddfd d ZZS) FigureAlignerz- Align figures to center by default. iargsrFr&Ncs"tdttj|i|dS)NzFigureAilgner is deprecated.)warningswarnrr=__init__)r+rrFr?r,r-r!szFigureAligner.__init__cKs0ttjtj}|j|D]}|ddq dS)Naligndefault)rr tablefigurer/rL setdefault)r+rFmatcherrar,r,r-rS&szFigureAligner.apply) r2r3r4r5rUrrrSrBr,r,r?r-rs rc@rC)FilterSystemMessagesz&Filter system messages from a doctree.rFr&NcKsT|jjrdnd}t|jtjD]}|d|kr'td| |j |qdS)Nlevelz%s [filtered system message]) r1 keep_warningsrZr/rLr system_messagerdebugastextr\r_)r+rF filterlevelrar,r,r-rS0s  zFilterSystemMessages.applyrTr,r,r,r-r,rrc@s*eZdZdZejZdejddfddZ dS)SphinxContentsFilterzx Used with BuildEnvironment.add_toc_from() to discard cross-file links within table-of-contents link nodes. rar&NcCstjr8)r SkipNode)r+rar,r,r- visit_image?sz SphinxContentsFilter.visit_image) r2r3r4r5r ignore_node_but_process_childrenvisit_pending_xrefr rxrr,r,r,r-r8srcsdeZdZdZdZdeddffdd Zdefdd Zd e e de e e e fddffd d ZZS) SphinxSmartQuoteszr Customized SmartQuotes to avoid transform for some extra node types. refs: sphinx.parsers.RSTParser irFr&Nc s$|sdS|jj|_tdSr8) is_availabler1smartquotes_actionr=rSrr?r,r-rSKs zSphinxSmartQuotes.applycCs|jjdg}|jjdg}|jjjdurdS|jjdur!dS|jjj |vr*dS|jj |vr2dS|j jd}t |D] }|t jvrFdSq.z7^(?P(?P.+)[\(\.](?P
[1-9]\w*)?\)?)$r:)pathpager]) r/rLrmanpagejoinrjrmatch groupdict attributesupdate)r+rFrarpatterninforr,r,r-rSs zManpageLink.applyrTr,r,r,r-rrrr)rr&cCs|t|t|t|t|t|t|t|t|t |t |t |t |t |tddddS)NbuiltinT)r$parallel_read_safeparallel_write_safe) add_transformryrrDrVrbrsrrlr|rrrrr)r)r,r,r-setups$              r)Sr5rrtypingrrrrrrrrr docutils.nodesr r r docutils.transformsr rdocutils.transforms.partsrdocutils.transforms.universalrdocutils.utilsrdocutils.utils.smartquotesrsphinxr sphinx.configrsphinx.deprecationr sphinx.localerr sphinx.utilrsphinx.util.docutilsrsphinx.util.i18nrsphinx.util.nodesrrrsphinx.applicationrsphinx.domain.stdr sphinx.environmentr! getLoggerr2rrIr%r7rDrVrbrlrs literal_blockrcrwr^rxrryr|rrrrrrrrrrrr,r,r,r-sd $                    ;