U 3_^+@sdZdZddlZddlZddlZddlmZmZddlm Z m Z ddl m Z Gddde Z Gd d d e ZGd d d e ZGd dde ZGddde ZGddde ZGddde ZGddde ZdS)a+ Transforms needed by most or all documents: - `Decorations`: Generate a document's header & footer. - `Messages`: Placement of system messages stored in `nodes.document.transform_messages`. - `TestMessages`: Like `Messages`, used on test runs. - `FinalReferences`: Resolve remaining references. reStructuredTextN)nodesutils)TransformError Transform) smartquotesc@s,eZdZdZdZddZddZddZd S) DecorationszD Populate a document's decoration element (header, footer). i4cCsT|}|r(|j}|}|||}|rP|j}|}||dSN)generate_headerdocumentZget_decoration get_headerextendgenerate_footerZ get_footer)selfZ header_nodesZ decorationheaderZ footer_nodesfooterrx/private/var/folders/2d/2jcwkxfx4hj39rq32sgz27wh9m_5lk/T/pip-target-wqqlibfd/lib/python/docutils/transforms/universal.pyapply"s   zDecorations.applycCsdSr r)rrrrr .szDecorations.generate_headerc Cs|jj}|js |js |js |jrg}|jr0|js6|jrt|jrD|j}nt|j |j}| t j dd|dt dg|jrt|jt}|t d|d|jr| t dt j ddddt d t j dd d dt d gt jd |gSdSdS)NzView document source)Zrefuriz. zGenerated on: z Generated by ZDocutilsz http://docutils.sourceforge.net/z from rz(http://docutils.sourceforge.net/rst.htmlz source. )rr)r settings generator datestampZ source_link source_url_sourcer relative_pathZ _destinationr r referenceTexttimestrftimegmtimeappendZ paragraph)rrtextsourcerrrrr1sD zDecorations.generate_footerN)__name__ __module__ __qualname____doc__default_priorityrr rrrrrrs  rc@s$eZdZdZdZddZddZdS)ExposeInternalszL Expose internal attributes if ``expose_internals`` setting is set. iHcCst|tj Sr ) isinstancerrrnoderrrnot_Text`szExposeInternals.not_TextcCsR|jjjrN|j|jD]4}|jjjD]$}t||d}|dk r&||d|<q&qdS)Nz internal:)r rZexpose_internalstraverser-getattr)rr,Zattvaluerrrrcs   zExposeInternals.applyN)r$r%r&r'r(r-rrrrrr)Xsr)c@seZdZdZdZddZdS)Messageszi Place any system messages generated after parsing into a dedicated section of the document. i\cCs|jj}|jjj}g}|D] }|d|kr|js||q|rtjdgd}|tdd7}||7}g|jjdd<|j|7_dS)Nlevelzsystem-messages)classesrzDocutils System Messages) r transform_messagesreporter report_levelparentr!rsectiontitle)rZ unfiltered thresholdmessagesmsgr8rrrrus  zMessages.applyNr$r%r&r'r(rrrrrr1lsr1c@seZdZdZdZddZdS)FilterMessagesz; Remove system messages below verbosity threshold. ifcCs6|jtjD]"}|d|jjjkr|j|qdS)Nr2)r r.rZsystem_messager5r6r7remover+rrrrszFilterMessages.applyNr=rrrrr>sr>c@seZdZdZdZddZdS) TestMessageszk Append all post-parse system messages to the end of the document. Used for testing purposes. ipcCs&|jjD]}|js|j|7_qdSr )r r4r7)rr<rrrrs zTestMessages.applyNr=rrrrr@sr@c@seZdZdZdZddZdS) StripCommentszq Remove comment elements from the document tree (only if the ``strip_comments`` setting is enabled). icCs.|jjjr*|jtjD]}|j|qdSr )r rstrip_commentsr.rcommentr7r?r+rrrrs zStripComments.applyNr=rrrrrAsrAc@s$eZdZdZdZddZddZdS)StripClassesAndElementsz Remove from the document tree all elements with classes in `self.document.settings.strip_elements_with_classes` and all "classes" attribute values in `self.document.settings.strip_classes`. icCsx|jjjs|jjjsdStdd|jjjp,gD|_tdd|jjjpJgD|_|j|jD]}|j |qbdS)NcSsg|] }|dfqSr r.0keyrrr sz1StripClassesAndElements.apply..cSsg|] }|dfqSr rrErrrrHs) r rZstrip_elements_with_classes strip_classesdictstrip_elementsr. check_classesr7r?r+rrrrs"  zStripClassesAndElements.applycCsNt|tjrJ|dddD],}||jkr8|d|||jkrdSqdS)Nr3)r*rElementrIr?rK)rr,Z class_valuerrrrLs    z%StripClassesAndElements.check_classesN)r$r%r&r'r(rrLrrrrrDsrDc@sTeZdZdZdZejejfZej ej ej ej ej fZdZddZddZdd Zd S) SmartQuotesz Replace ASCII quotation marks with typographic form. Also replace multiple dashes with em-dash/en-dash characters. iRZqDecCstj|||dt|_dS)N) startnode)r__init__setunsupported_languages)rr rPrrrrQszSmartQuotes.__init__ccs8ddd}|D]$}|t|j|j}||fVqdS)Nliteralplain)TF)r*r7 literal_nodesZastext)rtxtnodesZtexttypetxtnodeZnodetyperrr get_tokensszSmartQuotes.get_tokensc Cs|jjj}|sdSz|d}Wntk r8d}YnX|jjj}|jjj}|rdtjj t ||j t jD]}t||jrqrt|jt jrqrdd| t jD}||}|rd|kr|dd}n|d7}t|D]}|tjj kr|}q0q||jkr |jjjd||d|j|d}tj|||j|d } t|| D]$\} } | j| t j| | jd qRqrt |_dS) NZaltFcSsg|]}t|jtjs|qSr)r*r7rZ option_string)rFrXrrrrHs z%SmartQuotes.apply..z -x-altquotrz*No smart quotes defined for language "%s".)Z base_node)attrlanguage) rawsource)!r r smart_quotes startswithAttributeErrorZ language_codeZsmartquotes_localesrZ smartcharsquotesupdaterJr.rZ TextElementr* nodes_to_skipr7rZget_language_codereplacerZnormalize_language_tagrSr5warningaddZeducate_tokensrYsmartquotes_actionzipr\rR) rr] alternativeZdocument_languageZlc_smartquotesr,rWlangtagZteacherrXZnewtextrrrrsV           zSmartQuotes.applyN)r$r%r&r'r(rZFixedTextElementSpecialrbimagerTmathrawZ problematicrVrfrQrYrrrrrrOs   rO)r'Z __docformat__resysrZdocutilsrrZdocutils.transformsrrZdocutils.utilsrrr)r1r>r@rArDrOrrrrs  >"