o "5p`,@sdZdZddlZddlZddlZddlmZmZddlm Z m Z ddl m Z ej dkr-eZGdd d e ZGd d d e ZGd d d e ZGddde 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) smartquotes)rc@s,eZdZdZdZddZddZddZd S) DecorationszD Populate a document's decoration element (header, footer). i4cCsX|}|r|j}|}|||}|r*|j}|}||dSdSN)generate_headerdocumentget_decoration get_headerextendgenerate_footer get_footer)self header_nodes decorationheader footer_nodesfooterr?/usr/lib/python3/dist-packages/docutils/transforms/universal.pyapply's   zDecorations.applycCsdSr r)rrrrr 3szDecorations.generate_headerc Cs|jj}|js|js|js|jrg}|jr|js|jr:|jr"|j}nt|j |j}| t j dd|dt dg|jrRt|jt}|t d|d|jrt| t dt j ddddt d t j dd d dt d gt jddg|RgSdS) NzView document source)refuriz. zGenerated on: z Generated by Docutilsz http://docutils.sourceforge.net/z from rz(http://docutils.sourceforge.net/rst.htmlz source. )r settings generator datestamp source_link source_url_sourcer relative_path _destinationrr referenceTexttimestrftimegmtimeappend paragraph)rrtextsourcer rrrr6sD zDecorations.generate_footerN)__name__ __module__ __qualname____doc__default_priorityrr rrrrrr s  r c@$eZdZdZdZddZddZdS)ExposeInternalszL Expose internal attributes if ``expose_internals`` setting is set. iHcCst|tj Sr ) isinstancerr'rnoderrrnot_TexteszExposeInternals.not_TextcCsV|jjjr'|j|jD]}|jjjD]}t||d}|dur%||d|<qq dSdS)Nz internal:)r rexpose_internalstraverser9getattr)rr8attvaluerrrrhs   zExposeInternals.applyN)r/r0r1r2r3r9rrrrrr5]s  r5c@eZdZdZdZddZdS)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 |rDtjdgd}|tdd7}||7}g|jjdd<|j|7_dSdS)Nlevelzsystem-messages)classesrzDocutils System Messages) r transform_messagesreporter report_levelparentr+rsectiontitle)r unfiltered thresholdmessagesmsgrGrrrrzs  zMessages.applyNr/r0r1r2r3rrrrrr@q r@c@r?)FilterMessagesz; Remove system messages below verbosity threshold. ifcCs:t|jtjD]}|d|jjjkr|j|q dS)NrA) tupler r;rsystem_messagerDrErFremover7rrrrs  zFilterMessages.applyNrMrrrrrOs rOc@r?) TestMessageszk Append all post-parse system messages to the end of the document. Used for testing purposes. ipcCs&|jjD] }|js|j|7_qdSr )r rCrF)rrLrrrrs zTestMessages.applyNrMrrrrrSs rSc@r?) StripCommentszq Remove comment elements from the document tree (only if the ``strip_comments`` setting is enabled). icCs6|jjjrt|jtjD] }|j|qdSdSr ) r rstrip_commentsrPr;rcommentrFrRr7rrrrs zStripComments.applyNrMrrrrrTrNrTc@r4)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`. ic Cs|jjjrt|jjj|_t|j|jD]}|j |q|jjj s&dS|jjj }|jt j D]}|D]}z |d |Wq6t yJYq6wq2dS)NrB)r rstrip_elements_with_classessetstrip_elementsrPr; check_classesrFrR strip_classesrElement ValueError)rr8r\ class_valuerrrrs$    zStripClassesAndElements.applycCs:t|tjsdS|dddD] }||jvrdSqdS)NFrBT)r6rr]rZ)rr8r_rrrr[s  z%StripClassesAndElements.check_classesN)r/r0r1r2r3rr[rrrrrWs  rWc@sbeZdZdZdZejejfZ ejejej ej ej ej ej fZ dZ ddZddZdd Zd S) SmartQuotesz Replace ASCII quotation marks with typographic form. Also replace multiple dashes with em-dash/en-dash characters. iRqDecCstj|||dt|_dS)N) startnode)r__init__rYunsupported_languages)rr rbrrrrcs zSmartQuotes.__init__ccsZ|D]'}t|j|jst|jj|jrdt|fVqtddt|}d|fVqdS)Nliteralz(?<=)([-\'".`])z\\\1plain)r6rF literal_nodesunicoderesub)rtxtnodesr8txtrrr get_tokenss zSmartQuotes.get_tokensc Cs|jjdd}|s dSz|d}Wn tyd}Ynw|jjj}|jjj}|r4tjj t ||j t jD]}t||jrDq;t|jt jrLq;dd| t jD}||}|rmd|vri|dd}n|d7}t|D] }|tjj vr~|}nqr||jvr|jjjd||d |j|d}tj|||j|d } t|| D]\} } | j| t j| | jd qq;t |_dS) N smart_quotesFaltcSsg|] }t|jtjs|qSr)r6rFr option_string).0txtnoderrr s  z%SmartQuotes.apply..z -x-altquotrz*No smart quotes defined for language "%s".) base_node)attrlanguage) rawsource)!r r setdefault startswithAttributeError language_codesmartquotes_localesr smartcharsquotesupdatedictr;r TextElementr6 nodes_to_skiprFr'get_language_codereplacernormalize_language_tagrdrDwarningaddeducate_tokensrmsmartquotes_actionziprwrY) rrn alternativedocument_languagelc_smartquotesr8rklangtagteacherrrnewtextrrrrs^             zSmartQuotes.applyN)r/r0r1r2r3rFixedTextElementSpecialrimageremathraw problematicrgrrcrmrrrrrr`s   r`)r2 __docformat__risysr(docutilsrrdocutils.transformsrrdocutils.utilsr version_infostrrhr r5r@rOrSrTrWr`rrrrs$   >&