ifHdZdZddlZddlmZmZddlmZmZm Z ddlm Z m Z ddl m Z mZddlmZdd lmZmZddlZdd lmZmZmZmZdd lmZmZdd lmZmZmZdd lmZGdde Z Gdde Z!Gdde Z"Gdde Z#Gdde$Z%GddZ&Gdde Z'Gdde Z(GddeZ)dNd!Z*Gd"d#Z+e,d$d%z fd&Z-e,d'd%z fd(Z.d)Z/Gd*d+e)Z0Gd,d-e0Z1Gd.d/e0Z2Gd0d1e2Z3Gd2d3e2Z4Gd4d5e2Z5Gd6d7e2Z6Gd8d9e2Z7Gd:d;e2e1Z8Gd<d=e6Z9Gd>d?e2Z:Gd@dAe2Z;GdBdCe0Z<GdDdEe)Z=GdFdGe=Z>GdHdIe>Z?GdJdKe>Z@GdLdMe)ZAe0e3e4e5e6e7e:e9e;e=e?e@e@@ ( ?iiG##H$5666H$,$5$(M(*)*49#* ,,, !  X1222 *   $T; 2:82DFFF"}}}N}}} $$ DIIIr!)rTNrrrr5rLr r!r"r7r7s< GK%%%%%%r!r7ceZdZdZddZdS)NestedStateMachinezh StateMachine run from within other StateMachine runs, to parse nested document structures. Tc||_||_|j|_||jj|j|_|j|_||_tj |||}|gks Jd|S)z Parse `input_lines` and populate a `docutils.nodes.document` instance. Extend `StateMachineWS.run()`: set up document-wide data. z1NestedStateMachine.run() results should be empty!) rErHr9rIrJr:r;rKr rL)r2rMrNrHrKrErOs r"rLzNestedStateMachine.runs} )    T]6777      $T; EE"}}} (}}}r!NTrPr r!r"rRrRs2 r!rRceZdZdZeZgZddZdZdZ dZ dZ dd Z didddfd Z d Zd Zd ZdZdZdZdZdS)RSTStatez` reStructuredText State superclass. Contains methods used by all State subclasses. FcPtdd|_tj|||dS)NBody state_classes initial_state)rZnested_sm_kwargsr r4r2 state_machinedebugs r"r4zRSTState.__init__s22?28!:!:}e44444r!ctj||jj}||_|j|_|j|_|j|_|jj|_t|jds|jj |j_ dSdS)Nget_source_and_line) r runtime_initr^rHr:r?r9rKparenthasattrra)r2rHs r"rbzRSTState.runtime_initsT"""!&   |   (- t}&;<< W040B0VDM - - - W Wr!c^ |j|dS#t$rYdSwxYw)zT Jump to input line `abs_line_offset`, ignoring jumps past the end. N)r^ goto_lineEOFError)r2abs_line_offsets r"rfzRSTState.goto_linesF    ( ( 9 9 9 9 9    DD s  ,,c |jd|jjd|d|d|jjd |dgfS)zs Override `StateWS.no_match` to generate a system message. This code should never be run. z6Internal error: no transition pattern match. State: "z"; transitions: z ; context: z; current line: .N)r:severe __class__rr^line)r2context transitionss r"no_matchzRSTState.no_matchs` ~&&& WWW!&&& ( ) ) ) b  r!c ggfS)zCalled at beginning of file.r r2rns r"bofz RSTState.bofs 2v r!NcFd}| |j}|dz }| |j}|dz }t|}d} |dkr+ |j} n#t $rYnwxYw| s|dd|ji|} | |||j|||dkr|j | n| | } |j r@t||z dkr*|j t||z | S)zg Create a new StateMachine rooted at `node` and run it over the input `block`. rNr_rHrKrEr ) nested_smr\lennested_sm_cachepop IndexErrorr_rLrHappendunlinkrhrcr^ next_line) r2blockrNrKrEstate_machine_classstate_machine_kwargs use_default block_lengthr^ new_offsets r" nested_parsezRSTState.nested_parses   &"&.  1 K  '#'#8 1 K5zz  !    $ 4 8 8 : :      H//HHdjH2FHHM%DI#,  @ @ @ !    ' ' 6 6 6 6  " " ""2244 < DSZZ,61<<   ( (Ul)B C C CsA AAc | |j} | |j} || d<| dd|ji| } ||}|| j|_|D]!\} } t| j|| | "| |||j ||| j|j}| | |fS)z Create a new StateMachine rooted at `node` and run it over the input `block`. Also keep track of optional intermediate blank lines and the required final one. Nr[r_rwr ) rxr\copyr_states blank_finishitemssetattrrLrHr~rh)r2rrNrKr[rblank_finish_stateextra_settingsrErrr^keyvalues r"nested_list_parsezRSTState.nested_list_parse$s'  &"&.   '#'#8#=#=#?#? 0=_-++DD$*D.BDD  %!. @L /0=(..00 E EJC M(7e D D D D%DI#,  @ @ @$+,>?L ,,.. <r^ previous_linerg)r2r@rrrHr<mylevellevels r"rzRSTState.check_subsectionGs8 y( $  &&u--1EE   <  D$666##E***tt t66vvFFF uu   G  !&D 5zzQ04-   , ,SZZ!^ < < <N GaK  4 KK42266BB BKK5s07B*$BBcf|jdtjd||}|S)NzTitle level inconsistent:rm)r:rkr literal_block)r2 sourcetextrerrors r"rzRSTState.title_inconsistentps: $$ ')Kr6I666 i..0011W$$T*** !  &  **<FFF#/!3&66881< (( ,VWW5Id)44  |$$$   ( (N$r!cd|}tjd|rKt |dkrgdfS|ddvr|dd}n |dd}d}n|}d }|||\}}t j|d g|R}|j |\|_ |_ |g|z|fS) zW Return a list (paragraph & messages) & a boolean: literal_block next?  z(?G&H*0%22 2r!F)FNN)rrrr5rRrxrzr4rbrfrprsrrrrrrrrrr r!r"rVrVs+ #IO5555 W W W ! ! !DIDH####N.2)+',.2/3 ====<999 '''R %%%4+++*22222r!rVTc6|\}}}}g}|D]P}t|tr$|t|d;||Qd|}dt z} |rt j| S| S)a! Build, compile and return a regular expression based on `definition`. :Parameter: `definition`: a 4-tuple (group name, prefix, suffix, parts), where "parts" is a list of regular expressions and/or regular expression definitions to be joined into an or-group. N|z.%(prefix)s(?P<%(name)s>%(or_group)s)%(suffix)s) isinstancetupler} build_regexprlocalsrcompile) definitionrrprefixsuffixparts part_stringspartor_groupregexps r"rrs#-D&&%L&& dE " " &    T4 8 8 9 9 9 9    % % % %xx %%H = HFz&!!! r!c eZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ezZdZdZdZ d'dZdZdZdZdZd(dZdZdZdZdZdZdZd'dZ d Z!d!Z"d"Z#d#Z$d$Z%d%Z&eeeeeeee e!d& Z'dS))rFz9 Parse inline markup; call the `parse()` method. cg|_dSr/)implicit_dispatch)r2s r"r4zInliner.__init__s!# # #r!cNt|ddrd}d}nDdtjtjd}dtjtjtjd}t }|t|j d|dd d|j gd fd d|d |j zd dddd|j zdd|j zgfgfdd|j z|j dgfgf}||_ ||_||_t!t#|t%j|jdz|zt%j|jdz|zt%jd|zt$jt%jd|zt$jt%j|jdz|zt%j|jdz|zt%j|jdz|zt%j|j|zdzt$jt%jd|jzd z|zt$jt%jd!|zt$jt%jd"|zt$j# |_|j|jj|jf|jr+|j|jj|jf|j r-|j|jj!|j"fdSdS)$Ncharacter_level_inline_markupFz (^|(?%s)(?P__?) footnotelabelz\[z(?P\]_)[0-9]+z\#(%s)?z\*z(?P%s) backquotez(?P(:%s:)?)z`(?!`)z(\*)z(\*\*)a %(non_unescaped_whitespace_escape_before)s ( ` (?P (?P:%(simplename)s:)? (?P__?)? ) ) %(end_string_suffix)s a ( (?:[ \n]+|^) # spaces or beginning of line/string < # open bracket %(non_whitespace_after)s (([^<>]|\x00[<>])+) # anything but unescaped angle brackets %(non_whitespace_escape_before)s > # close bracket ) $ # end of string z(``)z(`)z (\|_{0,2})$a5 %(start_string_prefix)s (?P (?P # absolute URI (?P # scheme (http, ftp, mailto) [a-zA-Z][a-zA-Z0-9.+-]* ) : ( ( # either: (//?)? # hierarchical URI %(uric)s* # URI characters %(uri_end)s # final URI char ) ( # optional query \?%(uric)s* %(uri_end)s )? ( # optional fragment \#%(uric)s* %(uri_end)s )? ) ) | # *OR* (?P # email address z] ) ) %(end_string_suffix)s a %(start_string_prefix)s ( (pep-(?P\d+)(.txt)?) # reference to source file | (PEP\s+(?P\d+)) # reference by name ) %(end_string_suffix)sz{ %(start_string_prefix)s (RFC(-|\s+)?(?P\d+)) %(end_string_suffix)s) initialemphasisstronginterpreted_or_phrase_ref embedded_linkliteraltargetsubstitution_refemailuripeprfc)#getattrropeners delimitersclosing_delimitersclosersrrr1varsrlnon_whitespace_after simplenamestart_string_prefixend_string_suffixrr-rrrnon_whitespace_escape_beforeVERBOSEnon_whitespace_before email_patternpatternsrr}rstandalone_uripep_referencesr pep_referencerfc_referencesr rfc_reference)r2rCrrargsrs r"rGzInliner.init_customizationss 8"1  "   > %6$=$=$5$@$@$@$B  #4"F"F"3">">"3";";";"= xx}} D(()))!#6 b$3 b+/$/A'8T_,(4?:   4? 2  &Z )  8$7 !2 u%%:d? '(*;<==D='(*;<==$&J  * %& %&   * & &*T7&@0122D=$%'89:::d&G(5'6(9':;; 4-4s::''j4,5-405<=< Z?))@j),0024==j),0024 ==aT>T>T> l %%t}'8'+':'< = = =  " @  " ) )4=+<+/+=+? @ @ @  " @  " ) )4=+<+/+=+? @ @ @ @ @ @ @r!c||j|_|j|_|j|_||_|jjj}|j}t|}g}g} g} |r||} | r| } || dp| dp| dp| d} | || |\}}}}| || |z } |r3|| d | |z }||z }g} nn|d | |z}|r|| ||z }|| fS)a@ Return 2 lists: nodes (text and inline elements), and system_messages. Using `self.patterns.initial`, a pattern which matches start-strings (emphasis, strong, interpreted, phrase reference, literal, substitution reference, and inline target) and complete constructs (simple reference, footnote reference), search for a candidate. When one is found, check for validity (e.g., not a quoted '*' character). If valid, search for the corresponding end string if applicable, and check it for validity. If not found or invalid, generate a warning and ignore the start-string. Implicit inline markup (e.g. standalone URIs) is found last. :text: source string :lineno: absolute line number (cf. statemachine.get_source_and_line()) rrrefendfnendr) r:r9r;rcrrrdispatchr groupdictr}implicit_inliner)r2rrrHrcpattern_searchr  remaining processed unprocessedrmatchgroupsmethodbeforeinlines sysmessagess r"rz Inliner.parsefs&       .5=%%    "N9--E **!&/#IVK5H#I%+H%5#I9?J:@&uAG;I;I7K""6***K'%!5!5bggk6J6J6<">">>I(I"$K! "GGK((94  A --i@@ @I(""r!z(?]z[_~*/=+a-zA-Z0-9]z-(?:%(urilast)s|%(uric)s(?=%(uri_end_delim)s))z"[-_!~*'{|}/#?^`&=+$%a-zA-Z0-9\x00]z %(emailc)s+(?:\.%(emailc)s+)* # name (?E>E:Kw ;66r!cr||||jjtj\}}}}}||||fSr/)r.rrrr7s r"rzInliner.strongsA=A__VT]15<>A>A:Kw ;66r!c|jj}|j}|d}|d}|d}|d}d} |r |dd}d} n+||r|d|g||dgfS|||d} | r| dr|| z} | dr|rc|j d|} t||| d } | | | | }|d||g|| d| gfS| d dd}d } | jd| d}t||| d }|ddd kr|rf|j d | z|} t||| d } | | | | }|d||g|| d| gfS| |d||| d||St||| d }| ||||\}}|d|||| d|fS|j d |} t|||d } | | | | }|d||g||d| gfS)NrrolerrurrzVMultiple roles in interpreted text (both prefix and suffix present; only one allowed).rTr_z=Mismatch: both interpreted text role %s and reference suffix.zLInline interpreted text or phrase reference start-string without end-string.)rrrrrr"r rr:rrr# phrase_ref interpreted)r2rrr$rr'r( rolestartr;positionr)r*r,rr-escapedr+nodelistrs r"rz!Inliner.interpreted_or_phrase_refsm= [[-- 99[))KK'' {{6""  @":DHH   u % % @)8)$b&*;R? ?%%fXYY&788  4q)) 4/G~~f%% $N-//H#0%%C$F9W+<$=tDDD**4s;;C!*9*-ufWXX6FMM~~h//"5#o&8x~~a'8'8&89G  7(:!;TBBI~$$N-//.089?E0GGC$F9W+<$=tDDD**4s;;C!*9*-ufWXX6FMMvkzk':F788EE %)%5%5i$6<&>&>"(z z*Hwxx((44m##$*0$22z(23T::tT3//kzk"SE6())+z%Inliner.phrase_ref..9sJ!:!:%)"$!6!6!:!:!:!:!:!:r!refurizproblem with embedded link: %rr__rErO anonymousr)rrrrrr"endswithrrrrrrindirect_reference_namerr adjust_uri referencedr referencer+r9 note_refnamer}note_indirect_targetnote_explicit_targetrc)r2rafterr+rArr unescapedrawtext aliastext rawaliastextunderscore_escaped aliastypealiasr alias_partsrErW node_lists r"r=zInliner.phrase_ref#s +227;; % .?EKKNN?+D ItT**G AI#It44L!-!6!6u!=!= ""3'' &+ & M-33I>> &# &x #2#'?'?@@ekk!nneDDD1J4>%((-!#2#J,Eekk!nnUCCC$%! 4&'G)2(3444 '$TNN &D IFw--G ++OIt)B9)M)MOOO !( ! K RSS>T ! ! +9..', )$ **95555 +Y%//&+ (##)* +&& 6w&&w///&&+0Ii(M66v>>>M..y9999*/Ih'M66vt{KKK  (((('. )$ **9555y%++r!cR|jj|}|rd|zS|S)Nmailto:)rrr)r2rrs r"rUzInliner.adjust_urins1 #))#..  s? "Jr!ctj||j||j\}}|r||||||\}}|||zfS|jd|z|} |||| g|| gzfS)Nz#Unknown interpreted text role "%s".r)rr;r;r:rr#) r2r+rr;rrole_fnrr messages2r,s r"r>zInliner.interpretedus!JtT]F'+}66  &&wtYfdKK E9(Y.. .-%%5<&C%%iC@@Au$& &r!cv||||jjtjd\}}}}}||||fS)NT)r&)r.rrrr7s r"rzInliner.literalsJ=A__VT]2EM"&>M>(>(:Kw ;66r!c||||jjtj\}}}}}|rt |dtjryt |dksJ|d}t |} |d| |j ||j ||||fS)Nrrur) r.rrrrryrrr}r9rZrc) r2rrrrrrr8rrs r"inline_internal_targetzInliner.inline_internal_targets=A__VT]15<>A>A:K  Dz'!*el;; Dw<<1$$$$QZF!&--//22D 7O " "4 ( ( ( M . .vt{ C C Cw ;66r!c||||jjtj\}}}}}t |dkr|d}t |tjr|} |j || |dddkrbtj d| |d} |dddkrd| d <n,t| | d <|j | | |z } | g}||||fS) Nrurrr<rrrMrQrRrE) r.rrrsubstitution_referenceryrrr9note_substitution_refrWrrX) r2rrrrrrr8 subref_node subref_textreference_nodes r"rnzInliner.substitution_references+=A__VT];*>,>,:K w<<1  !!*K+u'CDD /)0022  33KMMMRSS>S((%*__#.; :B&@&@N ~--67{334B;4O4Oy1 22>BBB"k1N-.Gw ;66r!cX|d}t|}|j}|d|d}||dd}|drKt jd|z|}|t j|z }|j |nt j d|z}|ddkr*|d d}d |d <|j |n?|d kr"d }d |d <|j |n|t j|z }|r||d <|j |tj|jjr|}||g|gfS)ze Handles `nodes.footnote_reference` and `nodes.citation_reference` elements. rNr citationlabelz[%s]_rDr#ruauto*rrE)r"rrrrrcitation_referenceTextr9note_citation_reffootnote_referencenote_autofootnote_refnote_symbol_footnote_refnote_footnote_refrget_trim_footnote_ref_spacerCr) r2rrlabelrErrrrefnodes r"r{zInliner.footnote_references  O,, ''-W---.599W--../ ;; ' ' ).w7>@@@G uz%(( (G M + +G 4 4 4 4.w??GqzS  !!""+"# 33G<<<<C"% 665:e,,, 9%, " //88801GHH )y)R//r!c|d}t|}tj||dz|t |}||d_|rd|d<n||d<|j||j}| d}| d} |d||g|| dgfS)NrEr rPrrurRr) r"rrrWrr+r9rXrrr) r2rrrR referencenamerE referencenoderr'r(s r"rWzInliner.references I..  // EKK11 1=*=99;;; &3 a"  6)*M+ & &'.M) $ M & &} 5 5 5[[)) 99W%%kzk"]OVHII5FJJr!c2|||dS)NT)rR)rW)r2rrs r"anonymous_referencezInliner.anonymous_references~~eVt~<<rrlrnr{rWrrrrrrr r r!r"rFrFs### M@M@M@^1#1#1#l'#3 -F*$8J 8DM&GCVVXXMG 6FMBBB&(-HHHH0777 777 2D2D2DhI,I,I,I,V & & &777 7 7 7777*!0!0!0FKKKK"=== ! ! ! I I IGIII""",.,(+)++HHHr!rFaruc&t||z Sr/ords_zeros r"_loweralpha_to_intr& q66E>r!Ac&t||z Sr/rrs r"_upperalpha_to_intr*rr!cNtj|Sr/)r fromRomanupper)rs r"_lowerroman_to_intr.s ?17799 % %%r!c eZdZdZejjZ eZ eddddeddddedd ddd e_ ej e_ gd e_ d d dddd e_ eeeeejd e_ie_ej D](Zejej edzeje<)ejdZ ejdZ ejdZ iZ ded<ded<ded<ded<dej zed<dezed <d!ezed"<d#ezed$<d%ezed&<d'ezed(<ej D]TZd)ed*ejej ejedejej ej dee<Ud+d,ezd-d.ezd/d0eed1d2d3ezdd4 Z!d4Z"d5Z#d6Z$ejd7Z%d8Z&d9Z'd:Z(d;Z)d<Z*d=Z+dxd?Z,d@Z-dAZ.dBZ/dCZ0dDZ1dEZ2dFZ3dGZ4dHZ5dIZ6dJZ7dKZ8dLZ9dMZ:dNZ;dOZdRZ?dSZ@dydTZAdzdUZBdVZCeZD eejdWeEeFzejGejdXeEeFzejGejdYeEeFzejGZeD_!d[ZHd\ZId]ZJd^ZKd_ZLd`ZMdaZNdbZOdcZPddZQdeZRdfZSdgZTdhZUdiZVdjZWdkZXeHejdleFjYzejGfeIejdmeFjYzejGfeJejdnejGfeOejdoejGfeQejdpeFjYzejGfgeD_ZdqZ[drZ\dsZ]dtZ^duZ_dvZ`dwZad>S){rXz: Generic classifier of the first line of a block. ()rur)rrrrrrrj)parensrparenperiod)arabic loweralpha upperalpha lowerroman upperromanrz[a-z]z[A-Z]z [ivxlcdm]+z [IVXLCDM]+rz\+-[-+]+-\+ *$z =+( +=+)+ *$z=+[ =]*$z[!-/:-@[-`{-~]nonalphanum7bitz[a-zA-Z]alphaz [a-zA-Z0-9]alphanumz [a-zA-Z0-9_-] alphanumpluszJ(%(arabic)s|%(loweralpha)s|%(upperalpha)s|%(lowerroman)s|%(upperroman)s|#)enumz%(alphanum)s%(alphanumplus)s*optnamez%(%(alpha)s%(alphanumplus)s*|<[^<>]+>)optargz!(-|\+)%(alphanum)s( ?%(optarg)s)?shortoptz"(--|/)%(optname)s([ =]%(optarg)s)?longoptz(%(shortopt)s|%(longopt)s)optionz(?P<>u[-+*•‣⁃]( +|$)z((%(parens)s|%(rparen)s|%(period)s)( +|$)z1:(?![: ])([^:\\]|\\.|:(?!([ `]|$)))*(?>>( +|$)z\|( +|$)z \.\.( +|$)z__( +|$)z(%(nonalphanum7bit)s)\1* *$) bullet enumerator field_marker option_markerdoctest line_blockgrid_table_topsimple_table_topexplicit_markuprRrmrc|j\}}}}|||}|xj|z c_|s#|xj|dz c_||gfS)z Block quote.z Block quote)r^ get_indented block_quotercr) r2rrn next_stateindentedindentrrelementss r"rz Body.indents|  , , . . 6; ##Hk:: x  @ KK400?? ?KK B&&r!cg}|rtjd|}|j|dz\|_|_|||\}}}}}||||| ||r&| |||z\} } || z }|| z }|}|r!|ds|dd}|dz }|r|d||S)Nrr+rur) rrrr^rar@rmsplit_attributionrr}parse_attribution) r2rrr blockquoteblockquote_linesattribution_linesattribution_offsetnew_line_offset attributionrs r"rzBody.block_quotes@ !*TYYx5H5HIIIJ#77 A FF Z   !% 6 6x M M          . Z H H H OOJ ' ' '  %(,(>(>%{3E'E)G)G% Xk) H$)K !8A; !#ABB<q  !8A; !# !(r!u(---?(?!-)|—) *(?=[^ \n])cd}d}tt|D]}||}|r|r||dz kr|j|}|r|||\}} |rf|||} | |d| | d|d|| |||d||zfcSd}|}|ddddfS)a Check for a block quote attribution and split it off: * First line after a blank line must begin with a dash ("--", "---", em-dash; matches `self.attribution_pattern`). * Every line after that must have consistent indentation. * Attributions must be preceded by block quote content. Return a tuple of: (block quote content lines, attribution lines, attribution offset, remaining indented lines, remaining lines offset). NFru)r)rT)rangeryrattribution_patternrcheck_attribution trim_leftr) r2rrblank nonblank_seenirmrattribution_endra_liness r"rzBody.split_attributionsK s8}}%% 4 4AA;%%''D  CUa!e^^ 4::4@@E C262H2H$a3)3)/*C&.q/@&AG#--eiikkq-AAA#--fA->>>$,RaRL'$%x0@0@'A$//$A$CCCC!% T4t3 3r!cd}|dz}t|dzt|D]}||}|snr|2t|t|z }Tt|t|z |krdS|dz }||pdfS)zt Check attribution shape. Return the index past the end of the attribution, and the indent. Nru)NNr)rryrlstrip)r2rattribution_startrrrms r"rzBody.check_attributions   !(1,c(mm<<  AA;%%''D ~TS%7%77TS///699!zz: FA6;Qr!cd|}d|z}|||\}}tj|dg|R}|j|\|_|_||fS)Nrrur) rrrrrr^rar@rm)r2rrrrrrrKs r"rzBody.parse_attributionsyy""))++["..tV<< 8 r6I666!%!3!G!G!O!O TYX~r!c@tj}|j\|_|_|xj|z c_|jd|d<|| \}}||z }|jj dz}| |jj |d|j dz|d|\}}|||s#|xj|dz c_g|gfS)Bullet list item.rrruN BulletListrNrKr[rz Bullet list)r bullet_listr^rar@rmrcr list_itemrrrrMrhrfr) r2rrnr bulletlistrrrrs r"rz Body.bullets&((  .BBDD    z! $|A 8..55<a #/!3(,(>(> ,VWW5-==??!C\' )?))))% ''' @ KK400?? ?KK:r!!r!c0|jj|dr|j|\}}}n|j|\}}}}t jd|}|r||||||fS)NrrNrK)r^rmget_known_indentedget_first_known_indentedrrrr)r2rrrrlistitems r"rzBody.list_items   "677 + E"55f== 0Hk<<";;FCC 8Hfk<?499X#6#677  -   h[#+  - - -%%r!c r||\}}}}||||stjdt j}|xj|z c_|dkrd|d<n||d<|jj|j |d<|jj|j |d<|dkr6||d<|j d |d |d } |xj| z c_| |\} } || z }|jjdz} ||jj| d |jdz|d | |||dkd\} } || | s#|xj|dz c_g|gfS)zEnumerated List Itemrrurenumtyperrrurz,Enumerated list start value not ordinal-1: "z " (ordinal rNEnumeratedList) lastordinalformatrv)rNrKr[rrzEnumerated list)parse_enumeratoris_enumerated_list_itemrTransitionCorrectionrenumerated_listrcr formatinforrr:inforrr^rrrMrhrfr)r2rrnrrsequencerordinalenumlistr,rrrnewline_offsets r"rzBody.enumerators*.*?*?*F*F'$++GXvFF <3F;; ;(** x s??#+HZ #+HZ !Y1&9@!Y1&9@ a<< 'HW -$$$44"##C KK3 KK!% !(8(8$  ~&&& D KK4001BCC CKK:r!!r!Nc|}d}|jjD] }||rn td|||jj|j|jj|j}|dkrd}n\|rI |jj||r|}n1#t$rtd|zwxYw|dkrd}n|dkrd}|sE|jj D])}|jj||rn*td |dkrd }n4 |jj ||}n#tj $rd }YnwxYw||||fS) aA Analyze an enumerator and return the results. :Return: - the enumerator format ('period', 'parens', or 'rparen'), - the sequence used ('arabic', 'loweralpha', 'upperroman', etc.), - the text of the enumerator, stripped of formatting, and - the ordinal value of the enumerator ('a' -> 1, 'ii' -> 2, etc.; ``None`` is returned for invalid enumerator text). The enumerator format has already been determined by the regular expression match. If `expected_sequence` is given, that sequence is tried first. If not, we check for Roman numeral 1. This way, single-character Roman numerals (which are also alphabetical) can be matched. If no sequence has been matched, all sequences are checked in order. rzenumerator format not matchedruzunknown enumerator sequence: %srrIrzenumerator sequence not matchedruN)rrformatsr)rrrsequenceregexpsrKeyError sequences convertersrInvalidRomanNumeralError)r2rexpected_sequencerr rrr s r"rzBody.parse_enumerator6s$OO%% i' ? ?F   =>> > !5f!=!C#'9#7#?#C"DE 3;;HH  $ .9,->?EEdKK10H . . .!"C$,#-... .S[[#HH S[[#H E I/ E E9,X6<>1    xw..s'B--C /E EEc|dS |j}|jn*#t$r|jYdSwxYw|ddsdS||dz||}|rC|\}} ||s||rdSn#t$rYnwxYwdS)z Check validity based on the ordinal value and the second line. Return true if the ordinal is valid and the second line is blank, indented, or starts with the next enumerator or an auto-enumerator. Nru)r^rrrgstripmake_enumeratorr TypeError)r2r r rrresultnext_enumeratorauto_enumerators r"rzBody.is_enumerated_list_itemms, ?4 /*4466I   , , . . . .       , , . . .11  !}""$$ 1%%gk8VDD  /5 ,O_ ((99 ++O<<1    ts!9#A A #*C CCc|dkrd}n|dkrt|}n|dr+|dkrdSt|tdzdz }nS|dr, t j|}n(#tj$rYdSwxYwtd |z|d r| }n<|d r| }ntd |z|j j |}|j |z|jzd z}|j dz|jzd z}||fS) z Construct and return the next enumerated list item marker, and an auto-enumerator ("#" instead of the regular enumerator). Return ``None`` for invalid (out of range) ordinals. rurrNrrurz!unknown enumerator sequence: "%s"rrrF)strrSchrrrtoRoman RomanErrorr)rrrrrrr)r2r r rrrrrs r"rzBody.make_enumerators s??JJ  ! !WJJ  )) .R<<4 3s88!3a!788 ""7++ . !&w!7!7JJ'   44 ""E$,#-...""7++ .'--// $$W-- .'--// !"E$,#-...Y)&1 %,z9J()()$ ~&&& ? KK400>> >KK:r!!r!c&||}|j\}}|j}|j|\}}}} t j} || _|| _ | ||\} } | t j |dg| Rz } t j d |g| R} | | z } |r|||| | | fS)Nrr)parse_field_markerr^rarrrrr&r@rmr field_name field_bodyrparse_field_body)r2rrsrcsrclinerrrrr field_node name_nodes name_messagesr*s r"r&z Body.fields&&u--)==?? W#3355   8 8 E E 6; []]  ! $($4$4T6$B$B! Me&tR=*==== %dii&9&9JMJJJ j  E  ! !(K D D D<''r!cx|dd}|d|d}|S)z6Extract & return field name from a field marker match.ruN:)r"rfind)r2rr&s r"r(zBody.parse_field_markers9 abb!'u{{3'''( r!c6||||dS)Nr)r)r2rrrKs r"r+zBody.parse_field_bodys# (dCCCCCr!ctj}|j\|_|_ ||\}}n#t$r}|j d|z}|xj |z c_ |j | \} } } }| | | } |xj | z c_ |s#|xj |dz c_ g|gfcYd}~Sd}~wwxYw|xj |z c_ ||z }|jjdz} ||jj| d|jdz|d|\}}|||s#|xj |dz c_ g|gfS)Option list item.zInvalid option list marker: %sz Option listNru OptionListr)r option_listr^rar@rmoption_list_itemrr:rrcrrrrrrrMrhrf)r2rrnr optionlistrrrr,rrrrrr s r"rzBody.option_markers&((   3 3 5 5  JO &%)%:%:5%A%A "Hll & & &-%%&F(-'.//C KK3 KK#<>H KK8 #KK D t44]CCC z2% % % % % % % & z! h #/!3'+'='= ,VWW5-==??!C\' (>()()$ ~&&& @ KK400?? ?KK:r!!sA DB-D DDc|j}||}|j|\}}}}|s)||t jdtj dg|R}tj d |} tj d|| } |r| ||| | |fS)Nrrrr)r^rhparse_option_markerrrrfrrr option_group descriptionrr9r) r2rroptionsrrrrr=r>r9s r"r9zBody.option_list_items#3355**511   8 8 E E 6;  < NN6 " " "3F;; ;)"7w777 ' ((;(;<<  1"l2=??  0   h[#.  0 0 0--r!cg}|d}|D]}|}d}|ddd}t|dkr ||dd<d}nt|ddkrx|ddr|dd r|dd r'|ddd|dddg|dd<d }t|dkrY|dd r>|d dr#d|ddg|dd<dt|cxkrdkrnntj|}|tj |d|dz }t|dkr&|tj |d|d|z }| |tdt|d|d|S)z Return a list of `node.option` and `node.option_argument` objects, parsed from an option marker match. :Exception: `MarkupError` for invalid option markers. z, rFr=ruNrv-z--+rGIIIIFv&&&&!k!&kkkk<<<9:::r!cd|j}|xjt j||z c_g|gfS)Nr)rr^get_text_blockrcr doctest_block)r2rrnrrs r"rz Body.doctest4sNyy+::<<== u*4666 :r!!r!ctj}|xj|z c_|j}|||\}}}||z }|xj|z c_|sm|jjdz} ||jj| d|j dz|dd\} }| | |s-|xj|j d|dzz c_t|r/|dj d|d_||g|gfS)zFirst line of a line block.ruN LineBlockrrz%Line block ends without a blank line.r)rrrcr^rline_block_linerrrMrhrfr:rryrnest_line_block_lines) r2rrnrrrrmrrrrs r"rzBody.line_block<si "" u #3355'+';';E6'J'J$h    x  ,'3a7F,0,B,B$09#1AACCaGK -C-"-" )O\ NN? + + +  KK4=007AX1 KK u:: .Qx&"#a  & &u - - -:r!!r!c|j|d\}}}}d|}|||\}} t j|dg|R} |jdkr*t| ddz | _ | | |fS)z(Return one line element of a line_block.T until_blankrrrru) r^rrrrrrmrrryr"r) r2rrrrrrr text_nodesrrms r"rSzBody.line_block_lineVs  8 8EI9KK 6; yy""#//f== Hz$0Z000 <   C ' 'ekk!nn--1DKX|++r!ctdt|D]4}t||dd||dz j||_5||dS)Nrur)rryrrnest_line_block_segment)r2rrs r"rTzBody.nest_line_block_linesbsj1c%jj)) > >EuU|Xt44<&+EAI&6&=e # $$U+++++r!cd|D}t|}g}tj}|D]}|j|kr||#t |r=||||tj}||t |r*||||||dd<dS)Ncg|] }|j Sr )r)rKitems r" z0Body.nest_line_block_segment..is11144;111r!)minrrrr}ryrZ)r2rindentsleast new_items new_blockr]s r"rZzBody.nest_line_block_segmenths115111G  $&&  ' 'D{U""  &&&&y>>300;;;$$Y/// % 0 2 2I  &&&& y>> (  ( ( 3 3 3   Y ' ' 'aaar!cR|||||jtjS)zTop border of a full table.) table_topisolate_grid_tablerGridTableParserr2rrnrs r"rzBody.grid_table_top{s*~~eWj"5)9;; ;r!cR|||||jtjS)zTop border of a simple table.)reisolate_simple_tablerSimpleTableParserrhs r"rzBody.simple_table_tops*~~eWj"7);== =r!c|||\}}|xj|z c_|sF|jd|jdz}|xj|z c_g|gfS)zTop border of a generic table.z Blank line required after table.rur)tablercr:rr^r) r2rrnrisolate_function parser_classrBrr,s r"rezBody.table_tops"&,>!7X-/ N N N//sxx7I7I7:z0CCEMN N H%%sA'A::C  8CC c*g}d} |jd}nY#tj$rG}|j\}}}||jd||d}Yd}~nd}~wwxYw|| |j t|d }tt|D]b}|| ||<||ddvr3d}|jt||z ||d=nc|j|dsd}tt|d z ddD]Y}|j||r7|jt||z dz||dzd=n.Z|||g||fStt|D]Z}t|||ks||ddvr/|||g||fcS[|||fS) NruT flush_leftUnexpected indentation.r@rmrz+|rrv)r^rOrUnexpectedIndentationErrorr r}r:r disconnectpad_double_widthdouble_width_pad_charryrrrgrid_table_top_patrextendrs) r2rrrrwr,r-widthrs r"rfzBody.isolate_grid_tables  &555FFEE6   "%( E3 OODM//0I7:0JJ K K KLLLLLL    t9:::E!HNN$$%%s5zz""  AQx~~''E!HQx{$&& "00Ua@@@!""I ' &,,U2Y77 2L3u::>1b11 2 2*00q::&44SZZ!^a5GHHHacdd E  4 4U ; ;<<<8\11s5zz"" 2 2A58}}%%q"T)A)A 4 4U ; ;<<<8\1111*Bh ,,s"A8=A33A8c^|jj}|jj}t|dz }t||}|jj}d}d}|dz}||kr||} || } | rt| |kre|j||z ||||dzd} g| ||kp||dz fS|dz }|}|dks#||ks||dzs|} n|dz }||k|r-d} |j||z |||dz}n,d} |j||z dz ||d}||d| z} g| | fS|j| |z ||| dz}| |j |g| |kp|| dz fS)Nrurz5Bottom/header table border does not match top border.rvz$ or no blank line after table bottomrzNo bottom table border found%s.) r^rrMryrsimple_table_border_patrrrsrr)r2rrlimittoplen pattern_matchfoundfound_atrrmrrrextrars r"rjzBody.isolate_simple_tables".".E QU5\''))**4:  AI5jj8D!M$''E tzz||$$..&00U;;;#33eAaCi(+0 1 1Hxe)M51:;K;K;M;M7MMM A::e51:3C3C3E3EC FA5jj" &>",,X-=>>>eHQJ./",,QY];;;eff ++85@BBHxU* * $$S5[111eCEk" t9:::b#,BeCEl.@.@.B.B*BBBr!c>||jdd|}d}|jt |z dz}|r|d|zz }|j|tj ||||z}|gS)NrrzMalformed table.rur) replacerrr^rryr:rrr)r2rdetailrrr3 startliners r"rszBody.malformed_tables d0"555yy$&66883u::EI  % tf} $G ##GU-@t-L-L)26)9$;;wr!c|\}}}tj}|dkr|dxxdgz cc<n|r|dxxdgz cc<tjt|} || z }|D]-} tj| } |rd| jd<|dz}| | z } .|r6tj} | | z } |D]} | || |z } tj}| |z } |D]} ||| |z }|S) Nrvclasseszcolwidths-autozcolwidths-given)cols)colwidthrustub) rrmtgrouprycolspec attributestheadbuild_table_rowtbody)r2rurv stub_columnswidths colwidthsheadrowsbodyrowsrmrrrrrowrs r"rqzBody.build_tablesg(1% 8X  V   )   !1 2 2      4 )   !2 3 3   3y>>222 !  HmX666G "-."6*! g FF  >KMME eOF > >--c9=== % : :C T))#y99 9EE r!ctj}|D]b}||\}}}}i} |r|| d<|r|| d<tjdi| } || z }d|r||||z| c|S)Nmorerowsmorecolsrrr )rrentryrr) r2rowdatarvrcellrrr cellblockrrs r"rzBody.build_table_rowsikk . .D|48 1Hh J 2)1 :& 2)1 :&K--*--E 5LCwwy!! .!!))F:J',"... r!a? ( _ # anonymous target | # *OR* (?!_) # no underscore at the beginning (?P`?) # optional open quote (?![ `]) # first char. not space or # backquote (?P # reference name .+? ) %(non_whitespace_escape_before)s (?P=quote) # close quote if open quote used ) (?%(simplename)s)_ | # *OR* ` # open backquote (?![ ]) # not space (?P.+?) # hyperlink phrase %(non_whitespace_escape_before)s `_ # close backquote, # reference mark ) $ # end of string a ( (?![ ]) # first char. not space (?P.+?) # substitution text %(non_whitespace_escape_before)s \| # close delimiter ) ([ ]+|$) # followed by whitespace )rrW substitutionc|j\}}|j|\}}}}|d}t |} t jd|} || _ || _ | ddkrG| dd} d| d<| r| d | |j | nu| dkr"d} d| d<|j | nM| t jd|z } | d | |j | | r|j | | n|j | | |r|||| | g|fS) Nrurrrurvrrwrr)r^rarrr"rrfootnoterr@rmr}r9note_autofootnotenote_symbol_footnoter note_footnoterZr1r) r2rr,r-rrrrrrrs r"rz Body.footnote]s)==?? W   8 8 E E 66< Ae$$>$))H"5"566 7c>>8D HV  /!((... M + +H 5 5 5 5 S[[D"HV  M . .x 8 8 8 8  B.. .H W  $ $T * * * M ' ' 1 1 1  5 M . .x B B B B M 8 4 4 4  L   hV(  K K Kz<''r!c\|j\}}|j|\}}}}|d}t |} t jd|} || _ || _ | t j d|z } | d | |j | |j | | |r|||| | g|fS)Nrurrrr)r^rarrr"rrcitationrr@rmrr}r9 note_citationrZr) r2rr,r-rrrrrrrs r"rz Body.citation|s)==?? W   8 8 E E 66< Ae$$>$))H"5"566 EKE***  &&& ##H--- **8X>>>  L   hV(  K K Kz<''r!c|jjj}|j}|j|dd\}}}}|jd|d|z}d|D}|d} d} | | } | rn0| dz } | || z } n#t$rtdwxYwH|d| =|dd z| t| z dz d |d<||||| d } | g|fS) NTF)rW strip_indentrc,g|]}t|Sr rrKrms r"r^z)Body.hyperlink_target.. 555tT""555r!rruzmalformed hyperlink target.rFr)explicitrrr^rrrrrrr|rryr make_targetr") r2rrrrrrr blocktextrA blockindex targetmatchrs r"hyperlink_targetzBody.hyperlink_targets-(/#3355   8 8$U9DD  L%))++.51A1AA 55u555(  A!--00K  !OJ A5,, A A A!"?@@@ A A +:+ !HsNKOO$5$5c'll$B1$D$E$EFLLNNa!!%F"-"3"3F";";==x%%s CC1cn||||\}}|dkr_tj|dt|}||_||d|||j||S|dkr/tj|d}||||||S|S)NrErrDrO) parse_targetrrrrT add_targetr9rY)r2r block_textr target_name target_typerrs r"rzBody.make_targets --eZHH T ) # #\*b.:N:NOOOF-1F * OOKVV < < < M . .v 6 6 6M H $ $\*b11F OOKvv > > >MKr!cP|r`|ddddkr:dd|D}||}|rd|fStd|}dd|D}d|fS) z Determine the type of reference of a target. :Return: A 2-tuple, one of: - 'refname' and the indirect reference name - 'refuri' and the URI - 'malformed' and a system_message node rNr<rFc3>K|]}|VdSr/)rrs r"rLz$Body.parse_target..s* @ @$ @ @ @ @ @ @r!rEc3~K|]8}dt|V9dSrH)rrrIrJs r"rLz$Body.parse_target..sT44!% WWXd^^%9%9%;%;<<444444r!rO)rr is_referencer)r2rrrrWrE ref_partss r"rzBody.parse_targets  *U2Y__&&rss+s22 @ @% @ @ @@@I'' 22G * ')),SXXe__== HH44)244444 ""r!c|jjjt |}|sdSt |dp|dS)Nsimplephrase)rrrWrrrr")r2rWrs r"rzBody.is_referencesb &066 %i 0 022 4 H--FX1F1FGGGr!c||_|rtt|}|d||r4|j|}|r||d<nt d|z|j||j dS|r||d<d|d<|j |dS)NrrOzproblem with URI: %rrurR) rmrrr}r?rUr r9rZrcnote_anonymous_target)r2 targetnamerOrrrrs r"rzBody.add_targets  8!(:"6"677D 7O " "4 ( ( ( Ll--f55L'*F8$$*+AF+JKKK M . .vt{ C C C C C *#)x "#F;  M / / 7 7 7 7 7r!c |jjj}|j\}}|j|d\}}}}|jd|d|z} | t|d } d} | | } | rnR| dz } | dzt||  z} n#t$rtdwxYwj|d| =| t!| z dz } |d dz| d |d<|ds|d=|dz }|rJ|d  s0||r|d  0| d }t'j| }||_||_|s9|jd |zt'j| | || }|g|fS|d |d<|d t'j|||||d|\}}d}|ddD]U}t;|t&js4t;|t&js|xj ||z c_ ||=P|dz }V|!t&j"D]}|#|rzt'jd|$ }|j%d|j&z|t'j| | || }|g|fcSt!|dkr9|jd|zt'j| | || }|g|fS|j'(|||j |g|fS)NFrrrTrurFz"malformed substitution definition.rrz.Substitution definition "%s" missing contents.r|rSubstitutionDefrrz6Substitution definition contains illegal element <%s>:z.Substitution definition "%s" empty or invalid.))rrrr^rarrrrr~rrrrr|rryr{r"rsubstitution_definitionr@rmr:rrr}rrrInlineryrcfindallElement*disallowed_inside_substitution_definitionspformatrtagnamer9note_substitution_def)r2rrr,r-rrrrrrAr subdefmatchrsubnamesubstitution_noder,new_abs_offsetrrKrs r"substitution_defzBody.substitution_defs-(5)==?? W   8 8FK9MM  \,599;;,/$))E2B2BB  eAhoo//00  H!--00K  !OJ H!C-+.3J.?.E.E.G.G+I+II H H H!"FGGG H H +:+ !!#g,,.q0!HNN$$s*E"H5aQx a aKF E"IOO--  IIKKK E"IOO-- ##F++!9)DD#& !( '-''@7J#Iy99(**C5,& &8>>##a'"))  +G 4 4 6 6 6'+'='=&/@-L(>(J(J$  %aaa(  DtU\22 !$ 33  033 %a((Q%--em<< + +D>>tDD +-b$,,..2G2G2I2IJJm))Ll#U0IFFW *.. ul**** +  ! !Q & &-''BWL%i;;7(,,C5,& & ++ w  5 5 5!"L00s 4-D""D<c|ds^t|tjr|ds/t|tjr|drdSdS)NidsrRrvTF)rrrWgetr{)r2rKs r"rz/Body.disallowed_inside_substitution_definitions)sk K $00 59XXk5J5J $ 899 >Bhhv>N>N 45r!c |d}tj||jj|j\}}|xj|z c_|r|||||S||S)z?Returns a 2-tuple: list of nodes, and a "blank finish" boolean.ru) r"r directiverHr;r9rc run_directiveunknown_directive)r2roption_presets type_namedirective_classrs r"rzBody.directive1sKKNN $.$8 ty)4=%:%:! x  5%% >CC C)))44 4r!c t|ttfrddlm}||}|j}|jj}|j| d\}} } } d |jj ||jjdz} | || ||\} }}}nk#t$r^}|jd|dd |jd t#j| | | }|g| fcYd }~Sd }~wwxYw||| ||||| ||j } |}nh#t(jjj$rL}|j|j|j| }|t#j| | z }|g}Yd }~nd }~wwxYwt|t6s Jd |zt9t;|D];}t||t"jsJd |d|d||<|| p|jfS)a Parse a directive then run its directive function. Parameters: - `directive`: The class implementing the directive. Must be a subclass of `rst.Directive`. - `match`: A regular expression match object which matched the first line of the directive. - `type_name`: The directive name, as used in the source text. - `option_presets`: A dictionary of preset options, defaults for the directive options. Currently, only an "alt" option is passed by substitution definitions (value: the substitution name), which may be used by an embedded image directive. Returns a 2-tuple: list of nodes, and a "blank finish" boolean. r)convert_directive_function) strip_toprruz Error in "z " directive: rFrjrNz+Directive "%s" must return a list of nodes.z Directive "z"" returned non-Node object (index z): ) rrrdocutils.parsers.rstrr^rrrrrrMparse_directive_blockrr:rr rrrLdocutilsparsersrstDirectiveErrorsystem_messagerr,listrryNodeis_next_line_blank)r2rrrrrrinitial_line_offsetrrrrr argumentsr?contentcontent_offsetrrdirective_instancermsg_noders r"rzBody.run_directive=s* i, !; < < > G G G G G G229==I#3355"0<   8 8CD9FF 6; YYt1= $"4"@1"D D FGG  )**8[+4nFF 8Iw ) ) )M'''3<993688FK3H3H3H3HJ#J ;;&(JJE7L( ( ( ( ( ( (  ) 'Y y'7F Jd.@BB '++--FF#2   }33EK9?4AAH +J CC CHZFFFFFF  &$'' I I>H $ $!)3y>>>>;<< < ^^h1 1 12 =$NN4H1Dq1HII !k(***C NNNN<===r!ctj}||d|dd\}}|t|krdS t j||}n#t $r}dd|jdzfcYd}~Sd}~wttf$r)}ddd |jzfcYd}~Sd}~wtj $r)}dd d |jzfcYd}~Sd}~wwxYw|rd |fSd S) a Parse `datalines` for a field list containing extension options matching `option_spec`. :Parameters: - `option_spec`: a mapping of option name to conversion function, which should raise an exception on bad input. - `datalines`: a list of input strings. :Return: - Success value, 1 or 0. - An option dictionary on success, an error string on failure. rExtensionOptionsT)r[r)rzinvalid option blockzunknown option: "%s"Nzinvalid option value: %srFzinvalid option data: %sru)rzoption data incompletely parsed) rr%rryrextract_extension_optionsrr rrrExtensionOptionError)r2r datalinesrKr rr?rs r"rzBody.parse_extension_optionsse!!'+'='=D0B(>(!(!$  S^^ + +,, H5dKHHGG > > >,v{1~== = = = = = =I& I I I0388FK3H3HHH H H H H H H) H H H/#((6;2G2GGG G G G G G G H  8g: 77sBA C1'A>8C1>C1B60C16C1C,&C1,C1c|j}|jdd\}}}}d|}|jd|zt j|||}|g|fS)NrFrrzUnknown directive type "%s".r)r^rrrr:rrr) r2rrrrrrrrs r"rzBody.unknown_directives#3355   8 8 8 O O 66<yy"" ##$BY$N$)$7d$C$C)/$11w $$r!c|jr|j|d}|st jgdfS|dr"|jj gdfS|j |\}}}}|rJ|ds0| |r|d0d |}t j||g|fS)NTzend of inclusion from "rr)r^rrrrrcommentrr9 include_logr{rrr)r2rfirst_comment_linerrrrrs r"rz Body.comments7   0 0 2 2 !&eiikkll!; %++-- / ($..!,,-FGG  )--///4x   8 8 E E 66< x|1133       x|1133 yy"" dD))*L88r!a \.\.[ ]+ # explicit markup start \[ ( # footnote label: [0-9]+ # manually numbered footnote | # *OR* \# # anonymous auto-numbered footnote | # *OR* \#%s # auto-number ed?) footnote label | # *OR* \* # auto-symbol footnote ) \] ([ ]+|$) # whitespace or end of line z \.\.[ ]+ # explicit markup start \[(%s)\] # citation label ([ ]+|$) # whitespace or end of line z \.\.[ ]+ # explicit markup start _ # target indicator (?![ ]|$) # first char. not space or EOL z \.\.[ ]+ # explicit markup start \| # substitution indicator (?![ ]|$) # first char. not space or EOL aK \.\.[ ]+ # explicit markup start (%s) # directive name [ ]? # optional space :: # directive delimiter ([ ]+|$) # whitespace or end of line c||\}}|xj|z c_||g|gfSz3Footnotes, hyperlink targets, directives, comments.)explicit_constructrc explicit_listr2rrnrrBrs r"rzBody.explicit_markup1 sK!%!8!8!?!?, x  <(((:r!!r!cg}|jjD]\}}||j}|r |||cS#t$rm}|j}d|j}| |j ||Yd}~n d}~wwxYw| |\} } | |z| fS)z>Determine which explicit construct this is, parse & return it.rFrN) r constructsrrrr^rrr r}r:rr) r2rerrorsrrexpmatchrrr3rBrs r"rzBody.explicit_construct8 s#}7  OFG}}U\22H !6$11111"!/??AAF!hhuz22GMM$-"7"7f"7"M"MNNNEEEEE  "&e!4!4,& ,..s ? B6 A"B11B6cN|jjdz}||jj|d|jdz|jd||jj\}}|||s%|xj|dz c_dSdS)z Create a nested state machine for a series of explicit markup constructs (including anonymous hyperlink targets). ruNExplicit)rNrKr[rrEzExplicit markup) r^rrrMrhrcrErfr)r2rrr s r"rzBody.explicit_listH s #/!3'+'='= ,VWW5-==??!C;j'-: (>(<(<$ ~&&& D KK4001BCC CKKKK D Dr!c||\}}|xj|z c_||g|gfSzAnonymous hyperlink targets.)anonymous_targetrcrrs r"rRzBody.anonymousX sK!%!6!6u!=!=, x  <(((:r!!r!cZ|j}|j|d\}}}}|jd|d|z}d|D}||||d}|g|fS)NTrVrc,g|]}t|Sr rrs r"r^z)Body.anonymous_target..e rr!r)r^rrrrrr) r2rrrrrrrrs r"r&zBody.anonymous_target_ s#3355   8 8EI9KK  L%))++.51A1AA 55u555!!%FB??x%%r!cd|jjr |jgdgfS|jdkrt jdt |jdkrW|jd|j }|xj |z c_ t jd|jj }|j dtj|||j }|xj |z c_ g|gfS)z,Section title overline or transition marker.Line::rzeUnexpected possible title overline or transition. Treating it as ordinary text because it's so short.rz'Unexpected section title or transition.)r^rErrrrryr:rrrcrmrkrr)r2rrnrr,rs r"rmz Body.linei s.   * &L>62- - \   ! !T ) )3F;; ; ##%% & & * *-$$F'7799%;;C KK3 KK3F;; ;*/I-&&;%i;;)99;;'==C KK3 KKz2% %r!c|jgdgfS)z%Titles, definition lists, paragraphs.ryrrhs r"rz Body.text s ~vr))r!r/)rr)rN)brrrr5r TableParserrr-rrkeysrr sequencepatsrrrrrrrrr rrrsimple_table_top_patrpatsrescaperrrinitial_transitionsrrrrrrrrrrrrrr&r(r+rr9r<rrrSrTrZrrrermrfrjrsrqrrrrFrrrrrrrrrrrrrrrrrrrrrrrrRr&rmrr r!r"rXrX2s(3I= 688D.F#cCCCF"SrBBBF"SrBBBDDDO?''))DL222DN#+'.'.'3'3 55D "%%7%7%7%*_ 66DO DN11)3)C/*1*1X&&$$5666%2:n55,(bj44? D4.D DM$D*D)+/+<=DL5???6llIBIdof&=&DEEEEGV 4CdJN@4G!#.2*"047  H '''2%"*%FGG!4!4!4F   ("""( & & &!"!"!"F5/5/5/5/n:#0#0#0J""""(((" DDD"""@..."'''R""""""4 , , ,,,, &;;; === " " "&&&$$-$-$-L)C)C)CV    4$vxxHF &#'$w--'0&24'==(BJ #&*T']] 357J @ @"rz#&)-W #6#%* . .E+0+0+0HZ(((>((("&&&2   ###(HHH888$E1E1E1N 5 5 5:I:I:Ix,;,;,;\"""$"888B%%%999"  2:$./13  < < =  2:$. /13  < < =  2::  ' ' (  2::  ' ' (  2: $. / 13  < < =G*>HX"""/// DDD """&&&&&&,*****r!rXceZdZdZejZded<dejDZedddZ dZ d S) RFC2822Bodyz RFC2822 headers are only valid as the first constructs in documents. As soon as anything else appears, the `Body` state should take over. z[!-9;-~]+:( +|$)rfc2822cg|]}|dfS)rXr )rKrs r"r^zRFC2822Body. s2AAA#!&>AAAr!r)r8rXctjdg}|xj|z c_||\}}||z }|jjdz}||jj|d|jdz|d|\}}| ||s#|xj| dz c_g|gfS)RFC2822-style field list item.r8)rruN RFC2822ListrzRFC2822-style field list) rr%rc rfc2822_fieldr^rrrMrhrfr) r2rrnr fieldlistr&rrr s r"r8zRFC2822Body.rfc2822 s$i[999  y "0077|U #/!3'+'='= ,VWW5-==??!CM' (>()()$ ~&&& . KK400,.. .KK:r!!r!c|jd|jd}|j|d\}}}}t j}|t j||z }t jd |}||z }|r| |||||fS)Nr2TrVrr) rfindr^rrrr&r)r*rr) r2rrrrrr fieldnode fieldbodys r"r=zRFC2822Body.rfc2822_field s|3U\..s3334   8 8EI9KK 6; KMM U%dD111 $TYYx%8%899 Y  .   h[#,  . . .,&&r!N) rrrr5rXrrr5insertr8r=r r!r"r7r7 s }!!##H-HYAA'+'?AAAr#6777"""$ ' ' ' ' 'r!r7cNeZdZdZddZeZeZeZeZeZ eZ eZ eZ eZ eZeZeZeZdS)SpecializedBodya Superclass for second and subsequent compound element members. Compound elements are lists and list-like constructs. All transition methods are disabled (redefined as `invalid_input`). Override individual methods in subclasses to re-enable. For example, once an initial bullet list item, say, is recognized, the `BulletList` subclass takes over, with a "bullet_list" node as its container. Upon encountering the initial bullet list item, `Body.bullet` calls its ``self.nested_list_parse`` (`RSTState.nested_list_parse`), which starts up a nested parsing session with `BulletList` as the initial state. Only the ``bullet`` transition method is enabled in `BulletList`; as long as only bullet list items are encountered, they are parsed and inserted into the container. The first construct which is *not* a bullet list item triggers the `invalid_input` method, which ends the nested parse and closes the container. `BulletList` needs to recognize input that is invalid in the context of a bullet list, which means everything *other than* bullet list items, so it inherits the transition list created in `Body`. NcB|jtz8Not a compound element member. Abort this state machine.)r^rrgrhs r" invalid_inputzSpecializedBody.invalid_input s ((***r!NNN)rrrr5rHrrrrrrrrrrrRrmrr r!r"rErE sp, F FJ L!MGJ"N$#OI D DDDr!rEceZdZdZdZdS)rz-Second and subsequent bullet_list list_items.c|jd|jdkr|||\}}|xj|z c_||_g|gfS)rrr)rrcrHrrr)r2rrnrrrs r"rzBulletList.bullet so <?dk(3 3 3    !% !>"""""r!r7cBeZdZdZejZejZdZej Z dS)r<z6Second and subsequent RFC2822-style field_list fields.cj||\}}|xj|z c_||_gdgfS)r;r<)r=rcrrTs r"r8zRFC2822List.rfc28220 s?"0077| u (="$$r!N) rrrr5r7rr5r8rErHrr r!r"r<r<) s>@@#H%9%%%  )EEEr!r<ceZdZdZdZdS)rzz Parse field_list fields for extension options. No nested parsing is done (including inline markup parsing). cg}t|dgzD]]}|r||,|r/d|}|t j||z }g}^dS)z5Override `Body.parse_field_body` for simpler parsing.rrN)rrr}rrr)r2rrrKrrmrs r"r+z!ExtensionOptions.parse_field_bodyB sNNbT)  Dzz||  T"""" yy''d333   r!N)rrrr5r+r r!r"rr: s-     r!rc&eZdZdZejZdZdS)rRz,Second and subsequent lines of a line_block.c|j}|||\}}}|xj|z c_|jxj|z c_||_g|gfS)zNew line of line block.)r^rrSrcr)r2rrnrrrmrrs r"rzLineBlock.line_blockT sm#3355'+';';E6'J'J$h  t  h&(:r!!r!N)rrrr5rErHrrr r!r"rRrRN s166  )E"""""r!rRc,eZdZdZdZdZejZdS)r#z0Second and subsequent explicit markup construct.cj||\}}|xj|z c_||_g|gfSr)rrcrrs r"rzExplicit.explicit_markupb s?!%!8!8!?!?, x (:r!!r!cj||\}}|xj|z c_||_g|gfSr%)r&rcrrs r"rRzExplicit.anonymousi s?!%!6!6u!=!=, x (:r!!r!N) rrrr5rrRrErHrr r!r"r#r#^ s<::""""""  )EEEr!r#c\eZdZdZejdejzddZddgZ dZ dZ d S) rzG Parser for the contents of a substitution_definition element. z (%s)::( +|$)r)embedded_directiverrarc|||jdd\}}|xj|z c_|js||_t )Nrr)alt)rrcr^at_eofrrgrs r"raz"SubstitutionDef.embedded_directive sf!%48K4H4K"0"M"M, x !((** - ,D r!c~|js|j|_tr/)r^rdrrrgrhs r"rzSubstitutionDef.text s6!((** H $ 2 E E G GD r!N) rrrr5rrrFrrr5rarr r!r"rrs s{ !+ ?-4-?,@!A!AH08r!rceZdZdZejdddZddgZdZdZd Z d Z d Z d Z d Z dZejdZdZdS)ryzs Classifier of second line of a text block. Could be a paragraph, a definition list item, or a title. rmr) underliner)rgrX)rrXc|||jdz \}}|xj|z c_|r"|xj|z c_gdgfS)zEnd of paragraph.rurX)rr^rrcr)r2rrnrrrs r"rz Text.blank sw"&t)99;;a?"A"A ; y  0 KK4--// /KK62~r!c8|r|d|dgSr/)rrrs r"eofzText.eof s%  , JJtWd + + + r!ctj}||\}}||z }|xj|z c_|jjdz}||jj|d|jdz|d|d\}}| ||s#|xj| dz c_gdgfS)Definition list item.ruNrMrO)rNrKr[rrzDefinition listrX) rdefinition_listdefinition_list_itemrcr^rrrMrhrfr) r2rrnrdefinitionlistdefinitionlistitemrrr s r"rz Text.indent s.00+/+D+DW+M+M(L,, ~% #/!3'+'='= ,VWW5-==??!C!1A'L (>(J(J$ ~&&& D KK4001BCC CKK62~r!c|j}|d}|j}|dz|z}g}t |t |krt |dkrL|jjr,|jd|} |xj | z c_ tj d|ddz|jj z} |j dtj| | |} || |jjs|ddz|jj z} |j\} } |jdtj| | | | } |xj |z c_ |xj | z c_ g|gfS|d} g|d d <|||| |d z |g|gfS) zSection title.rrr,zfPossible title underline, too short for the title. Treating it as ordinary text because it's so short.rrzTitle underline too short.zUnexpected section title.r|Nru)r^rrrrryrEr:rrcrrrmrrrr}rarkr)r2rrnrrrrgr@rr,rr,r-rs r"rgzText.underline s#3355 !!##L''))  )   Y / /9~~!!%2'-,,N#-%%CKK3&KK"7???#AJ-0B0GG m++0' 9==,!!$$$!. & T)D,>,CCI-AACCLC -&&+#Iy99'**C KK8 #KK KK3 KKz2% %!   UFE6A:x@@@:r!!r!c>|jdz }d} |jd}nD#tj$r2}|j\}}} |jd|| }Yd}~nd}~wwxYw|t|z} | | |\} } |xj | z c_ |xj |z c_ | rM |j n#t$rYnwxYw|xj | z c_ g|gfS)z Paragraph.ruNTryr{r|)r^rrOrr}r r:rrrrcrrgr) r2rrnrrr,rrwr,r-rrrs r"rz Text.text s]&66881<  @&555FFEE6 @ @ @"%( E3-%%&?-0w&@@CCCCCC @$u++%!%y!A!A ; y  s  0 ",,....     KK4--// /KK:r!!s'<A= (A88A=C(( C54C5c|j\}}}}|rJ|ds0||r|d0|s|Sd|}t j||}|j|dz\|_ |_ |g}|s(| | d|S)zReturn a list of nodes.rrruz Literal block) r^rrrquoted_literal_blockrrrrar@rmr}r)r2rrrrrrrBs r"rzText.literal_block s  , , . . 66< x|1133       x|1133  /,,.. .yy""+D$77 #1EEfQhOO    !? D OOD11/BB C C Cr!c |j}|jj}tj}||jj|d||dtfdd}|||j S)NFQuotedLiteralBlockrY)rNrKrEr) r^rhrrrrrMrvrfchildren)r2rhr parent_noders r"rtzText.quoted_literal_block s,<<>>#/moo **   *677 3({4F3H3G"I"I+JJ ~&&&##r!c@|j\}}}}tjd|t |z}|jdz }|j|\|_|_ | ||\}} ||z }tj dg| R} || z }|ddddkr"| |j d|dzz } |||| ||fS) NrrurrrMr+z`Blank line missing before literal block (after the "::")? Interpreted as a definition list item.rr)r^rrrnrrrrar@rmtermrr:rr) r2termlinerrrritemnodertermlistrrs r"rnzText.definition_list_item s;   , , . . 6; - IIhh/ 0 022#33559,@@HH  !YYx88(H%b48444 J A;rss t # # $-,,;ax-!! !J (:NNN%%r!z +: +c t|dksJ||d|\}}tj|d}|j|\|_|_|g}tt|D]}||}t|tj r|j |} t| dkr|dxx|z cc<b| d } tj | } |dxx| z cc<| ddD]8} |tjt!| d| 9|dxx|z cc<||fS)z9Return a definition_list's term and optional classifiers.rurrNT)ryrrrzr^rar@rmrrryclassifier_delimiterrIrr} classifierr) r2rrrXr term_noderdrrKrrtextnoders r"rzz Text.term- s5zzQ#//a&AA HJuQx(( -AA&II   K s:'' & &Aa=D$ ++ &177==u::??bMMMT)MMMM 8??,,D$z$//HbMMMX-MMM %abb JJ!((!,XdD-A-A4HHJJJJJ" % (""r!N)rrrr5rXrr5rrjrrgrrrtrnrrrrzr r!r"ryry s "]62H02BC ")")")"V"""," $ $ $&&&(&2:g..#####r!ryc0eZdZdZdZddZeZeZeZeZ dS)SpecializedTextz Superclass for second and subsequent lines of Text-variants. All transition methods are disabled. Override individual methods in subclasses to re-enable. cgS)zIncomplete construct.r rrs r"rjzSpecializedText.eofP s r!NctrGrgrhs r"rHzSpecializedText.invalid_inputT sr!rI) rrrr5rjrHrrrgrr r!r"rrG sQ E FI DDDr!rceZdZdZdZdZdS)rOz.Second line of potential definition_list_item.c:|jdgS)zNot a definition.rv)r^rrrs r"rjzDefinition.eofb s ((+++ r!cj||\}}|xj|z c_||_gdgfS)rlrM)rnrcr)r2rrnrr|rs r"rzDefinition.indentg s@!%!:!:7!C!C, x (#R''r!N)rrrr5rjrr r!r"rOrO^ s888 (((((r!rOcDeZdZdZdZ dZdZdZeZdZ d dZ d dZ d S) r*zO Second line of over- & underlined section title or transition marker. ruc|d}|jjr d|j_n(t|dkr|||jrX|j\}}tj |d}||_ |dz |_ |xj |z c_ d|_gS)z0Transition marker at end of section or document.rFr,rru) rrHr>rystate_correctioneofcheckr^rar transitionr@rmrc)r2rnmarkerr,r-rs r"rjzLine.eofx s!!## 9 - +16DI . . [[1__  ! !' * * * = &-AACCLC)GAJ???J #J %kJO KK: %KK  r!c4|j\}}|d}t|dkr||t j|}||_|dz |_|xj |z c_ gdgfS)zTransition marker.rr,rrurX) r^rarryrrrr@rmrc)r2rrnrr,r-rrs r"rz Line.blank s)==?? W!!## v;;??  ! !' * * *%777  !A+  z! 62~r!c|jdz }|d}|j}d} |j}n#t$r|dz|z}t |dkr||||dnG|j dtj |||} |xj | z c_ gd gfcYSYnwxYw|d|d|} |}|}|j d d|s|dz|zdz|z}t |dkr||||dn|j d tj | | |} |xj | z c_ gd gfS||kr|dz|zdz|z}t |dkr||||dnE|j d tj | | |} |xj | z c_ gd gfS|}g} t|t |kr|dz|zdz|z}t |dkr||||dnE|jd tj | | |} | | |d|df} d|_||| | |dz| d|_gd gfS)z#Potential over- & underlined title.rurrrr,rvzIncomplete section title.rrXrgz6Missing matching underline for section title overline.z$Title overline & underline mismatch.zTitle overline too short.)r^rrrrgryrshort_overliner:rkrrrcrorrrr}rrr) r2rrnrroverlinerrgrr,r@rrs r"rz Line.text s#335591:   &*4466II & & & 4%/I8??$$%%))##GYBBBBm**/' 9==+!! s" 62~%%%CB &"*555))<??$$$$&&  ,Q/55i@@ & 4%/$6BI8??$$%%))##GYBBBBm**L'77+!! s" 62~%  " " 4%/$6BI8??$$%%))##GYBBBBm**<)&&99!+## s" 62~%    X . . 4%/$6BI8??$$%%))##GYBBBBm++1)&&99!,##$$$!il+  U\\^^VUFQJIII 62~sA BC#"C#cr|d}|dz|jjz}|jdz }t|dkr||||d|jdtj |||}|xj |z c_ gdgfS)Nrrrur,z+Invalid section title or transition marker.rrX) r^rmrryrrr:rrrrc)r2rrnrrrrr,s r"rgzLine.underline s1:tOd&8&== #33559 x  ! !A % %   FA > > >m!!;!)Y77" s 62~r!c|jd|}|xj|z c_|||dS)Nz`Possible incomplete section title. Treating the overline as ordinary text because it's so short.r)r:rrcr)r2rnrrrr,s r"rzLine.short_overline sTm   3! s  gu-----r!cn|j|g|dd<tjdd)NrXr)r^rrStateCorrection)r2rnrs r"rzLine.state_correction s9 ((/// *66:::r!N)ru) rrrr5rrjrrrrgrrr r!r"r*r*o sHJ$   <<<|F   ....;;;;;;r!r*c\eZdZdZdejzddZdZddZdZ dZ d Z d Z d Z d Zd S)rvz Nested parse handler for quoted (unindented) literal blocks. Special-purpose. Not for inclusion in `state_classes`. z(%(nonalphanum7bit)s)r)initial_quotedrFcZt|||g|_d|_dSr/)rVr4rinitial_linenor]s r"r4zQuotedLiteralBlock.__init__ s/$ u555 "r!c|rt||gfSr/rrhs r"rzQuotedLiteralBlock.blank s  +NJ* *r!c|rk|j|j\}}d|}t j||}||_||_|xj|z c_nZ|xj|j d|j z c_|j |xj|j z c_gS)Nrz#Literal block expected; none found.r)r^rarrrrr@rmrcr:rrrr)r2rnr,r-rrs r"rjzQuotedLiteralBlock.eof s  /-AA8<8KMMLC99W%%D!/d;;M#&M !(M  KK= (KKK KK4=005'77991 KK   , , . . . t}$  r!c|s Jd|j|jd|j|jt)Nz7QuotedLiteralBlock.indent: context should not be empty!r{rrr}r:rr^rrrgrhs r"rzQuotedLiteralBlock.indent s & &% & &w  M   9%)%7%G%G%I%I  K K L L L ((***r!c4|d|jd}tjtj|}|d||j|jjf|j |_ |jg|gfS)z7Match arbitrary quote character on the first line only.rrquoted) remove_transitionrrrr4add_transitionrrlrr^rr)r2rrnrquoters r"rz!QuotedLiteralBlock.initial_quoted# s /000 Q*RYu--.. H$dk4>3JK M M M"0@@BB ~z2--r!c@||j||gfS)z,Match consistent quotes on subsequent lines.)r}rrhs r"rzQuotedLiteralBlock.quoted. s#u|$$$ B&&r!c|rd|j|jd|j|jt)Nz#Inconsistent literal block quoting.rrrhs r"rzQuotedLiteralBlock.text3 st  / M  ##$I)-);)K)K)M)M$OO P P P   , , . . .r!Nr)rrrr5rXr3rr5r4rrjrrrrr r!r"rvrv s #;TY"FH4#### +++ $ . . .''' r!rvrT)Cr5 __docformat__rtypesrrrrrrr r docutils.statemachiner r docutils.nodesr rrrrrrrrdocutils.utilsrrrrrrrr%r'r) Exceptionr+r-r7rRrVrrFrrrrrXr7rErrMrr$r7r<rrRr#rryrrOr*rvrZr r!r"rsP ``D#  ********//////////0000000099999999AAAAAA>>>>>>>>JJJJJJJJJJJJ44444444??????????333333#"""")"""22222)22299999999)))))")))%%%%%Y%%%********$%$%$%$%$%n$%$%$%N4i2i2i2i2i2wi2i2i2X.W +W +W +W +W +W +W +W +t"%S!"%S!&&&O*O*O*O*O*8O*O*O*d*+'+'+'+'+'$+'+'+'\)))))d)))X " " " " " " " "00000_000"""""_"""0 " " " " " " " " " " " " " " " "*****/;***"y( " " " " " " " " *********d4w#w#w#w#w#8w#w#w#td.((((((((";;;;;?;;;DHHHHHHHHVz>>9Y(8(DT?KN EDr!