U C^^+@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_nodesfooterrC/tmp/pip-install-6_kvzl1k/docutils/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_linkZ source_urlZ_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_levelparentrrsectiontitle)rZ unfiltered thresholdmessagesmsgr6rrrrus  zMessages.applyNr"r#r$r%r&rrrrrr/lsr/c@seZdZdZdZddZdS)FilterMessagesz; Remove system messages below verbosity threshold. ifcCs6|jtjD]"}|d|jjjkr|j|qdS)Nr0)r r,rZsystem_messager3r4r5remover)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 r2r5)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,rcommentr5r=r)rrrrs zStripComments.applyNr;rrrrr?sr?c@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 rrCrrrrFs) r rZstrip_elements_with_classes strip_classesdictstrip_elementsr, check_classesr5r=r)rrrrs"  zStripClassesAndElements.applycCsNt|tjrJ|dddD],}||jkr8|d|||jkrdSqdS)Nr1)r(rElementrGr=rI)rr*Z class_valuerrrrJs    z%StripClassesAndElements.check_classesN)r"r#r$r%r&rrJrrrrrBsrBc@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 rNrrrrOszSmartQuotes.__init__ccs8ddd}|D]$}|t|j|j}||fVqdS)Nliteralplain)TF)r(r5 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(r5r option_string)rDrVrrrrFs 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 smartcharsquotesupdaterHr,rZ TextElementr( nodes_to_skipr5rZget_language_codereplacerZnormalize_language_tagrQr3warningaddZeducate_tokensrWsmartquotes_actionzipr[rP) rr\ alternativeZdocument_languageZlc_smartquotesr*rUlangtagZteacherrVZnewtextrrrrsV           zSmartQuotes.applyN)r"r#r$r%r&rZFixedTextElementSpecialraimagerRmathrawZ problematicrTrerOrWrrrrrrMs   rM)r%Z __docformat__resysrZdocutilsrrZdocutils.transformsrrZdocutils.utilsrrr'r/r<r>r?rBrMrrrrs  >"