3 E\^+@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|j}|r(|jj}|j}|j||j}|rP|jj}|j}|j|dS)N)generate_headerdocumentZget_decoration get_headerextendgenerate_footerZ get_footer)selfZ header_nodesZ decorationheaderZ footer_nodesfooterrw/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/docutils/docutils/transforms/universal.pyapply"s   zDecorations.applycCsdS)Nr)rrrrr .szDecorations.generate_headerc Cs|jj}|js |js |js |jrg}|jr0|js6|jrt|jrD|j}ntj|j |j}|j t j dd|dt j dg|jrtj|jtj}|jt j d|d|jr|j t j dt j ddddt j d t j dd d dt j 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_url_sourcerZ relative_pathZ _destinationr r referenceTexttimestrftimegmtimeappendZ paragraph)rrtextsourcerrrrr 1s6 zDecorations.generate_footerN)__name__ __module__ __qualname____doc__default_priorityrr r rrrrrs  rc@s$eZdZdZdZddZddZdS)ExposeInternalszL Expose internal attributes if ``expose_internals`` setting is set. iHcCst|tj S)N) isinstancerr)rnoderrrnot_Text`szExposeInternals.not_TextcCsZ|jjjrVxJ|jj|jD]8}x2|jjjD]$}t||d}|dk r*||d|<q*WqWdS)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}x*|D]"}|d|kr|j r|j|qW|rtjdgd}|tjdd7}||7}g|jjdd<|j|7_dS)Nlevelzsystem-messages)classesrzDocutils System Messages) r transform_messagesreporter report_levelparentrrsectiontitle)rZ unfiltered thresholdmessagesmsgr4rrrrus  zMessages.applyN)r!r"r#r$r%rrrrrr-lsr-c@seZdZdZdZddZdS)FilterMessagesz; Remove system messages below verbosity threshold. ifcCs:x4|jjtjD]"}|d|jjjkr|jj|qWdS)Nr.)r r*rZsystem_messager1r2r3remove)rr(rrrrszFilterMessages.applyN)r!r"r#r$r%rrrrrr9sr9c@seZdZdZdZddZdS) TestMessageszk Append all post-parse system messages to the end of the document. Used for testing purposes. ipcCs*x$|jjD]}|js |j|7_q WdS)N)r r0r3)rr8rrrrszTestMessages.applyN)r!r"r#r$r%rrrrrr;sr;c@seZdZdZdZddZdS) StripCommentszq Remove comment elements from the document tree (only if the ``strip_comments`` setting is enabled). icCs2|jjjr.x"|jjtjD]}|jj|qWdS)N)r rstrip_commentsr*rcommentr3r:)rr(rrrrs zStripComments.applyN)r!r"r#r$r%rrrrrr<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`. icCs||jjjp|jjjsdStdd|jjjp,gD|_tdd|jjjpJgD|_x"|jj|jD]}|jj |qdWdS)NcSsg|] }|dfqS)Nr).0keyrrr sz1StripClassesAndElements.apply..cSsg|] }|dfqS)Nr)r@rArrrrBs) r rZstrip_elements_with_classes strip_classesdictstrip_elementsr* check_classesr3r:)rr(rrrrs     zStripClassesAndElements.applycCsPt|tjrLx>|dddD]*}||jkr:|dj|||jkrdSqWdS)Nr/)r'rElementrCr:rE)rr(Z class_valuerrrrFs    z%StripClassesAndElements.check_classesN)r!r"r#r$r%rrFrrrrr?sr?c@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 rJrrrrKszSmartQuotes.__init__ccs<ddd}x,|D]$}|t|j|j}||jfVqWdS)Nliteralplain)TF)r'r3 literal_nodesZastext)rtxtnodesZtexttypetxtnodeZnodetyperrr get_tokenss   zSmartQuotes.get_tokensc Cs|jjj}|sdSy|jd}Wntk r8d}YnX|jjj}|jjj}|rdtjj j t |x|jj t jD]}t||jrqvt|jt jrqvdd|j t jD}|j|}|rd|kr|jdd}n|d7}xVtj|D]}|tjj kr|}PqW||jkr$|jjjd||d|jj|d}tj|j||j|d } x2t|| D]$\} } | jj| t j| | jd qXWqvWt |_dS) NZaltFcSsg|]}t|jtjs|qSr)r'r3rZ option_string)r@rRrrrrBsz%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 smartcharsquotesupdaterDr*rZ TextElementr' nodes_to_skipr3rZget_language_codereplacerZnormalize_language_tagrMr1warningaddZeducate_tokensrSsmartquotes_actionziprVrL) rrW alternativeZdocument_languageZlc_smartquotesr(rQlangtagZteacherrRZnewtextrrrrsJ             zSmartQuotes.applyN)r!r"r#r$r%rZFixedTextElementSpecialr\imagerNmathrawZ problematicrPr`rKrSrrrrrrIs    rI)r$Z __docformat__resysrZdocutilsrrZdocutils.transformsrrZdocutils.utilsrrr&r-r9r;r<r?rIrrrrs >"