U n^^+@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_nodesfooterrw/private/var/folders/sd/whlwsn6x1_qgglc0mjv25_695qk2gl/T/pip-install-4zq3fp6i/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_link 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_levelparentr rsectiontitle)rZ unfiltered thresholdmessagesmsgr7rrrrus  zMessages.applyNr#r$r%r&r'rrrrrr0lsr0c@seZdZdZdZddZdS)FilterMessagesz; Remove system messages below verbosity threshold. ifcCs6|jtjD]"}|d|jjjkr|j|qdS)Nr1)r r-rZsystem_messager4r5r6remover*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 r3r6)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-rcommentr6r>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 rrDrrrrGs) r rZstrip_elements_with_classes strip_classesdictstrip_elementsr- check_classesr6r>r*rrrrs"  zStripClassesAndElements.applycCsNt|tjrJ|dddD],}||jkr8|d|||jkrdSqdS)Nr2)r)rElementrHr>rJ)rr+Z class_valuerrrrKs    z%StripClassesAndElements.check_classesN)r#r$r%r&r'rrKrrrrrCsrCc@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 rOrrrrPszSmartQuotes.__init__ccs8ddd}|D]$}|t|j|j}||fVqdS)Nliteralplain)TF)r)r6 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)r6rZ option_string)rErWrrrrGs 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 smartcharsquotesupdaterIr-rZ TextElementr) nodes_to_skipr6rZget_language_codereplacerZnormalize_language_tagrRr4warningaddZeducate_tokensrXsmartquotes_actionzipr[rQ) rr\ alternativeZdocument_languageZlc_smartquotesr+rVlangtagZteacherrWZnewtextrrrrsV           zSmartQuotes.applyN)r#r$r%r&r'rZFixedTextElementSpecialraimagerSmathrawZ problematicrUrerPrXrrrrrrNs   rN)r&Z __docformat__resysrZdocutilsrrZdocutils.transformsrrZdocutils.utilsrrr(r0r=r?r@rCrNrrrrs  >"