
    -Ph                    H   d Z dZddlZddlmZmZ ddlmZmZm	Z	 ddlm
Z
mZ ddlmZmZ ddlmZ dd	lmZmZ ddlZdd
lmZmZmZmZ ddlmZmZ ddlmZmZmZ ddlmZ  G d de          Z  G d de          Z! G d de          Z" G d de
          Z# G d de$          Z% G d d          Z& G d de          Z' G d de          Z( G d de          Z)dNd!Z* G d" d#          Z+ e,d$          d%z
  fd&Z- e,d'          d%z
  fd(Z.d) Z/ G d* d+e)          Z0 G d, d-e0          Z1 G d. d/e0          Z2 G d0 d1e2          Z3 G d2 d3e2          Z4 G d4 d5e2          Z5 G d6 d7e2          Z6 G d8 d9e2          Z7 G d: d;e2e1          Z8 G d< d=e6          Z9 G d> d?e2          Z: G d@ dAe2          Z; G dB dCe0          Z< G dD dEe)          Z= G dF dGe=          Z> G dH dIe>          Z? G dJ dKe>          Z@ G dL dMe)          ZAe0e3e4e5e6e7e:e9e;e=e?e@e<e1e8fZBdS )Oa  
This is the ``docutils.parsers.rst.states`` module, the core of
the reStructuredText parser.  It defines the following:

:Classes:
    - `RSTStateMachine`: reStructuredText parser's entry point.
    - `NestedStateMachine`: recursive StateMachine.
    - `RSTState`: reStructuredText State superclass.
    - `Inliner`: For parsing inline markup.
    - `Body`: Generic classifier of the first line of a block.
    - `SpecializedBody`: Superclass for compound element members.
    - `BulletList`: Second and subsequent bullet_list list_items
    - `DefinitionList`: Second+ definition_list_items.
    - `EnumeratedList`: Second+ enumerated_list list_items.
    - `FieldList`: Second+ fields.
    - `OptionList`: Second+ option_list_items.
    - `RFC2822List`: Second+ RFC2822-style fields.
    - `ExtensionOptions`: Parses directive option fields.
    - `Explicit`: Second+ explicit markup constructs.
    - `SubstitutionDef`: For embedded directives in substitution definitions.
    - `Text`: Classifier of second line of a text block.
    - `SpecializedText`: Superclass for continuation lines of Text-variants.
    - `Definition`: Second line of potential definition_list_item.
    - `Line`: Second line of overlined section title or transition marker.
    - `Struct`: An auxiliary collection class.

:Exception classes:
    - `MarkupError`
    - `ParserError`
    - `MarkupMismatch`

:Functions:
    - `escape2null()`: Return a string, escape-backslashes converted to nulls.
    - `unescape()`: Return a string, nulls removed or restored to backslashes.

:Attributes:
    - `state_classes`: set of State classes used with `RSTStateMachine`.

Parser Overview
===============

The reStructuredText parser is implemented as a recursive state machine,
examining its input one line at a time.  To understand how the parser works,
please first become familiar with the `docutils.statemachine` module.  In the
description below, references are made to classes defined in this module;
please see the individual classes for details.

Parsing proceeds as follows:

1. The state machine examines each line of input, checking each of the
   transition patterns of the state `Body`, in order, looking for a match.
   The implicit transitions (blank lines and indentation) are checked before
   any others.  The 'text' transition is a catch-all (matches anything).

2. The method associated with the matched transition pattern is called.

   A. Some transition methods are self-contained, appending elements to the
      document tree (`Body.doctest` parses a doctest block).  The parser's
      current line index is advanced to the end of the element, and parsing
      continues with step 1.

   B. Other transition methods trigger the creation of a nested state machine,
      whose job is to parse a compound construct ('indent' does a block quote,
      'bullet' does a bullet list, 'overline' does a section [first checking
      for a valid section header], etc.).

      - In the case of lists and explicit markup, a one-off state machine is
        created and run to parse contents of the first item.

      - A new state machine is created and its initial state is set to the
        appropriate specialized state (`BulletList` in the case of the
        'bullet' transition; see `SpecializedBody` for more detail).  This
        state machine is run to parse the compound element (or series of
        explicit markup elements), and returns as soon as a non-member element
        is encountered.  For example, the `BulletList` state machine ends as
        soon as it encounters an element which is not a list item of that
        bullet list.  The optional omission of inter-element blank lines is
        enabled by this nested state machine.

      - The current line index is advanced to the end of the elements parsed,
        and parsing continues with step 1.

   C. The result of the 'text' transition depends on the next line of text.
      The current state is changed to `Text`, under which the second line is
      examined.  If the second line is:

      - Indented: The element is a definition list item, and parsing proceeds
        similarly to step 2.B, using the `DefinitionList` state.

      - A line of uniform punctuation characters: The element is a section
        header; again, parsing proceeds as in step 2.B, and `Body` is still
        used.

      - Anything else: The element is a paragraph, which is examined for
        inline markup and appended to the parent element.  Processing
        continues with step 1.
reStructuredText    N)FunctionType
MethodType)nodesstatemachineutils)ApplicationError	DataError)StateMachineWSStateWS)fully_normalize_name)unescapewhitespace_normalize_name)
directives	languagestableparserroles)escape2nullcolumn_width)punctuation_charsroman
urischemes)split_escaped_whitespacec                       e Zd ZdS )MarkupErrorN__name__
__module____qualname__     [/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/docutils/parsers/rst/states.pyr   r   y             r!   r   c                       e Zd ZdS )UnknownInterpretedRoleErrorNr   r    r!   r"   r%   r%   z   r#   r!   r%   c                       e Zd ZdS )"InterpretedRoleNotImplementedErrorNr   r    r!   r"   r'   r'   {   r#   r!   r'   c                       e Zd ZdS )ParserErrorNr   r    r!   r"   r)   r)   |   r#   r!   r)   c                       e Zd ZdS )MarkupMismatchNr   r    r!   r"   r+   r+   }   r#   r!   r+   c                       e Zd ZdZd ZdS )Structz3Stores data attributes for dotted-attribute access.c                 :    | j                             |           d S N)__dict__update)selfkeywordargss     r"   __init__zStruct.__init__   s    [)))))r!   N)r   r   r   __doc__r4   r    r!   r"   r-   r-      s)        ==* * * * *r!   r-   c                       e Zd ZdZ	 	 ddZdS )RSTStateMachinezy
    reStructuredText's master StateMachine.

    The entry point to reStructuredText parsing is the `run()` method.
    r   TNc           	         t          j        |j        j        |j                  | _        || _        |t                      }|                    |j                   t          ||j        | j        g dd|          | _
        || _        |                     |j                   | j
        j        | _        || _        t          j        | |||d                   }|g k    s
J d            dx| _        | _
        dS )z
        Parse `input_lines` and modify the `document` node in place.

        Extend `StateMachineWS.run()`: set up parse-global data and
        run the StateMachine.
        Nr   F)documentreporterlanguagetitle_stylessection_levelsection_bubble_up_kludgeinlinersource)input_sourcez.RSTStateMachine.run() results should be empty!)r   get_languagesettingslanguage_coder:   r;   match_titlesInlinerinit_customizationsr-   memor9   attach_observernote_sourcenoder   run)r2   input_linesr9   input_offsetrE   r?   resultss          r"   rL   zRSTStateMachine.run   s    ".+X->@ @(?iiG##H$5666H$,$5$(M(*)*49#*, , ,	 !X1222	*	 $T;2:82DF F F"}}}N}}} $$	DIIIr!   )r   TNr   r   r   r5   rL   r    r!   r"   r7   r7      s<          GK% % % % % %r!   r7   c                       e Zd ZdZddZdS )NestedStateMachinezh
    StateMachine run from within other StateMachine runs, to parse nested
    document structures.
    Tc                    || _         || _        |j        | _        |                     | j        j                   |j        | _        |j        | _        || _        t          j	        | ||          }|g k    s
J d            |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!)
rE   rH   r9   rI   rJ   r:   r;   rK   r   rL   )r2   rM   rN   rH   rK   rE   rO   s          r"   rL   zNestedStateMachine.run   s}     )	T]6777	 $T;EE"}}}  (}}}r!   NTrP   r    r!   r"   rR   rR      s2         
     r!   rR   c                       e Zd ZdZeZg ZddZd Zd Z	d Z
d Z	 	 dd	Zdi dddfd
Zd Zd Zd Zd Zd Zd Zd ZdS )RSTStatez`
    reStructuredText State superclass.

    Contains methods used by all State subclasses.
    Fc                 P    t           dd| _        t          j        | ||           d S )NBodystate_classesinitial_state)rZ   nested_sm_kwargsr   r4   r2   state_machinedebugs      r"   r4   zRSTState.__init__   s2    2?28!: !:}e44444r!   c                    t          j        |            | j        j        }|| _        |j        | _        |j        | _        |j        | _        | j        j        | _        t          | j        d          s| j        j
        | j        _
        d S d S )Nget_source_and_line)r   runtime_initr^   rH   r:   r?   r9   rK   parenthasattrra   )r2   rH   s     r"   rb   zRSTState.runtime_init   s    T"""!&	|(-t}&;<< 	W040B0VDM---	W 	Wr!   c                 ^    	 | j                             |           dS # t          $ r Y dS w xY w)zT
        Jump to input line `abs_line_offset`, ignoring jumps past the end.
        N)r^   	goto_lineEOFError)r2   abs_line_offsets     r"   rf   zRSTState.goto_line   sF    	((99999 	 	 	DD	s    
,,c                     | j                             d| j        j        d|d|d| j        j        d	           |dg fS )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__r   r^   line)r2   contexttransitionss      r"   no_matchzRSTState.no_match   s`     	 ~&&&WWW!&&&(	) 	) 	)
 b  r!   c                 
    g g fS )zCalled at beginning of file.r    r2   rn   s     r"   bofzRSTState.bof   s    2vr!   Nc                 F   d}|| j         }|dz  }|| j        }|dz  }t          |          }d}	|dk    r+	 | j                                        }	n# t
          $ r Y nw xY w|	s |dd| j        i|}	|	                    ||| j        ||           |dk    r| j        	                    |	           n|	
                                 |	                                }
|j        r@t          |          |z
  dk    r*| j                            t          |          |z
             |
S )zg
        Create a new StateMachine rooted at `node` and run it over the input
        `block`.
        r   N      r_   rH   rK   rE   r    )	nested_smr\   lennested_sm_cachepop
IndexErrorr_   rL   rH   appendunlinkrh   rc   r^   	next_line)r2   blockrN   rK   rE   state_machine_classstate_machine_kwargsuse_defaultblock_lengthr^   
new_offsets              r"   nested_parsezRSTState.nested_parse   s    &"&.1K'#'#8 1K5zz! $ 4 8 8 : :    	H// H Hdj H2FH HM%DI#, 	 	@ 	@ 	@! ''6666  """"2244
< 	DSZZ,61<<((Ul)BCCCs   A 
AAc                    |	| j         }	|
| j                                        }
||
d<    |	dd| j        i|
}||}||j        |         _        |                                D ]!\  }}t          |j        |         ||           "|                    ||| j	        ||           |j        |         j        }|
                                 |                                |fS )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_   rw   r    )rx   r\   copyr_   statesblank_finishitemssetattrrL   rH   r~   rh   )r2   r   rN   rK   r[   r   blank_finish_stateextra_settingsrE   r   r   r^   keyvalues                 r"   nested_list_parsezRSTState.nested_list_parse$  s'    &"&.'#'#8#=#=#?#? 0=_-++ D D$* D.BD D%!.@L/0=(..00 	E 	EJCM(7eDDDD%DI#, 	 	@ 	@ 	@$+,>?L,,..<<r!   c                 f    |                      |||          r|                     |||           dS dS )z=Check for a valid subsection and create one if it checks out.N)check_subsectionnew_subsection)r2   titler@   stylelinenomessagess         r"   sectionzRSTState.sectionB  sD      77 	9vx88888	9 	9r!   c                 <   | j         }|j        }|j        }	 |                    |          dz   }ne# t          $ rX t          |          |j        k    r|                    |           Y dS | xj        |                     ||          z  c_        Y dS w xY w||k    rR||_        t          |          dk    rd|_	        | j
                            t          |          dz              t          ||dz   k    rdS | xj        |                     ||          z  c_        dS )a  
        Check for a valid subsection header.  Return True or False.

        When a new section is reached that isn't a subsection of the current
        section, back up the line count (use ``previous_line(-x)``), then
        ``raise EOFError``.  The current StateMachine will finish, then the
        calling StateMachine can re-examine the title.  This will work its way
        back up the calling chain until the correct section level isreached.

        @@@ Alternative: Evaluate the title, store the title info & level, and
        back up the chain until that level is reached.  Store in memo? Or
        return in results?

        :Exception: `EOFError` when a sibling or supersection encountered.
        ru   TFrv   )rH   r<   r=   index
ValueErrorry   r}   rc   title_inconsistentr>   r^   previous_linerg   )r2   r@   r   r   rH   r<   mylevellevels           r"   r   zRSTState.check_subsectionG  s8     y($	 &&u--1EE 	 	 	<  D$666##E***ttt66vvFFFuu	 G!&D5zzQ04-,,SZZ!^<<<NGaK4KK42266BBBKK5s   0 7B*$BBc                 f    | j                             dt          j        d|          |          }|S )NzTitle level inconsistent: rm   )r:   rk   r   literal_block)r2   
sourcetextr   errors       r"   r   zRSTState.title_inconsistentp  s:    $$')<R)L)L %   r!   c                    | j         }|j        }|xj        dz  c_        t          j                    }| xj        |z  c_        |                     ||          \  }}t          j        |dg|R  }	t          |	                                          }
|d         	                    |
           ||	z  }||z  }||z  }| j
                            ||           | j        j        dz   }| j                                        dz   }|                     | j        j        |d         ||d          }|                     |           |j        |k    rt$          ||_        dS )z?Append new subsection to document tree. On return, check level.ru   r   namesNT)rN   rK   rE   )rH   r=   r   r   rc   inline_textr   normalize_nameastextr}   r9   note_implicit_targetr^   line_offsetrh   r   rM   rf   rg   )r2   r   r   r   rH   r   section_node	textnodestitle_messages	titlenodenameoffset	absoffsetnewabsoffsets                 r"   r   zRSTState.new_subsectionv  sl   y$a}|#$($4$4UF$C$C!	>Kr6I666	i..0011W$$T***	! &**<FFF#/!3&66881<	(( ,VWW5Id ) 4 4 	|$$$((N$r!   c                    d                     |                                          }t          j        d|          rKt	          |          dk    rg dfS |d         dv r|dd                                         }n
|dd         }d}n|}d	}|                     ||          \  }}t          j        |d
g|R  }| j        	                    |          \  |_
        |_        |g|z   |fS )zW
        Return a list (paragraph & messages) & a boolean: literal_block next?
        
z(?<!\\)(\\\\)*::$rv   ru   z 
Nr   r   )joinrstripresearchry   r   r   	paragraphr^   ra   r@   rm   )	r2   linesr   datatextliteralnextr   r   ps	            r"   r   zRSTState.paragraph  s     yy&&((9)400 
	4yyA~~1ubU""CRCy''))CRCyKKDK"..tV<<	8OD"1y111-AA&II!&sX~{**r!   c                 ^    | j                             ||| j        | j                  \  }}||fS )zX
        Return 2 lists: nodes (text and inline elements), and system_messages.
        )r?   parserH   rc   )r2   r   r   r   r   s        r"   r   zRSTState.inline_text  s8     ,,,T6-1YE Exhr!   c                 x    | j                                         dz   }| j                            d|z  |          S )Nru   z2%s ends without a blank line; unexpected unindent.r   )r^   abs_line_numberr:   warning)r2   	node_namer   s      r"   unindent_warningzRSTState.unindent_warning  sK    #33559}$$ &<>G&H*0 % 2 2 	2r!   F)FNN)r   r   r   r5   rR   rx   rz   r4   rb   rf   rp   rs   r   r   r   r   r   r   r   r   r   r    r!   r"   rV   rV      s+         #IO5 5 5 5

W 
W 
W  ! ! !   DIDH# # # #N .2)+',.2/3= = = =<9 9 9
' ' 'R  % % %4+ + +*  2 2 2 2 2r!   rV   Tc                 6   | \  }}}}g }|D ]P}t          |t                    r$|                    t          |d                     ;|                    |           Qd                    |          }dt                      z  }	|rt          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)
isinstancetupler}   build_regexpr   localsr   compile)

definitionr   r   prefixsuffixpartspart_stringspartor_groupregexps
             r"   r   r     s     #-D&&%L & &dE"" 	&T4 8 89999%%%%xx%%H=HF z&!!!r!   c            
           e Zd ZdZd Zd Zd ZdZdZdZ	dZ
d	Zd
ZdZdZd e            z  ZdZdZd Z	 d'dZd Zd Zd Zd Zd(dZd Zd Zd Zd Zd Zd Zd'dZ d  Z!d! Z"d" Z#d#Z$d$ Z%d% Z&eeeeeeee e!d&	Z'dS ))rF   z9
    Parse inline markup; call the `parse()` method.
    c                     g | _         d S r/   )implicit_dispatch)r2   s    r"   r4   zInliner.__init__  s    !#	# 	#r!   c                 N   t          |dd          rd}d}nDdt          j        t          j        d}dt          j        t          j        t          j        d}t                                                      }|                    t          | j
                             d|dd	d| j        g d
fdd|d| j        z  ddddd| j        z  dd| j        z  gfgfdd| j        z  | j        dgfgf}|| _        || _        || _        t!          t#          |          t%          j        | j        dz   |z             t%          j        | j        dz   |z             t%          j        d|z  t$          j                  t%          j        d|z  t$          j                  t%          j        | j        dz   |z             t%          j        | j        dz   |z             t%          j        | j        dz   |z             t%          j        | j        |z  dz   t$          j                  t%          j        d| j        z   d z   |z  t$          j                  t%          j        d!|z  t$          j                  t%          j        d"|z  t$          j                  #          | _        | j                            | j        j        | j        f           |j        r+| j                            | j        j        | j        f           |j         r-| j                            | j        j!        | j"        f           d S d S )$Ncharacter_level_inline_markupFz
(^|(?<! ))r   z(^|(?<=\s|[z]))z($|(?=\s|[ initial_inlinestart)z\*\*z\*(?!\*)``_`z\|(?!\|)wholez(?P<refname>%s)(?P<refend>__?)footnotelabelz\[z(?P<fnend>\]_)[0-9]+z\#(%s)?z\*z(?P<citationlabel>%s)	backquotez(?P<role>(:%s:)?)z`(?!`)z(\*)z(\*\*)a  
              %(non_unescaped_whitespace_escape_before)s
              (
                `
                (?P<suffix>
                  (?P<role>:%(simplename)s:)?
                  (?P<refend>__?)?
                )
              )
              %(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<whole>
                  (?P<absolute>           # absolute URI
                    (?P<scheme>             # 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>              # email address
                    z]
                  )
                )
                %(end_string_suffix)s
                a  
                %(start_string_prefix)s
                (
                  (pep-(?P<pepnum1>\d+)(.txt)?) # reference to source file
                |
                  (PEP\s+(?P<pepnum2>\d+))      # reference by name
                )
                %(end_string_suffix)sz{
                %(start_string_prefix)s
                (RFC(-|\s+)?(?P<rfcnum>\d+))
                %(end_string_suffix)s)initialemphasisstronginterpreted_or_phrase_refembedded_linkliteraltargetsubstitution_refemailuripeprfc)#getattrr   openers
delimitersclosing_delimitersclosersr   r   r1   varsrl   non_whitespace_after
simplenamestart_string_prefixend_string_suffixr   r-   r   r   r   non_whitespace_escape_beforeVERBOSEnon_whitespace_beforeemail_patternpatternsr   r}   r   standalone_uripep_referencesr   pep_referencerfc_referencesr   rfc_reference)r2   rC   r   r   argsr   s         r"   rG   zInliner.init_customizations  s   8<eDD 
	>"1 "
	>
 %6$=$=$5$@$@$@$B #4"F"F"3">">"3";";";"= xx}}D(()))!#6b$3   b+/$/A'8T_,(4?:	  4?2&Z)
8 $7 !2
u%%:d? '(*;< = =D='(*;< = =$&J
 
 *%& %& 

 
 *& & *T7&@01 2 2D=$%'89 : ::d&G(5'6(9': ; ; 
4-4s::' 'j4 ,5-405< =<  Z?) )@ j) ,00 24= = j) ,00 24	= =aT> T> T>l 	%%t}'8'+':'< 	= 	= 	=" 	@"))4=+<+/+=+? @ @ @" 	@"))4=+<+/+=+? @ @ @ @ @	@ 	@r!   c                 |   |j         | _         |j        | _        |j        | _        || _        | j        j        j        }| j        }t          |          }g }g }	g }
|r ||          }|r|	                                }||d         p|d         p|d         p|d                  } || ||          \  }}}}|	
                    |           |
|z  }
|r3||                     d                    |	          |          z  }||z  }g }	nn|d                    |	          |z   }|r||                     ||          z  }||
fS )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())
        r   r   refendfnendr   )r:   r9   r;   rc   r  r   r   dispatchr   	groupdictr}   implicit_inliner   )r2   r   r   rH   rc   pattern_searchr  	remaining	processedunprocessedr   matchgroupsmethodbeforeinlinessysmessagess                    r"   r   zInliner.parsef  s   & .5=%%		 	"N9--E **!&/ #IVK5H #I%+H%5#I9?J:@&uAG;I ;I7K""6***K' %!5!5bggk6J6J6<"> "> >I(I"$K!  	" GGK((94	 	A--i@@@I(""r!   z(?<!\s)z(?<![\s\x00])z(?<!(?<!\x00)[\s\x00])z(?!\s)z$(?:(?!_)\w)+(?:[-._+:](?:(?!_)\w)+)*z%[-_.!~*'()[\];/:@&=+$,%a-zA-Z0-9\x00]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
          (?<!\x00)@                      # at
          %(emailc)s+(?:\.%(emailc)s*)*   # host
          %(uri_end)s                     # final URI char
          c                     |j         }|                                }|dk    rdS ||dz
           }	 ||                                         }n# t          $ r Y dS w xY wt	          j        ||          S )zTest if inline markup start-string is 'quoted'.

        'Quoted' in this context means the start-string is enclosed in a pair
        of matching opening/closing delimiters (not necessarily quotes)
        or at the end of the match.
        r   Fru   T)stringr   endr|   r   match_chars)r2   r  r  r   prestart	poststarts         r"   quoted_startzInliner.quoted_start  s     A::5%!)$	uyy{{+II 	 	 	44	 ,XyAAAs   A 
AAFc                 2   |j         }|                    d          }|                    d          }|                     |          r|d |         g ||d          g dfS |                    ||d                    }	|	r|	                    d          r|	j         d |	                    d                   }
|rt          |
d          }
||	                    d          z   }t          |||         d          } |||
          }|d |         |g||d          g |	                    d          fS | j                            d|j	        z  |          }t          |||         d          }
| 
                    |
|
|          }|d |         |g||d          |gdfS )Nr   r   ru   Tz*Inline %s start-string without end-string.r   )r  r   r  r   r   r   groupr:   r   r   problematic)r2   r  r   end_pattern	nodeclassrestore_backslashesr  
matchstartmatchendendmatchr   textend	rawsourcerK   msgprbs                   r"   
inline_objzInliner.inline_obj  s   [[))
99W%%U## 	D)8)$b&*;RCC%%fXYY&788 	=q)) 	=?#5HNN1$5$5#56D" ,d++a0G 
7(:!;TBBI9Y--D;J;'$788$b(..*;*;= =m##:"#)/ $ 1 1 z(23T::tT3//kzk"SE6())+<seRGGr!   c                     | j                             || j                  }t          j        |||          }| j                             |          }|                    |           |S )N)refid)r9   set_idrc   r   r#  add_backref)r2   r   r+  messagemsgidr#  prbids          r"   r#  zInliner.problematic  sa    $$Wdk::'	4uEEE$$[11E"""r!   c                 r    |                      ||| j        j        t          j                  \  }}}}}||||fS r/   )r.  r  r   r   r2   r  r   r  r  r  r  	endstrings           r"   r   zInliner.emphasis  sA    =A__VT]3U^>E >E:Kw	;66r!   c                 r    |                      ||| j        j        t          j                  \  }}}}}||||fS r/   )r.  r  r   r   r7  s           r"   r   zInliner.strong  sA    =A__VT]15<>A >A:Kw	;66r!   c                    | j         j        }|j        }|                    d          }|                    d          }|                    d          }|                    d          }d}	|r|dd         }d}	n+|                     |          r|d |         g ||d          g fS |                    ||d                    }
|
r|
                    d          r||
                                z   }|
                    d          r|rc| j        	                    d|          }t          |||         d	          }|                     |||          }|d |         |g||d          |gfS |
                    d
          dd         }d
}	|
j        d |
                    d                   }t          |||         d	          }|dd          dk    r|rf| j        	                    d|	z  |          }t          |||         d	          }|                     |||          }|d |         |g||d          |gfS |                     |d |         ||d          ||          S t          |||         d	          }|                     ||||          \  }}|d |         |||d          |fS | j        	                    d|          }t          |||         d	          }|                     |||          }|d |         |g||d          |gfS )Nr   roler   ru   r   r   zVMultiple roles in interpreted text (both prefix and suffix present; only one allowed).r   Tr   _z=Mismatch: both interpreted text role %s and reference suffix.zLInline interpreted text or phrase reference start-string without end-string.)r  r   r  r   r  r"  r   r   r:   r   r   r#  
phrase_refinterpreted)r2   r  r   r$  r  r'  r(  	rolestartr;  positionr)  r*  r,  r   r-  escapedr+  nodelistr   s                      r"   r   z!Inliner.interpreted_or_phrase_ref  s   m=[[--
99[))KK''	{{6"" 	@":DHHu%% 	@)8)$b&*;R??%%fXYY&788 	4q)) 	4/G~~f%% 
$ N-//H# 0 % %C $F9W+<$=tDDD**4s;;C!*9*-ufWXX6FMM~~h//"5#o&8x~~a'8'8&89G 
7(:!;TBBI~$$ N-//.089?E 0 G GC $F9W+<$=tDDD**4s;;C!*9*-ufWXX6FMMvkzk':F788<L'0'; ; ; %VIg,=%>EE	%)%5%5i$6<&> &>"(z	z*Hwxx((4 4m##$*0 $ 2 2 z(23T::tT3//kzk"SE6())+<seCCr!   Nc                 ,   | j         j                            |          }|r|d |                    d                   }t	          |          }t	          |d          }|                    d          }	t	          |	d          }
|
                    d          }|	                    d          r|s| j         j                            |	          syd}t          t	          |	d d                             }t          j        |                    d          |	          }t          t	          |	d d                             |_        nd
}t          |                    d                    }d                    d |D                       }|                     t	          |                    }|                    d          r|d d         dz   }t          j        |                    d          |          }d|_        |	st%          d|	z            |s|}t	          |          }|
}n#|}t	          |          }d }t	          |d          }t          |          }t          j        ||t          |                    }||d         _        |g}|dd          dk    r<|r&|dk    r ||d<   | j                            |           n|r|d
k    r||d<   nd|d<   n|r|d                             |           |dk    r:||d<   | j                            |           | j                            |           n%||d<   | j                            || j                   |                    |           n||d<   | j                            |           |||g fS )Nr   Trv   z\_r<  r   r   ru   refnamer    c              3   d   K   | ]+}d                      |                                          V  ,dS r   N)r   split.0r   s     r"   	<genexpr>z%Inliner.phrase_ref.<locals>.<genexpr>9  sJ       !: !:%) "$!6!6 !: !: !: !: !: !:r!   refurizproblem with embedded link: %rr   __rE  rO  	anonymousr   )r  r   r   r   r   r"  endswithr   r  r   r   r   r   indirect_reference_namer   r   
adjust_uri
referencedr	   	referencer+  r9   note_refnamer}   note_indirect_targetnote_explicit_targetrc   )r2   r  afterr+  rA  r   r  	unescapedrawtext	aliastextrawaliastextunderscore_escaped	aliastypealiasr   alias_partsrE  rW  	node_lists                      r"   r=  zInliner.phrase_ref#  s   +227;; %	.?EKKNN?+D ItT**GAI#It44L!-!6!6u!=!=""3'' &+& M-33I>>& #	&x	#2#'?'?@@ekk!nneDDD1J4<Yss^4L4L2N 2N.. "	6u{{1~~FF !: !:-8!: !: !: : :88>>%(( -!#2#J,Eekk!nnUCCC$%! 4&'G)2(3 4 4 4 '$TNN	&D IFw--G ++OIt)B9)M)MO O O	!(	!K	RSS>T!! +9..',	)$**95555 +Y%//&+	(##)*	+&& 6w&&w///&&+0Ii(M66v>>>M..y9999*/Ih'M66vt{KKK  (((('.	)$**9555y%++r!   c                 R    | j         j                            |          }|rd|z   S |S )Nmailto:)r  r   r  )r2   r   r  s      r"   rU  zInliner.adjust_urin  s1    #))#.. 	s?"Jr!   c                     t          j        || j        || j                  \  }}|r ||||||           \  }}|||z   fS | j                            d|z  |          }	|                     |||	          g||	gz   fS )Nz#Unknown interpreted text role "%s".r   )r   r;  r;   r:   r   r#  )
r2   r+  r   r;  r   role_fnr   r   	messages2r,  s
             r"   r>  zInliner.interpretedu  s    !JtT]F'+}6 6 	&&wtYfdKKE9(Y...-%%5< &  C %%iC@@Au$& &r!   c                 v    |                      ||| j        j        t          j        d          \  }}}}}||||fS )NT)r&  )r.  r  r   r   r7  s           r"   r   zInliner.literal  sJ    =A__VT]2EM"& >M >( >(:K w	;66r!   c                    |                      ||| j        j        t          j                  \  }}}}}|rt	          |d         t          j                  ryt          |          dk    sJ |d         }t          |                                          }	|d                             |	           | j	        
                    || j                   ||||fS )Nr   ru   r   )r.  r  r   r   r   ry   r   r   r}   r9   rZ  rc   )
r2   r  r   r  r  r  r  r8  r   r   s
             r"   inline_internal_targetzInliner.inline_internal_target  s    =A__VT]15<>A >A:K 	Dz'!*el;; 	Dw<<1$$$$QZF!&--//22D7O""4(((M..vt{CCCw	;66r!   c                    |                      ||| j        j        t          j                  \  }}}}}t          |          dk    r|d         }t          |t          j                  r|                                }	| j        	                    ||	           |dd          dk    rbt          j
        d|	|d          }
|dd          dk    rd|
d	<   n,t          |	          |
d
<   | j                            |
           |
|z  }
|
g}||||fS )Nru   r   r   r<  r   r   rM  rQ  rR  rE  )r.  r  r   r   substitution_referencery   r   r   r9   note_substitution_refrW  r   rX  )r2   r  r   r  r  r  r  r8  subref_nodesubref_textreference_nodes              r"   rn  zInliner.substitution_reference  s+   =A__VT];*>, >,:K w<<1!!*K+u'CDD /)002233KMMMRSS>S((%*__#.;		:B&@ &@N ~--67{334B;4O4Oy122>BBB"k1N-.Gw	;66r!   c                 X   |                     d          }t          |          }|j        }|d|                    d                   }||                    d          d         }|                     d          rKt          j        d|z  |          }|t          j        |          z  }| j        	                    |           nt          j
        d|z            }|d         dk    r*|d	d         }d	|d
<   | j                            |           n?|dk    r"d}d|d
<   | j                            |           n|t          j        |          z  }|r||d<   | j                            |           t          j        | j        j                  r|                                }||g|g fS )ze
        Handles `nodes.footnote_reference` and `nodes.citation_reference`
        elements.
        r   Nr   citationlabelz[%s]_rD  r   #ru   auto*r   rE  )r"  r   r  r   r  r   citation_referenceTextr9   note_citation_reffootnote_referencenote_autofootnote_refnote_symbol_footnote_refnote_footnote_refr   get_trim_footnote_ref_spacerC   r   )	r2   r  r   labelrE  r  r  r  refnodes	            r"   r{  zInliner.footnote_reference  s   
 O,, ''-W---.599W--../	;;'' 	).w7>@ @ @Guz%(((GM++G4444.w??GqzS  !!""+"#33G<<<<C"%66    5:e,,, 9%,	"//88801GHH )y)R//r!   c                    |                     d          }t          |          }t          j        ||                     d          z   |t	          |                    }||d         _        |rd|d<   n||d<   | j                            |           |j        }|	                    d          }|
                    d          }	|d |         |g||	d          g fS )NrE  r  rP  r   ru   rR  r   )r"  r   r   rW  r   r+  r9   rX  r  r   r  )
r2   r  r   rR  referencenamerE  referencenoder  r'  r(  s
             r"   rW  zInliner.reference  s    I.. //EKK111=*=99; ; ; &3a" 	6)*M+&&'.M)$M&&}555[[))
99W%%kzk"]OVHII5FJJr!   c                 2    |                      ||d          S )NT)rR  )rW  )r2   r  r   s      r"   anonymous_referencezInliner.anonymous_reference  s    ~~eVt~<<<r!   c                 r   |                     d          r3|                     d                                          t          j        v ri|                     d          rd}nd}|                     d          }|t	          |          z   }t          j        t	          |d          ||          }|gS t          )Nschemer   rf  r   r   TrN  )r"  lowerr   schemesr   r   rW  r+   )r2   r  r   	addschemer   rO  rW  s          r"   r  zInliner.standalone_uri  s    H%% 	!;;x((..00J4FFF{{7## %			;;w''D$/Ft(<(<d/57 7 7I;  r!   c                    |                     d          }|                    d          r0t          t          |                     d                              }nL|                    d          r0t          t          |                     d                              }nt          | j        j        j        | j        j        j        |z  z   }t          j
        t          |d          ||          gS )Nr   zpep-pepnum1PEPpepnum2TrN  )r"  
startswithintr   r+   r9   rC   pep_base_urlpep_file_url_templater   rW  )r2   r  r   r   pepnumrefs         r"   r  zInliner.pep_reference  s    {{1~~??6"" 	!%++i"8"899::FF__U## 	!%++i"8"899::FF  }%2'=FGt 4 4d3GGGHHr!   z
rfc%d.htmlc                 H   |                     d          }|                    d          rLt          t          |                     d                              }| j        j        j        | j        |z  z   }nt          t          j
        t          |d          ||          gS )Nr   RFCrfcnumTrN  )r"  r  r  r   r9   rC   rfc_base_urlrfc_urlr+   r   rW  )r2   r  r   r   r  r  s         r"   r  zInliner.rfc_reference  s    {{1~~??5!! 	!%++h"7"78899F-(5v8MMCC  t 4 4d3GGGHHr!   c                 ~   |sg S | j         D ]\  }}|                    |          }|r	 |                     |d|                                         |           |||          z   |                     ||                                d         |          z   c S # t
          $ r Y w xY wt          j        |          gS )a  
        Check each of the patterns in `self.implicit_dispatch` for a match,
        and dispatch to the stored method for the pattern.  Recursively check
        the text before and after the match.  Return a list of `nodes.Text`
        and inline element nodes.
        N)r   r   r  r   r  r+   r   ry  )r2   r   r   patternr  r  s         r"   r  zInliner.implicit_inline  s      	I#5 
	 
	OGVNN4((E  !00nu{{}}n1EvNN$fUF334"224		3EvNNO P P P &   D 
4  !!s   A-B
B&%B&)	rw  z**`r   r   z]_r   r<  rQ  r   r/   )(r   r   r   r5   r4   rG   r   r  r   &non_unescaped_whitespace_escape_beforer   r   uricuri_end_delimurilastr   uri_endemailcr  r   r.  r#  r   r   r   r=  rU  r>  r   rl  rn  r{  rW  r  r  r  r  r  r  r  r    r!   r"   rF   rF     s        # # #
M@ M@ M@^1# 1# 1#l '#3 -F*$8J 8DM&G CVVXXMG6FMB B B& (-H H H H0  7 7 7
7 7 7
2D 2D 2DhI, I, I, I,V  & & &7 7 7	7 	7 	77 7 7*!0 !0 !0FK K K K"= = =! ! !
I 
I 
I GI I I" " ", .,(+)+ +HHHr!   rF   aru   c                 &    t          |           |z
  S r/   ords_zeros     r"   _loweralpha_to_intr  &      q66E>r!   Ac                 &    t          |           |z
  S r/   r  r  s     r"   _upperalpha_to_intr  *  r  r!   c                 N    t          j        |                                           S r/   )r   	fromRomanupper)r  s    r"   _lowerroman_to_intr  .  s    ?17799%%%r!   c                       e Zd ZdZej        j        Z	  e            Z	  edddd           edddd           edd	dd          d
e_	        ej	        
                                e_        g de_        dddddde_        eeeeej        de_        i e_        ej        D ](Z ej        ej        e         dz             ej        e<   ) ej        d          Z	  ej        d          Z	  ej        d          Z	 i Z	 ded<   ded<   ded<   ded<   dej        z  ed<   dez  ed <   d!ez  ed"<   d#ez  ed$<   d%ez  ed&<   d'ez  ed(<   ej        D ]TZd)ed* ej        ej	        e         j                  ed          ej        ej	        e         j                   dee<   Ud+d,ez  d-d.ez  d/d0eed1d2d3ez  dd4Z!d4Z"d5 Z#d6 Z$ ej        d7          Z%d8 Z&d9 Z'd: Z(d; Z)d< Z*d= Z+dxd?Z,d@ Z-dA Z.dB Z/dC Z0dD Z1dE Z2dF Z3dG Z4dH Z5dI Z6dJ Z7dK Z8dL Z9dM Z:dN Z;dO Z<dP Z=dQ Z>dR Z?dS Z@dydTZAdzdUZBdV ZC e            ZD	  e ej        dW eEeF          z  ejG                   ej        dX eEeF          z  ejG                   ej        dY eEeF          z  ejG                  Z          eD_!        d[ ZHd\ ZId] ZJd^ ZKd_ ZLd` ZMda ZNdb ZOdc ZPdd ZQde ZRdf ZSdg ZTdh ZUdi ZVdj ZWdk ZXeH ej        dleFjY        z  ejG                  feI ej        dmeFjY        z  ejG                  feJ ej        dnejG                  feO ej        doejG                  feQ ej        dpeFjY        z  ejG                  fgeD_Z        dq Z[dr Z\ds Z]dt Z^du Z_dv Z`dw Zad>S ){rX   z:
    Generic classifier of the first line of a block.
    ()ru   r   )r   r   r   r  r   r   rj   )parensrparenperiod)arabic
loweralpha
upperalpha
lowerroman
upperromanr   z[a-z]z[A-Z]z
[ivxlcdm]+z
[IVXLCDM]+r   z\+-[-+]+-\+ *$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"%(option)s(, %(option)s)*(  +| ?$)z	>>>( +|$)z\|( +|$)z
\.\.( +|$)z__( +|$)z(%(nonalphanum7bit)s)\1* *$)bullet
enumeratorfield_markeroption_markerdoctest
line_blockgrid_table_topsimple_table_topexplicit_markuprR  rm   r   c                     | j                                         \  }}}}|                     ||          }| xj        |z  c_        |s#| xj        |                     d          z  c_        ||g fS )zBlock quote.zBlock quote)r^   get_indentedblock_quoterc   r   )	r2   r  rn   
next_stateindentedindentr   r   elementss	            r"   r  zBody.indent  s|     ,,..	6;##Hk::x 	@KK400???KK
B&&r!   c                    g }|rt          j        d                    |                    }| j                            |dz             \  |_        |_        |                     ||          \  }}}}}|                     |||           |	                    |           |r&| 
                    |||z             \  }	}
||	z  }||
z  }|}|r!|d         s|dd          }|dz  }|r|d         ||S )Nr   r+  ru   r   )r   r  r   r^   ra   r@   rm   split_attributionr   r}   parse_attribution)r2   r  r   r  
blockquoteblockquote_linesattribution_linesattribution_offsetnew_line_offsetattributionr   s              r"   r  zBody.block_quote  s@    	!*TYYx5H5HIIIJ#77AFFZ
 !% 6 6x M M	.ZHHHOOJ'''  %(,(>(>%{3E'E)G )G%Xk)
H$)K !8A; !#ABB<q   !8A; !#  	!( r!   u   (---?(?!-)|—) *(?=[^ \n])c                    d}d}t          t          |                    D ]}||                                         }|r|r||dz
  k    r| j                            |          }|r|                     ||          \  }}	|rf|||         }
|
                    |                                d           |
                    |	d           |d|         |
|||d         ||z   fc S d}|}|ddddfS )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  )r   T)rangery   r   attribution_patternr  check_attribution	trim_leftr  )r2   r  r   blanknonblank_seenirm   r  attribution_endr  a_liness              r"   r  zBody.split_attribution  sK    s8}}%% 	4 	4AA;%%''D   CUa!e^^ 4::4@@E 	C262H2H$a3) 3)/* C&.q/@&AG#--eiikkq-AAA#--fA->>>$,RaRL'$%x0@0@'A$//$A$C C C C !%T4t33r!   c                    d}|dz   }t          |dz   t          |                    D ]}||                                         }|s nr|2t          |          t          |                                          z
  }Tt          |          t          |                                          z
  |k    r dS |dz  }||pdfS )zt
        Check attribution shape.
        Return the index past the end of the attribution, and the indent.
        Nru   )NNr   )r  ry   r   lstrip)r2   r  attribution_startr  r  rm   s         r"   r  zBody.check_attribution  s    
 !(1,c(mm<< 
	 
	AA;%%''D ~TS%7%77TS///699!zz : FA6;Qr!   c                    d                     |                                          }d|z   }|                     ||          \  }}t          j        |dg|R  }| j                            |          \  |_        |_        ||fS )Nr   ru   r   )	r   r   r   r   r  r^   ra   r@   rm   )r2   r  r   r   r   r   r   rK   s           r"   r  zBody.parse_attribution  s    yy""))++["..tV<<	8 r6I666!%!3!G!G!O!OTYX~r!   c                 @   t          j                    }| j                                        \  |_        |_        | xj        |z  c_        |j        d         |d<   |                     |	                                          \  }}||z  }| j        j
        dz   }|                     | j        j        |d         | j                                        dz   |d|          \  }}|                     |           |s#| xj        |                     d          z  c_        g |g fS )Bullet list item.r   r  ru   N
BulletListrN   rK   r[   r   zBullet list)r   bullet_listr^   ra   r@   rm   rc   r  	list_itemr  r   r   rM   rh   rf   r   )	r2   r  rn   r  ulr  r   r   r  s	            r"   r  zBody.bullet  s     !/CCEE	27r|A8..55<
a#/!3(,(>(> ,VWW5-==??!C\'	 )? )) ))%
 	''' 	@KK400???KK:r!!r!   c                    | j                                         \  }}| j         j        |d          r| j                             |          \  }}}n| j                             |          \  }}}}t          j        d                    |                    }||c|_        |_        |r| 	                    |||           ||fS )Nr   rN   rK   )
r^   ra   rm   get_known_indentedget_first_known_indentedr   r  r   r@   r   )r2   r  srcsrcliner  r   r   listitems           r"   r  zBody.list_item  s    )==??W"677+ 	E"55f== 0Hk<< ";;FCC 8Hfk<?499X#6#677),g& 	-h[#+  - - -%%r!   c                 r   |                      |          \  }}}}|                     |||          st          j        d          t	          j                    }| xj        |z  c_        |dk    rd|d<   n||d<   | j        j        |         j	        |d<   | j        j        |         j
        |d<   |dk    r6||d<   | j                            d	|d
|d          }	| xj        |	z  c_        |                     |                                          \  }
}||
z  }| j        j        dz   }|                     | j        j        |d         | j                                        dz   |d||||dk    d          \  }}|                     |           |s#| xj        |                     d          z  c_        g |g fS )zEnumerated List Itemr   ru  r  enumtyper   r   ru   r   z,Enumerated list start value not ordinal-1: "z" (ordinal r  NEnumeratedList)lastordinalformatrv  )rN   rK   r[   r   r   zEnumerated list)parse_enumeratoris_enumerated_list_itemr   TransitionCorrectionr   enumerated_listrc   r  
formatinfor   r   r:   infor  r  r^   r   r   rM   rh   rf   r   )r2   r  rn   r  r  sequencer   ordinalenumlistr,  r  r   r   newline_offsets                 r"   r  zBody.enumerator  s   *.*?*?*F*F'$++GXvFF 	<3F;;;(**xs??#+HZ  #+HZ !Y1&9@!Y1&9@a<< 'HW-$$$44"# #C KK3KK!%		!<!<,H#/!3'+'='= ,VWW5-==??!C+;'-4(.&.#o7 7 (> (8 (8$ 	~&&& 	DKK4001BCCCKK:r!!r!   Nc                    |                                 }d}| j        j        D ]}||         r nt          d          ||         | j        j        |         j        | j        j        |         j                 }|dk    rd}n\|rI	 | j        j        |                             |          r|}n1# t          $ r t          d|z            w xY w|dk    rd}n|dk    rd}|sE| j        j
        D ])}| j        j        |                             |          r n*t          d	          |dk    rd
}n4	  | j        j        |         |          }n# t          j        $ r d}Y nw xY w||||fS )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.
        r   zenumerator format not matchedru  zunknown enumerator sequence: %sr  r  Ir  zenumerator sequence not matchedru   N)r  r  formatsr)   r	  r   r  sequenceregexpsr  KeyError	sequences
convertersr   InvalidRomanNumeralError)r2   r  expected_sequencer  r  r  r   r  s           r"   r  zBody.parse_enumerator7  s   $ OO%%	i' 	? 	?F   =>>> !5f!=!C#'9#7#?#C"D E3;;HH 
	$.9,->?EEdKK 10H . . .!"C$,#- . . .. S[[#HHS[[#H 	E I/ E E9,X6<<TBB E ""CDDDs??GG8$).x8>>1   xw..s   'B- -C
/E EEc                    |dS 	 | j                                         }| j                                          n*# t          $ r | j                                          Y dS w xY w|dd                                         sdS |                     |dz   ||          }|rC|\  }}	 |                    |          s|                    |          rdS n# t          $ r Y nw xY wdS )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^   r   r   rg   stripmake_enumeratorr  	TypeError)r2   r  r  r  r   resultnext_enumeratorauto_enumerators           r"   r  zBody.is_enumerated_list_itemn  s,    ?4	/*4466I
 ,,....	  	 	 	,,...11	
 !}""$$ 	1%%gk8VDD 	/5,O_((99  ++O<<1    ts!   9 #A A #*C 
CCc                    |dk    rd}n|dk    rt          |          }n|                    d          r+|dk    rdS t          |t          d          z   dz
            }nS|                    d          r,	 t	          j        |          }n(# t          j        $ r Y dS w xY wt          d	|z            |                    d
          r|	                                }n<|                    d          r|
                                }nt          d	|z            | j        j        |         }|j        |z   |j        z   dz   }|j        dz   |j        z   dz   }||fS )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.
        ru  r  r     Nr  ru   r   z!unknown enumerator sequence: "%s"r  r  rF  )strrS  chrr  r   toRoman
RomanErrorr)   r  r  r  r  r	  r   r   )r2   r  r  r  r  r	  r  r  s           r"   r  zBody.make_enumerator  s    s??JJ!!WJJ  )) .R<<4 3s88!3a!788

""7++ . !&w!7!7JJ'      44  ""E$,#- . . .""7++ .'--//

$$W-- .'--//

!"E$,#- . . .Y)&1
%,z9J<MM !$+c1J4EEK//s   7B BBc                    t          j                    }| xj        |z  c_        |                     |          \  }}||z  }| j        j        dz   }|                     | j        j        |d         | j                                        dz   |d|          \  }}| 	                    |           |s#| xj        | 
                    d          z  c_        g |g fS )zField list item.ru   N	FieldListr  z
Field list)r   
field_listrc   fieldr^   r   r   rM   rh   rf   r   )	r2   r  rn   r  r'  r(  r   r   r  s	            r"   r  zBody.field_marker  s    %''
z!"jj//|e
#/!3'+'='= ,VWW5-==??!C['	 (> () ()$
 	~&&& 	?KK400>>>KK:r!!r!   c                 &   |                      |          }| j                                        \  }}| j                                        }| j                            |                                          \  }}}}	t          j                    }
||
_        ||
_	        | 
                    ||          \  }}|
t          j        |dg|R  z  }
t          j        d                    |          g|R  }|
|z  }
|r|                     |||           |
|	fS )Nr   r   )parse_field_markerr^   ra   r   r  r  r   r(  r@   rm   r   
field_name
field_bodyr   parse_field_body)r2   r  r   r  r  r   r  r  r   r   
field_node
name_nodesname_messagesr,  s                 r"   r(  z
Body.field  s   &&u--)==??W#335588EE	6;[]]

!
$($4$4T6$B$B!
Me&tR=*====
%dii&9&9JMJJJ
j 
 	E!!(KDDD<''r!   c                 x    |                                 dd         }|d|                    d                   }|S )z6Extract & return field name from a field marker match.ru   N:)r"  rfind)r2   r  r(  s      r"   r*  zBody.parse_field_marker  s9    abb!'u{{3'''(r!   c                 6    |                      |||           d S )Nr  )r   )r2   r  r   rK   s       r"   r-  zBody.parse_field_body  s#    (dCCCCCr!   c                    t          j                    }| j                                        \  |_        |_        	 |                     |          \  }}n# t          $ r}| j        	                    d|z            }| xj
        |z  c_
        | j                            |                                          \  }	}
}}|                     |	|          }| xj
        |z  c_
        |s#| xj
        |                     d          z  c_
        g |g fcY d}~S d}~ww xY w| xj
        |z  c_
        ||z  }| j        j        dz   }|                     | j        j        |d         | j                                        dz   |d|          \  }}|                     |           |s#| xj
        |                     d          z  c_
        g |g fS )Option list item.zInvalid option list marker: %szOption listNru   
OptionListr  )r   option_listr^   ra   r@   rm   option_list_itemr   r:   r   rc   r  r  r  r   r   r   rM   rh   rf   )r2   r  rn   r  
optionlistr  r   r   r,  r  r  r   r  r   r  s                  r"   r  zBody.option_marker  s   &((
3355		JO	&%)%:%:5%A%A"Hll 	& 	& 	&-%%&F(-'. / /CKK3KK#<<UYY[[IIXv{L''+>>HKK8#KK Dt44]CCCz2%%%%%%%	& 	z!h
#/!3'+'='= ,VWW5-==??!C\'	 (> () ()$
 	~&&& 	@KK400???KK:r!!s   A 
DB-DDDc                    | j                                         }|                     |          }| j                             |                                          \  }}}}|s)|                     |           t          j        d          t          j	        dg|R  }t          j
        d                    |                    }	t          j        d||	          }
|r|                     |||	           |
|fS )Nr   r   r   r  )r^   rh   parse_option_markerr  r  rf   r   r  r   option_groupdescriptionr   r9  r   )r2   r  r   optionsr  r  r   r   r=  r>  r9  s              r"   r9  zBody.option_list_item  s   #3355**51188EE	6; 	<NN6"""3F;;;)"7w777'		((;(;<< 1"l2=? ? 	0h[#.  0 0 0--r!   c                    g }t          j        d|                                                                          }|D ]}|                                }d}|d                             dd          }t	          |          dk    r
||dd<   d}nt	          |d                   dk    rx|d                             d          r|d                             d	          r|d                             d
          r'|d         dd         |d         dd         g|dd<   d}t	          |          dk    rY|d                             d          r>|d                             d          r#d                    |dd                   g|dd<   dt	          |          cxk     rdk    rn nt          j	        |          }|t          j
        |d         |d                   z  }t	          |          dk    r&|t          j        |d         |d         |          z  }|                    |           t          dt	          |          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, (?![^<]*>)rF  r   =ru   Nrv   -z--+r   <r   r  )	delimiterz wrong number of option tokens (=z), should be 1 or 2: "")r   rI  r"  r   ry   r  rS  r   r   r  option_stringoption_argumentr}   r   )	r2   r  optlistoptionstringsoptionstringtokensrE  firstoptr  s	            r"   r<  zBody.parse_option_marker  sh    %++--2F2F2H2HII) 	: 	:L!''))FIaysA..H8}}q  %rr
		fQi..1$$q	,,S11 % &q	 4 4T : : % !)..s33 %
 %QimVAYqrr];rr
	6{{QF1I$8$8$=$=(.r
(;(;C(@(@  "hhvabbz223qrr
3v;;####!#####l33%-fQiCCCv;;??e3F1Ivay>GI I I IFv&&&&!k!&kkkk<<<9: : : r!   c                     d                     | j                                                  }| xj        t	          j        ||          z  c_        g |g fS )Nr   )r   r^   get_text_blockrc   r   doctest_block)r2   r  rn   r  r   s        r"   r  zBody.doctest6  sN    yy+::<<== 	u*4666:r!!r!   c                    t          j                    }| xj        |z  c_        | j                                        }|                     ||          \  }}}||z  }| xj        |z  c_        |sm| j        j        dz   }	|                     | j        j        |	d         | j        	                                dz   |dd          \  }
}| 
                    |
           |s-| xj        | j                            d|dz             z  c_        t          |          r/|d         j        d|d         _        |                     |           g |g fS )zFirst line of a line block.ru   N	LineBlockr   r  z%Line block ends without a blank line.r   )r   r  rc   r^   r   line_block_liner   r   rM   rh   rf   r:   r   ry   r  nest_line_block_lines)r2   r  rn   r  r   r   rm   r   r   r   r  s              r"   r  zBody.line_block>  si    ""u#3355'+';';E6'J'J$hx 	,'3a7F,0,B,B$09#1AACCaGK 	 -C -" -")O\
 NN?+++ 	KK4=007AX 1   KK u:: 	.Qx&"#a&&u---:r!!r!   c                    | j                             |                                d          \  }}}}d                    |          }|                     ||          \  }}	t          j        |dg|R  }
|j                                        dk    r*t          |
                    d                    dz
  |
_        |
|	|fS )z(Return one line element of a line_block.Tuntil_blankr   r   r   ru   )r^   r  r  r   r   r   rm   r  r   ry   r"  r  )r2   r  r   r  r  r   r   r   
text_nodesr   rm   s              r"   rS  zBody.line_block_lineX  s     88EI 9 K K	6; yy""#//f==
Hz$0Z000<  C''ekk!nn--1DKX|++r!   c                     t          dt          |                    D ]4}t          ||         dd           ||dz
           j        ||         _        5|                     |           d S )Nru   r  )r  ry   r   r  nest_line_block_segment)r2   r   r   s      r"   rT  zBody.nest_line_block_linesd  sj    1c%jj)) 	> 	>EuU|Xt44<&+EAI&6&=e#$$U+++++r!   c                    d |D             }t          |          }g }t          j                    }|D ]}|j        |k    r|                    |           #t          |          r=|                     |           |                    |           t          j                    }|                    |           t          |          r*|                     |           |                    |           ||d d <   d S )Nc                     g | ]	}|j         
S r    )r  )rK  items     r"   
<listcomp>z0Body.nest_line_block_segment.<locals>.<listcomp>k  s    11144;111r!   )minr   r  r  r}   ry   rZ  )r2   r   indentsleast	new_items	new_blockr]  s          r"   rZ  zBody.nest_line_block_segmentj  s   115111G	$&&	 	' 	'D{U""  &&&&y>> 300;;;$$Y/// % 0 2 2I  &&&&y>> 	(((333Y'''aaar!   c                 R    |                      |||| j        t          j                  S )zTop border of a full table.)	table_topisolate_grid_tabler   GridTableParserr2   r  rn   r  s       r"   r  zBody.grid_table_top}  s*    ~~eWj"5)9; ; 	;r!   c                 R    |                      |||| j        t          j                  S )zTop border of a simple table.)re  isolate_simple_tabler   SimpleTableParserrh  s       r"   r  zBody.simple_table_top  s*    ~~eWj"7);= = 	=r!   c                     |                      ||          \  }}| xj        |z  c_        |sF| j                            d| j                                        dz             }| xj        |z  c_        g |g fS )zTop border of a generic table.z Blank line required after table.ru   r   )tablerc   r:   r   r^   r   )	r2   r  rn   r  isolate_functionparser_classrB  r   r,  s	            r"   re  zBody.table_top  s     "&,<l!K!K,x 	-''2'7799!; ( = =C KK3KK:r!!r!   c                     |            \  }}}|r	  |            }|                     |          }| j                                        t          |          z
  dz   }|                     ||          }	|	g|z   }
nV# t
          j        $ rB}|                     |d                    |j	                  |j
                  |z   }
Y d}~n
d}~ww xY w|}
|
|fS )zParse a table.ru   rF  )r   N)r   r^   r   ry   build_tabler   TableMarkupErrormalformed_tabler   r	  r   )r2   rn  ro  r   r   r   parser	tabledata	tablelinerm  rB  errs               r"   rm  z
Body.table  s	   (8(8(:(:%x 	 	N%"LL//	!/??AACJJN !	((I>>!7X-/ N N N//sxx7I7I7:z 0 C CEMNN  H%%s   A'A: :C	8CCc                 *   g }d}	 | j                             d          }nY# t          j        $ rG}|j        \  }}}|                    | j                            d||                     d}Y d }~nd }~ww xY w|                                 |	                    | j
                   t          |d                                                   }t          t          |                    D ]b}||                                         ||<   ||         d         dvr3d}| j                             t          |          |z
             ||d =  nc| j                            |d                   sd}t          t          |          d	z
  dd          D ]Y}| j                            ||                   r7| j                             t          |          |z
  dz              ||dz   d =  n.Z|                    |                     |                     g ||fS t          t          |                    D ]Z}t          ||                   |k    s||         d         dvr/|                    |                     |                     g ||fc S [|||fS )
Nru   T
flush_leftUnexpected indentation.r@   rm   r   z+|r   rv   )r^   rO  r   UnexpectedIndentationErrorr	  r}   r:   r   
disconnectpad_double_widthdouble_width_pad_charry   r  r  r   grid_table_top_patr  extendrs  )	r2   r   r   r   rw  r  r  widthr  s	            r"   rf  zBody.isolate_grid_table  s   	&555FFEE6 	 	 	"%(E3OODM//0I7: 0 J J K K KLLLLLL		
 	t9:::E!HNN$$%%s5zz"" 	 	AQx~~''E!HQx{$&& "00Ua@@@!""I	 '
 &,,U2Y77 
	2L3u::>1b11 2 2*00q:: &44SZZ!^a5GHHHacddE
  4 4U ; ;<<<8\11s5zz"" 	2 	2A58}}%%q"T)A)A 4 4U ; ;<<<8\1111 *B h,,s   " A8=A33A8c                 ^   | j         j        }| j         j        }t          |          dz
  }t          ||                                                   }| j        j        }d}d }|dz   }||k    r||         }	 ||	          }
|
rt          |	                                          |k    re| j                             ||z
             |                     |||dz            d          }g |||k    p||dz                                             fS |dz  }|}|dk    s#||k    s||dz                                            s|}n|dz  }||k    |r-d}| j                             ||z
             |||dz            }n,d}| j                             ||z
  dz
             ||d          }|                     |d|z            }g || fS | j                             ||z
             |||dz            }|	                    | j
                   |g ||k    p||dz                                             fS )Nru   r   z5Bottom/header table border does not match top border.rv   z$ or no blank line after table bottomr   zNo bottom table border found%s.)r^   r   rM   ry   r  simple_table_border_patr  r   rs  r  r  )r2   r   r   limittoplenpattern_matchfoundfound_atr  rm   r  r   r  extrar   s                  r"   rj  zBody.isolate_simple_table  s   ".".E

QU5\''))**4:AI5jj8D!M$''E tzz||$$..&00U;;;#33eAaCi( +0 1  1H xe)M51:;K;K;M;M7MMM
A::e51:3C3C3E3ECFA 5jj"  &>",,X-=>>>eHQJ./",,QY];;;eff++85@B BHxU**$$S5[111eCEk"t9:::b#,BeCEl.@.@.B.B*BBBr!   c                 >   |                     | j        d           d                    |          }d}| j                                        t          |          z
  dz   }|r|d|z   z  }| j                            |t          j	        ||          ||z             }|gS )Nr   r   zMalformed table.ru   r   )
replacer  r   r^   r   ry   r:   r   r   r   )r2   r   detailr   r   r3  	startliner   s           r"   rs  zBody.malformed_table  s    d0"555yy$&66883u::EI	 	%tf}$G##GU-@t-L-L)26)9 $ ; ;wr!   c                    |\  }}}t          j                    }|dk    r|dxx         dgz  cc<   n|r|dxx         dgz  cc<   t          j        t          |                    }	||	z  }|D ]-}
t          j        |
          }|rd|j        d<   |dz  }|	|z  }	.|r6t          j                    }|	|z  }	|D ]}||                     ||          z  }t          j                    }|	|z  }	|D ]}||                     ||          z  }|S )	Nrv  classeszcolwidths-autozcolwidths-given)cols)colwidthru   stub)	r   rm  tgroupry   colspec
attributestheadbuild_table_rowtbody)r2   ru  rv  stub_columnswidths	colwidthsheadrowsbodyrowsrm  r  r  r  r  rowr  s                  r"   rq  zBody.build_table  sg   (1%	8XV)!1 22 	4)!2 333y>>222! 	 	HmX666G "-."6*!gFF 	>KMMEeOF > >--c9===% 	: 	:CT))#y999EEr!   c                     t          j                    }|D ]b}||\  }}}}i }	|r||	d<   |r||	d<   t          j        di |	}
||
z  }d                    |          r|                     |||z   |
           c|S )Nmorerowsmorecolsr   r  r    )r   r  entryr   r   )r2   rowdatarv  r  cellr  r  r   	cellblockr  r  s              r"   r  zBody.build_table_row  s    ikk 	. 	.D|481Hh	J 2)1
:& 2)1
:&K--*--E5LCwwy!! .!!))F:J', " . . .
r!   a?  
                            (
                              _               # anonymous target
                            |               # *OR*
                              (?!_)           # no underscore at the beginning
                              (?P<quote>`?)   # optional open quote
                              (?![ `])        # first char. not space or
                                              # backquote
                              (?P<name>       # reference name
                                .+?
                              )
                              %(non_whitespace_escape_before)s
                              (?P=quote)      # close quote if open quote used
                            )
                            (?<!(?<!\x00):) # no unescaped colon at end
                            %(non_whitespace_escape_before)s
                            [ ]?            # optional space
                            :               # end of reference name
                            ([ ]+|$)        # followed by whitespace
                            a  
                               (
                                 (?P<simple>%(simplename)s)_
                               |                  # *OR*
                                 `                  # open backquote
                                 (?![ ])            # not space
                                 (?P<phrase>.+?)    # hyperlink phrase
                                 %(non_whitespace_escape_before)s
                                 `_                 # close backquote,
                                                    # reference mark
                               )
                               $                  # end of string
                               a  
                                  (
                                    (?![ ])          # first char. not space
                                    (?P<name>.+?)    # substitution text
                                    %(non_whitespace_escape_before)s
                                    \|               # close delimiter
                                  )
                                  ([ ]+|$)           # followed by whitespace
                                  )r   rW  substitutionc                    | j                                         \  }}| j                             |                                          \  }}}}|                    d          }t          |          }	t          j        d                    |                    }
||
_	        ||
_
        |	d         dk    rG|	dd          }	d|
d<   |	r|
d                             |	           | j                            |
           nu|	dk    r"d}	d|
d<   | j                            |
           nM|
t          j        d|          z  }
|
d                             |	           | j                            |
           |	r| j                            |
|
           n| j                            |
|
           |r|                     |||
	           |
g|fS )
Nru   r   r   ru  rv  r   rw  r   r  )r^   ra   r  r  r"  r   r   footnoter   r@   rm   r}   r9   note_autofootnotenote_symbol_footnoter  note_footnoterZ  r1  r   )r2   r  r  r  r  r  r   r   r  r   r  s              r"   r  zBody.footnote_  s   )==??W88EE	66<Ae$$>$))H"5"566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Kz<''r!   c                 \   | j                                         \  }}| j                             |                                          \  }}}}|                    d          }t          |          }	t          j        d                    |                    }
||
_	        ||
_
        |
t          j        d|          z  }
|
d                             |	           | j                            |
           | j                            |
|
           |r|                     |||
           |
g|fS )Nru   r   r   r   r  )r^   ra   r  r  r"  r   r   citationr   r@   rm   r  r}   r9   note_citationrZ  r   )r2   r  r  r  r  r  r   r   r  r   r  s              r"   r  zBody.citation~  s   )==??W88EE	66<Ae$$>$))H"5"566EKE***  &&&##H---**8X>>> 	LhV(KKKz<''r!   c                    | j         j        j        }| j                                        }| j                            |                                dd          \  }}}}|j        d |                                         d                    |          z   }d |D             }|d         }	d}
	 |	                    |	          }|rn0|
dz  }
	 |	||
         z  }	n# t          $ r t          d          w xY wH|d |
= |d         d	z   |                                t          |	          z
  dz
  d                                          |d<   |                     ||||                    d
                    }|g|fS )NTF)rW  strip_indentr   c                 ,    g | ]}t          |          S r    r   rK  rm   s     r"   r^  z)Body.hyperlink_target.<locals>.<listcomp>       555tT""555r!   r   ru   zmalformed hyperlink target.rF  r   )explicitr  r   r^   r   r  r  r  r   r  r|   r   ry   r  make_targetr"  )r2   r  r  r   r   r  r   r   	blocktextrA  
blockindextargetmatchr   s                r"   hyperlink_targetzBody.hyperlink_target  s   -(/#335588$U 9 D D	 L%))++.51A1AA	55u555(
	A!--00K !OJA5,, A A A!"?@@@A	A +:+!HsNKOO$5$5c'll$B1$D$E$EFLLNNa!!%F"-"3"3F";";= =x%%s   C C1c                 n   |                      |||          \  }}|dk    r_t          j        |dt          |                    }||_        |                     |d||           | j                            |           |S |dk    r/t          j        |d          }|                     ||||           |S |S )NrE  r   rD  rO  )parse_targetr   r   r   rT  
add_targetr9   rY  )r2   r   
block_textr   target_nametarget_typer   r   s           r"   r  zBody.make_target  s     --eZHHT)##\*b.:N:NOOOF-1F*OOKVV<<<M..v666MH$$\*b11FOOKvv>>>MKr!   c                 P   |r`|d                                          dd         dk    r:d                    d |D                       }|                     |          }|rd|fS t          d                    |                    }d                    d |D                       }d|fS )	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
        r   Nr<  rF  c              3   >   K   | ]}|                                 V  d S r/   )r  r  s     r"   rL  z$Body.parse_target.<locals>.<genexpr>  s*       @ @$ @ @ @ @ @ @r!   rE  c              3   ~   K   | ]8}d                      t          |                                                    V  9dS rH  )r   r   rI  rJ  s     r"   rL  z$Body.parse_target.<locals>.<genexpr>  sT       4 4!%  WWXd^^%9%9%;%;<< 4 4 4 4 4 4r!   rO  )r  r   is_referencer   )r2   r   r  r   rW  rE  	ref_partss          r"   r  zBody.parse_target  s      	*U2Y__&&rss+s22 @ @% @ @ @@@I''	22G * ')),SXXe__==	HH 4 4)24 4 4 4 4	""r!   c                     | j         j        j                            t	          |                    }|sd S t          |                    d          p|                    d                    S )Nsimplephrase)r  r  rW  r  r   r   r"  )r2   rW  r  s      r"   r  zBody.is_reference  sb    &066%i002 2 	4H--FX1F1FGGGr!   c                    ||_         |rt          t          |                    }|d                             |           |r4| j                            |          }|r||d<   nt          d|z            | j                            || j	                   d S |r||d<   d|d<   | j        
                    |           d S )Nr   rO  zproblem with URI: %rru   rR  )rm   r   r   r}   r?   rU  r	   r9   rZ  rc   note_anonymous_target)r2   
targetnamerO  r   r   r   r   s          r"   r  zBody.add_target  s     	8!(:"6"677D7O""4((( Ll--f55 L'*F8$$*+AF+JKKKM..vt{CCCCC *#)x "#F;M//77777r!   c           	         | j         j        j        }| j                                        \  }}| j                            |                                d          \  }}}}|j        d |                                         d                    |          z   }	|	                                 t          |d                                                   }
d}	 |                    |
          }|rnR|dz  }	 |
dz   t          ||                                                   z   }
n# t          $ r t          d          w xY wj|d |= |                                t!          |
          z
  dz
  }|d                                         dz   |d	         |d<   |d         s|d= |dz  }|rJ|d	                                         s0|                                 |r|d	                                         0|                    d
          }t'          j        |	          }||_        ||_        |s9| j                            d|z  t'          j        |	|	          ||          }|g|fS |d                                         |d<   |d                             t'          j        |                     |                     |||d|          \  }}d}|d d          D ]U}t;          |t&          j                  s4t;          |t&          j                  s| xj         ||         z  c_         ||= P|dz  }V|!                    t&          j"                  D ]}| #                    |          rzt'          j        d|$                                                                          }| j        %                    d|j&        z  |t'          j        |	|	          ||          }|g|fc S t!          |          dk    r9| j                            d|z  t'          j        |	|	          ||          }|g|fS | j'        (                    ||| j                    |g|fS )NFr  r   r   Tru   rF  z"malformed substitution definition.r   r   z.Substitution definition "%s" missing contents.r|  r   SubstitutionDefr  r   z6Substitution definition contains illegal element <%s>:z.Substitution definition "%s" empty or invalid.))r  r  r  r^   ra   r  r  r  r   r~  r   r   r  r  r|   r   ry   r{   r"  r   substitution_definitionr@   rm   r:   r   r   r}   r   r   r   Inlinery  rc   findallElement*disallowed_inside_substitution_definitionspformatr   tagnamer9   note_substitution_def)r2   r  r  r  r  r   r  r   r   r  rA  r  subdefmatchr   subnamesubstitution_noder,  new_abs_offsetr  rK   r  s                        r"   substitution_defzBody.substitution_def  s   -(5)==??W88FK 9 M M	 \,599;;,/$))E2B2BB	eAhoo//00
		H!--00K !OJH!C-+.3J.?.E.E.G.G+I +I I H H H!"FGGGH		H +:+!!#g,,.q0!HNN$$s*E"H5aQx 	aaKF 	E"IOO-- 	IIKKK  	E"IOO-- 	##F++!9)DD#& !( 	'-''@7J#Iy99 ( * *C 5,&&8>>##a'"))+G44	6 	6 	6'+'='=&/@-L (> (J (J$ %aaa( 	 	DtU\22 !$
33033%a((Q%--em<< 	+ 	+D>>tDD +-b$,,..2G2G2I2IJJm))Ll#U0IFFW	 * . .
 ul****+  !!Q&&-''BWL%i;;7 ( , ,C 5,&&++w	5 	5 	5!"L00s   4-D" "D<c                     |d         s^t          |t          j                  r|                    d          s/t          |t          j                  r|                    d          rdS dS )NidsrR  rv  TF)r   r   rW  getr{  )r2   rK   s     r"   r  z/Body.disallowed_inside_substitution_definitions+  sk    K 	$00	59XXk5J5J	$ 899	>Bhhv>N>N	 45r!   c                     |                     d          }t          j        || j        j        | j                  \  }}| xj        |z  c_        |r|                     ||||          S |                     |          S )z?Returns a 2-tuple: list of nodes, and a "blank finish" boolean.ru   )	r"  r   	directiverH   r;   r9   rc   run_directiveunknown_directive)r2   r  option_presets	type_namedirective_classr   s         r"   r  zBody.directive3  s    KKNN	$.$8ty)4=%: %:!x 	5%%	>C C C )))444r!   c                    t          |t          t          f          rddlm}  ||          }| j                                        }| j        j        }| j                            |	                                d          \  }}	}
}d
                    | j        j        || j        j        dz                      }	 |                     ||
||          \  }}}}nk# t          $ r^}| j                            d|dd
                    |j                  d	t#          j        ||          |
          }|g|fcY d}~S d}~ww xY w ||||||||| | j        	  	        }	 |                                }nh# t(          j        j        j        $ rL}| j                            |j        |j        |
          }|t#          j        ||          z  }|g}Y d}~nd}~ww xY wt          |t6                    sJ d|z              t9          t;          |                    D ];}t          ||         t"          j                  sJ d|d|d||                     <||p| j                                        fS )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_topr   ru   z
Error in "z" directive:
rF  rj   r   Nz+Directive "%s" must return a list of nodes.zDirective "z"" returned non-Node object (index z): ) r   r   r   docutils.parsers.rstr  r^   r   r   r  r  r   rM   parse_directive_blockr   r:   r   r	  r   r   rL   docutilsparsersrstDirectiveErrorsystem_messager   r,  listr  ry   Nodeis_next_line_blank)r2   r  r  r  r  r  r   initial_line_offsetr  r  r   r   r  	argumentsr?  contentcontent_offsetr  r   directive_instancer  msg_noder  s                          r"   r  zBody.run_directive?  s   * i,
!;<< 	>GGGGGG229==I#3355"0<88CD 9 F F	6; YYt1=$"4"@1"DD F G G
		)**8[+4nF F 8Iw  	) 	) 	)M'''3<993688FK3H3H3H3HJ#J
;;& ( J JE 7L(((((((	) 'Yy'7FJd.@B B	 '++--FF#2 	  	  	 }33EK9? 4 A AH+J
CCCHZFFFFFF		 
 &$'' 	I 	I<yH	I 	I 	Is6{{## 	1 	1AfQi44 1 1 1 yy!!!VAYY01 1 1 1 G 2 E E G GI 	Is8   ;C 
E#AD<6E<EE2 2GAGGc                    |j         }|j        }|r3|d                                         s|                                 |dz  }|rJ|d                                         s0|                                 |r|d                                         0|r`|j        s	|j        s|rPt          |          D ]\  }}|                                s n|dz  }|d |         }	||dz   d          }
||z   dz   }n|}
|}g }	|r|                     |||	          \  }}	ni }|	r|j        s|j        s|	||d          z   }
|}g }	|
rO|
d                                         s5|
                                 |dz  }|
r|
d                                         5|j        s|j        r| 	                    ||	          }ng }|
r|st          d          |||
|fS )Nr   ru   r   zno content permitted)option_spechas_contentr  
trim_starttrim_endrequired_argumentsoptional_arguments	enumerateparse_directive_optionsparse_directive_argumentsr   )r2   r  r   r  r  r  r  r  rm   	arg_blockr  r  r?  r  s                 r"   r  zBody.parse_directive_block{  sq   ++ 	HQK--// 	!!!1K 	 x|1133 	   	 x|1133 	  	5 	%8	'	 %X..  4zz|| E Q !IqsttnG(1_q0NNG(NI 	!%!=!=Y"8 "8GYY G 	i: 	!*!=	(122,.G(NI 	 gaj..00 	    aN  	 gaj..00 	  ' 	9+G 	669& &II I 	6; 	64555'7N::r!   c                 Z   |                                 }t          |          D ]@\  }}t          j        t          j        d         |          r||d          }|d |         } nAg }|r@|                     ||          \  }}	|r|                    |	           nt          |	          ||fS )Nr  )	r   r  r   r  rX   r  parse_extension_optionsr1   r   )
r2   r  r  r  r?  r  rm   	opt_blocksuccessr   s
             r"   r  zBody.parse_directive_options  s     %%'' ++ 	 	GAtxn5t<< %abbM	%bqbM	
 I 	( 889BD DMGT (t$$$$!$'''	!!r!   c                    |j         }|j        }d                    |          }|                                }t	          |          |k     r"t          |dt	          |          d          t	          |          ||z   k    rJ|j        r|                    d ||z   dz
            }n&t          d||z   dt	          |          d          |S )Nr   z argument(s) required, z	 suppliedru   zmaximum z argument(s) allowed, )r   r  r   rI  ry   r   final_argument_whitespace)r2   r  r  requiredoptionalarg_textr  s          r"   r  zBody.parse_directive_arguments  s    //99Y''NN$$	y>>H$$!)3y>>>>; < < <^^h1112 =$NN4H1Dq1HII		!k(***C	NNNN<= = = r!   c                    t          j                    }|                     |d|dd          \  }}|t          |          k    rdS 	 t	          j        ||          }n# t          $ r}dd|j        d         z  fcY d}~S d}~wt          t          f$ r)}ddd	
                    |j                  z  fcY d}~S d}~wt          j        $ r)}dd
d	
                    |j                  z  fcY d}~S d}~ww xY w|rd|fS d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.
        r   ExtensionOptionsT)r[   r   )r   zinvalid option blockzunknown option: "%s"Nzinvalid option value: %srF  zinvalid option data: %sru   )r   zoption data incompletely parsed)r   r'  r   ry   r   extract_extension_optionsr  r	  r   r  r   ExtensionOptionError)r2   r  	datalinesrK   r  r   r?  r  s           r"   r  zBody.parse_extension_options  se    !!'+'='=D0B (> (! (!$ S^^++,,	H5dKHHGG 	> 	> 	>,v{1~========I& 	I 	I 	I0388FK3H3HHHHHHHHH) 	H 	H 	H/#((6;2G2GGGGGGGGG	H 	8g:77sB   A 
C1'A>8C1>C1B60C16C1C,&C1,C1c                    | j                                         }| j                             dd          \  }}}}d                    |          }| j                            d|z  t          j        ||          |          }|g|fS )Nr   Fr  r   zUnknown directive type "%s".r   )r^   r   r  r   r:   r   r   r   )	r2   r  r   r  r  r   r   r   r   s	            r"   r  zBody.unknown_directive  s    #3355888OO	66<yy""##$BY$N$)$7d$C$C)/ $ 1 1 w$$r!   c                    | j                                         r|j        |                                d          }|                                st          j                    gdfS |                    d          r"| j        j	        
                                 g dfS | j                             |                                          \  }}}}|rJ|d                                         s0|                                 |r|d                                         0d                    |          }t          j        ||          g|fS )NTzend of inclusion from "r   r   )r^   r  r  r  r  r   commentr  r9   include_logr{   r  r  r   )r2   r  first_comment_liner  r  r   r   r   s           r"   r  zBody.comment  s7   0022 	 !&eiikkll!;%++-- /($..!,,-FGG  )--///4x88EE	66< 	 x|1133 	   	 x|1133 	 yy""dD))*L88r!   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                     |                      |          \  }}| xj        |z  c_        |                     |           g |g fS z3Footnotes, hyperlink targets, directives, comments.)explicit_constructrc   explicit_listr2   r  rn   r  rB  r   s         r"   r  zBody.explicit_markup3	  sK    !%!8!8!?!?,x<(((:r!!r!   c                    g }| j         j        D ]\  }}|                    |j                  }|r	  || |          c S # t          $ rm}| j                                        }d                    |j                  }|	                    | j
                            ||                     Y d}~ n	d}~ww xY w|                     |          \  }	}
|	|z   |
fS )z>Determine which explicit construct this is, parse & return it.rF  r   N)r  
constructsr  r  r   r^   r   r   r	  r}   r:   r   r  )r2   r  errorsr  r  expmatchr   r   r3  rB  r   s              r"   r  zBody.explicit_construct:	  s    #}7 		 		OFG}}U\22H !6$11111"   !/??AAF!hhuz22GMM$-"7"7f"7"M"MNNNEEEEE	 "&e!4!4,& ,..s   ?
B6	A"B11B6c                 N   | j         j        dz   }|                     | j         j        |d         | j                                         dz   | j        d|| j         j                  \  }}|                     |           |s%| xj        |                     d          z  c_        dS dS )z
        Create a nested state machine for a series of explicit markup
        constructs (including anonymous hyperlink targets).
        ru   NExplicit)rN   rK   r[   r   rE   zExplicit markup)	r^   r   r   rM   rh   rc   rE   rf   r   )r2   r   r   r  s       r"   r  zBody.explicit_listJ	  s    
 #/!3'+'='= ,VWW5-==??!C;j'-: (> (< (<$ 	~&&& 	DKK4001BCCCKKKK	D 	Dr!   c                     |                      |          \  }}| xj        |z  c_        |                     |           g |g fS zAnonymous hyperlink targets.)anonymous_targetrc   r  r  s         r"   rR  zBody.anonymousZ	  sK    !%!6!6u!=!=,x<(((:r!!r!   c                 Z   | j                                         }| j                             |                                d          \  }}}}|j        d |                                         d                    |          z   }d |D             }|                     |||d          }|g|fS )NTrV  r   c                 ,    g | ]}t          |          S r    r  r  s     r"   r^  z)Body.anonymous_target.<locals>.<listcomp>g	  r  r!   r   )r^   r   r  r  r  r   r  )	r2   r  r   r   r  r   r   r  r   s	            r"   r&  zBody.anonymous_targeta	  s    #335588EI 9 K K	 L%))++.51A1AA	55u555!!%FB??x%%r!   c                 d   | j         j        r|j        gdg fS |j                                        dk    rt	          j        d          t          |j                                                  dk     rW| j                            d| j         	                                          }| xj
        |z  c_
        t	          j        d          | j         j        }| j                            dt          j        ||          | j         	                                          }| xj
        |z  c_
        g |g fS )z,Section title overline or transition marker.Line::r      zeUnexpected possible title overline or transition.
Treating it as ordinary text because it's so short.r   z'Unexpected section title or transition.)r^   rE   r  r  r   r  ry   r:   r
  r   rc   rm   rk   r   r   )r2   r  rn   r  r,  r  s         r"   rm   z	Body.linek	  s.   * 	&L>62--\!!T))3F;;;##%%&&**-$$F'7799 % ; ;C KK3KK3F;;;*/I-&&;%i;;)99;; ' = =C KK3KKz2%%r!   c                     |j         gdg fS )z%Titles, definition lists, paragraphs.ry  r  rh  s       r"   r   z	Body.text	  s    ~vr))r!   r/   )r   r   )r   N)br   r   r   r5   r   TableParserr  r-   r  r	  keysr  r  sequencepatsr  r  r  r  r   r  r  r  r  r   r   r  simple_table_top_patr  patsr  escaper   r   r  initial_transitionsr  r  r  r  r  r  r  r  r  r  r  r  r  r(  r*  r-  r  r9  r<  r  r  rS  rT  rZ  r  r  re  rm  rf  rj  rs  rq  r  r  r   rF   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  rR  r&  rm   r   r    r!   r"   rX   rX   2  s         (3I=688D. F#cCCCF"SrBBBF"SrBBBD DDO ?''))DL2 2 2DN#+'.'.'3'3	5 5D
 "%%7%7%7%*_	6 6DO DN 1 1)3)C/*1 *1X&& $$5666%2:n55,(bj44?D4.D	DM$D*D)+/+<=DL5<DO<tCDN;dBD;dBDO2T9DN, G Gffibi 7 >???6llIBIdof&=&DEEEEGV
 4CdJN@4G!#.2*"047 H' ' '  2 %"*%FGG!4 !4 !4F     (  " " "&& & &!" !" !"F5/ 5/ 5/ 5/n  :#0 #0 #0J" " ""( ( ("  D D D" " "@. . ."( ( (T" " "" " "4
, 
, 
,, , ,  &; ; ;= = =
" 
" 
"& & &$$- $- $-L)C )C )CV	 	 	 	   4  $ vxxHF  & #'$w--'0& 24'= =( BJ  # &*T']] 3 57J@ @ "rz #& )-W#6 #%*	. 	.E+0 +0 +0HZ( ( (>( ( ("& & &2  # # #(H H H8 8 8$E1 E1 E1N  
5 
5 
5:I :I :Ix,; ,; ,;\" " "$  "8 8 8B% % %9 9 9" 2:  $./ 13
< <=  2:  $.	/ 13
	< <= 2:  :	' '( 2:  :	' '( 2:  $./ 13
< <=G*>HX" " "/ / / D D D " " "& & && & &,* * * * *r!   rX   c                       e Zd ZdZej                                        Zded<   d ej        D             Ze                    dd           d Z	d Z
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;-~]+:( +|$)rfc2822c                     g | ]}|d fS )rX   r    )rK  r   s     r"   r^  zRFC2822Body.<listcomp>	  s2     A A A# !&> A A Ar!   r   )r8  rX   c                    t          j        dg          }| xj        |z  c_        |                     |          \  }}||z  }| j        j        dz   }|                     | j        j        |d         | j                                        dz   |d|          \  }}| 	                    |           |s#| xj        | 
                    d          z  c_        g |g fS )RFC2822-style field list item.r8  )r  ru   NRFC2822Listr  zRFC2822-style field list)r   r'  rc   rfc2822_fieldr^   r   r   rM   rh   rf   r   )	r2   r  rn   r  	fieldlistr(  r   r   r  s	            r"   r8  zRFC2822Body.rfc2822	  s    $i[999	y "0077|U	#/!3'+'='= ,VWW5-==??!CM'	 (> () ()$
 	~&&& 	.KK400,. . .KK:r!!r!   c                    |j         d |j                             d                   }| j                            |                                d          \  }}}}t          j                    }|t          j        ||          z  }t          j        d	                    |                    }||z  }|r| 
                    |||           ||fS )Nr2  TrV  r   r  )r  findr^   r  r  r   r(  r+  r,  r   r   )	r2   r  r   r  r  r   r   	fieldnode	fieldbodys	            r"   r=  zRFC2822Body.rfc2822_field	  s    |3U\..s333488EI 9 K K	6; KMM	U%dD111	$TYYx%8%899	Y	 	.h[#,  . . .,&&r!   N)r   r   r   r5   rX   r  r   r5  insertr8  r=  r    r!   r"   r7  r7  	  s         
 }!!##H-HYA A'+'?A A Ar#6777" " "$' ' ' ' 'r!   r7  c                   N    e Zd ZdZddZeZeZeZeZeZ	eZ
eZeZeZeZeZeZeZdS )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`.
    Nc                 B    | j                                          t          z8Not a compound element member. Abort this state machine.)r^   r   rg   rh  s       r"   invalid_inputzSpecializedBody.invalid_input	  s    ((***r!   NNN)r   r   r   r5   rH  r  r  r  r  r  r  r  r  r  r  rR  rm   r   r    r!   r"   rE  rE  	  sp         ,   
 FFJ L!MGJ"N$#OIDDDDr!   rE  c                       e Zd ZdZd ZdS )r  z-Second and subsequent bullet_list list_items.c                     |j         d         | j        d         k    r|                                  |                     |                                          \  }}| xj        |z  c_        || _        g |g fS )r  r   r  )r  rc   rH  r  r  r   )r2   r  rn   r  r  r   s         r"   r  zBulletList.bullet	  so    <?dk(333   !%		!<!<,x(:r!!r!   N)r   r   r   r5   r  r    r!   r"   r  r  	  s)        77" " " " "r!   r  c                       e Zd ZdZd ZdS )DefinitionListz,Second and subsequent definition_list_items.c                     |j         gdg fS )zDefinition lists.
Definitionr.  rh  s       r"   r   zDefinitionList.text	  s    ~|R//r!   N)r   r   r   r5   r   r    r!   r"   rM  rM  	  s)        660 0 0 0 0r!   rM  c                       e Zd ZdZd ZdS )r  z1Second and subsequent enumerated_list list_items.c                    |                      || j        d                   \  }}}}|| j        k    sC|dk    r&|| j        d         k    s,| j        s%|| j        dz   k    s|                     |||          s|                                  |dk    rd| _        |                     |                                          \  }}	| xj        |z  c_        |	| _	        || _        g |g fS )zEnumerated list item.r  ru  ru   )
r  rc   r  rv  r  r  rH  r  r  r   )
r2   r  rn   r  r  r  r   r  r  r   s
             r"   r  zEnumeratedList.enumerator	  s    *.*?*?T[,+. +.'$dk!!CXZ1H%H%H(,	 &I(/D4Dq4H(I(I//6JJ )J    s??DI!%		!<!<,x(":r!!r!   N)r   r   r   r5   r  r    r!   r"   r  r  	  s)        ;;" " " " "r!   r  c                       e Zd ZdZd ZdS )r&  z(Second and subsequent field_list fields.c                 j    |                      |          \  }}| xj        |z  c_        || _        g |g fS )zField list field.)r(  rc   r   r2   r  rn   r  r(  r   s         r"   r  zFieldList.field_marker
  s=    "jj//|u(:r!!r!   N)r   r   r   r5   r  r    r!   r"   r&  r&  
  s)        22" " " " "r!   r&  c                       e Zd ZdZd ZdS )r7  z4Second and subsequent option_list option_list_items.c                     	 |                      |          \  }}n$# t          $ r |                                  Y nw xY w| xj        |z  c_        || _        g |g fS )r6  )r9  r   rH  rc   r   )r2   r  rn   r  r9  r   s         r"   r  zOptionList.option_marker 
  s{    	!-1-B-B5-I-I*ll 	! 	! 	!     	!''(:r!!s    <<N)r   r   r   r5   r  r    r!   r"   r7  r7  
  s)        >>" " " " "r!   r7  c                   B    e Zd ZdZej        Zej        Zd Zej	        Z
dS )r<  z6Second and subsequent RFC2822-style field_list fields.c                 j    |                      |          \  }}| xj        |z  c_        || _        g dg fS )r;  r<  )r=  rc   r   rT  s         r"   r8  zRFC2822List.rfc28222
  s?    "0077|u(="$$r!   N)r   r   r   r5   r7  r  r5  r8  rE  rH  r  r    r!   r"   r<  r<  +
  s>        @@#H%9% % % )EEEr!   r<  c                       e Zd ZdZd ZdS )r  zz
    Parse field_list fields for extension options.

    No nested parsing is done (including inline markup parsing).
    c                     g }t          |          dgz   D ]]}|                                r|                    |           ,|r/d                    |          }|t	          j        ||          z  }g }^dS )z5Override `Body.parse_field_body` for simpler parsing.r   r   N)r  r  r}   r   r   r   )r2   r  r   rK   r   rm   r   s          r"   r-  z!ExtensionOptions.parse_field_bodyD
  s    NNbT) 	 	Dzz|| T"""" yy''d333	 	r!   N)r   r   r   r5   r-  r    r!   r"   r  r  <
  s-         	 	 	 	 	r!   r  c                   &    e Zd ZdZej        Zd ZdS )rR  z,Second and subsequent lines of a line_block.c                     | j                                         }|                     ||          \  }}}| xj        |z  c_        | j        xj        |z  c_        || _        g |g fS )zNew line of line block.)r^   r   rS  rc   r   )r2   r  rn   r  r   rm   r   r   s           r"   r  zLineBlock.line_blockV
  sm    #3355'+';';E6'J'J$hth&(:r!!r!   N)r   r   r   r5   rE  rH  r  r  r    r!   r"   rR  rR  P
  s1        66)E" " " " "r!   rR  c                   ,    e Zd ZdZd Zd Zej        ZdS )r#  z0Second and subsequent explicit markup construct.c                 j    |                      |          \  }}| xj        |z  c_        || _        g |g fS r  )r  rc   r   r  s         r"   r  zExplicit.explicit_markupd
  s?    !%!8!8!?!?,x(:r!!r!   c                 j    |                      |          \  }}| xj        |z  c_        || _        g |g fS r%  )r&  rc   r   r  s         r"   rR  zExplicit.anonymousk
  s?    !%!6!6u!=!=,x(:r!!r!   N)	r   r   r   r5   r  rR  rE  rH  r  r    r!   r"   r#  r#  `
  s<        ::" " "" " " )EEEr!   r#  c                   \    e Zd ZdZ ej        dej        z            ddZddgZ	d Z
d Zd	S )
r  zG
    Parser for the contents of a substitution_definition element.
    z(%s)::( +|$)r   )embedded_directiver   ra  r   c                     |                      || j        d         d                   \  }}| xj        |z  c_        | j                                        s|| _        t
          )Nr   r   )alt)r  rc   r^   at_eofr   rg   r  s         r"   ra  z"SubstitutionDef.embedded_directive
  sf    !%48K4H4K "0 "M "M,x!((** 	- ,Dr!   c                 ~    | j                                         s| j                                         | _        t          r/   )r^   rd  r  r   rg   rh  s       r"   r   zSubstitutionDef.text
  s6    !((** 	H $ 2 E E G GDr!   N)r   r   r   r5   r   r   rF   r   r  r5  ra  r   r    r!   r"   r  r  u
  s{         
 !+
?-4-?,@ !A !A H 08      r!   r  c                       e Zd ZdZej        d         ddZddgZd Zd Zd	 Z	d
 Z
d Zd Zd Zd Z ej        d          Zd ZdS )ry  zs
    Classifier of second line of a text block.

    Could be a paragraph, a definition list item, or a title.
    rm   r   )	underliner   )rg  rX   )r   rX   c                     |                      || j                                        dz
            \  }}| xj        |z  c_        |r"| xj        |                                 z  c_        g dg fS )zEnd of paragraph.ru   rX   )r   r^   r   rc   r   )r2   r  rn   r  r   r   s         r"   r  z
Text.blank
  sw     "&t)99;;a?"A "A	;y  	0KK4--///KK62~r!   c                 8    |r|                      d |d            g S r/   )r  rr   s     r"   eofzText.eof
  s%     	,JJtWd+++	r!   c                 8   t          j                    }| j                                        dz
  }| j                            |          \  |_        |_        |                     |          \  }}||z  }| xj        |z  c_        | j        j	        dz   }| 
                    | j        j        |d         | j                                        dz   |d|d          \  }	}|                     |	           |s#| xj        |                     d          z  c_        g dg fS )Definition list item.ru   NrM  rO  )rN   rK   r[   r   r   zDefinition listrX   )r   definition_listr^   r   ra   r@   rm   definition_list_itemrc   r   r   rM   rh   rf   r   )
r2   r  rn   r  dlr   dl_itemr   r   r  s
             r"   r  zText.indent
  s&   "$$#33559!/CCFKK	27 $ 9 9' B B
gr#/!3'+'='= ,VWW5-==??!C%5'L	 (> (J (J$
 	~&&& 	DKK4001BCCCKK62~r!   c                    | j                                         }|d                                         }|j                                        }|dz   |z   }g }t	          |          t          |          k    rt          |          dk     rL| j         j        r,| j                            d|          }	| xj	        |	z  c_	        t          j        d          |d         dz   | j         j        z   }
| j                            dt          j        |
|
          |          }	|                    |	           | j         j        s|d         dz   | j         j        z   }
| j                                         \  }}| j                            dt          j        |
|
          ||	          }	| xj	        |z  c_	        | xj	        |	z  c_	        g |g fS |d         }g |d
d
<   |                     ||||dz
  |           g |g fS )zSection title.r   r   r,  zfPossible title underline, too short for the title.
Treating it as ordinary text because it's so short.r   r   zTitle underline too short.zUnexpected section title.r|  Nru   )r^   r   r   r  r   ry   rE   r:   r
  rc   r   r  rm   r   r   r   r}   ra   rk   r   )r2   r  rn   r  r   r   rg  r@   r   r,  r  r  r  r   s                 r"   rg  zText.underline
  s   #3355
!!##L''))		)Y//9~~!!%2 '-,,N# - % %C KK3&KK"7???#AJ-0B0GG	m++0'	9== , ! ! $$$!. 	&
T)D,>,CCI-AACCLC
 -&&+#Iy99 ' * *C KK8#KKKK3KKz2%%!
UFE6A:x@@@:r!!r!   c                 >   | j                                         dz
  }d}	 | j                             d          }nD# t          j        $ r2}|j        \  }}}	| j                            d||	          }Y d}~nd}~ww xY w|t          |          z   }
| 	                    |
|          \  }}| xj
        |z  c_
        | xj
        |z  c_
        |rM	 | j                                          n# t          $ r Y nw xY w| xj
        |                                 z  c_
        g |g fS )z
Paragraph.ru   NTry  r{  r|  )r^   r   rO  r   r}  r	  r:   r   r  r   rc   r   rg   r   )r2   r  rn   r  r  r,  r   rw  r  r  r   r   r   s                r"   r   z	Text.text
  s]   &66881<		@&555FFEE6 	@ 	@ 	@"%(E3-%%&?-0w & @ @CCCCCC	@ $u++%!%y!A!A	;y s 	0",,....   KK4--///KK:r!!s'   < A=(A88A=C( (
C54C5c                    | j                                         \  }}}}|rJ|d                                         s0|                                 |r|d                                         0|s|                                 S d                    |          }t          j        ||          }| j                             |dz             \  |_	        |_
        |g}|s(|                    |                     d                     |S )zReturn a list of nodes.r   r   ru   zLiteral block)r^   r  r  r  quoted_literal_blockr   r   r   ra   r@   rm   r}   r   )r2   r  r  r   r   r   r   rB  s           r"   r   zText.literal_block
  s    ,,..	66< 	 x|1133 	   	 x|1133 	  	/,,...yy""+D$77#1EEfQhOO				!? 	DOOD11/BBCCCr!   c           	         | j                                         }| j         j        }t          j                    }|                     | j         j        |d          ||dt          fdd          }|                     |           |j	        S )NFQuotedLiteralBlockrY   )rN   rK   rE   r   )
r^   rh   r   r   r  r   rM   rv  rf   children)r2   rh   r   parent_noder  s        r"   rt  zText.quoted_literal_block  s    ,<<>>#/moo***6773({4F3H3G"I "I + J J
 	~&&&##r!   c                    | j                                         }|dz
  }| j                                         \  }}}}t          j        d                    |t          |          z                       }| j                             |          \  |_        |_	        | 
                    ||          \  }	}
||	z  }t          j        dg|
R  }| j                             |          \  |_        |_	        ||z  }|d         dd          dk    r|| j                            d|          z  }|                     |||	           ||fS )
Nru   r   r   r   rM  r+  z`Blank line missing before literal block (after the "::")? Interpreted as a definition list item.r   r  )r^   r   r  r   rn  r   r  ra   r@   rm   termr   r:   r
  r   )r2   termline	dd_lineno	dt_linenor  r  r   r   rp  dt_nodesr   dds               r"   rn  zText.definition_list_item  s[   &6688	M	,,..	6;,ii4>> 9::< < +??	JJ		!YYx;;(8b,8,,,!/CCINN	272A;rsst##$-$$;  % " " "B 	(2FFF$$r!   z +: +c           
         t          |          dk    sJ |                     |d         |          \  }}t          j        |d                   }| j                            |          \  |_        |_        |g}t          t          |                    D ]}||         }t          |t          j
                  r| j                            |          }	t          |	          dk    r|dxx         |z  cc<   b|	d                                         }
t          j
        |
          }|dxx         |z  cc<   |	dd         D ]8}|                    t          j        t!          |d          |                     9|dxx         |z  cc<   ||fS )z9Return a definition_list's term and optional classifiers.ru   r   r   NT)ry   r   r   rz  r^   ra   r@   rm   r  r   ry  classifier_delimiterrI  r   r}   
classifierr   )r2   r   r   rX  r   dtrd  r  rK   r   r   textnoder   s                r"   rz  z	Text.term8  s   5zzQ#//a&AA
HZa!!!/CCFKK	27D	s:'' 	& 	&Aa=D$
++ &177==u::??bMMMT)MMMM 8??,,D$z$//HbMMMX-MMM %abb	 J J!((!,XdD-A-A4HHJ J J JJ "%(""r!   N)r   r   r   r5   rX   r  r5  r  rj  r  rg  r   r   rt  rn  r   r   r  rz  r    r!   r"   ry  ry  
  s          "]62 H02BC    
  ()" )" )"V" " ",  "
$ 
$ 
$% % %4 &2:g..# # # # #r!   ry  c                   0    e Zd ZdZd ZddZeZeZeZeZ	dS )SpecializedTextz
    Superclass for second and subsequent lines of Text-variants.

    All transition methods are disabled. Override individual methods in
    subclasses to re-enable.
    c                     g S )zIncomplete construct.r    rr   s     r"   rj  zSpecializedText.eofZ  s    	r!   Nc                     t           rG  rg   rh  s       r"   rH  zSpecializedText.invalid_input^  s    r!   rI  )
r   r   r   r5   rj  rH  r  r  rg  r   r    r!   r"   r  r  Q  sQ               EFIDDDr!   r  c                       e Zd ZdZd Zd ZdS )rO  z.Second line of potential definition_list_item.c                 :    | j                             d           g S )zNot a definition.rv   )r^   r   rr   s     r"   rj  zDefinition.eofl  s    ((+++	r!   c                 j    |                      |          \  }}| xj        |z  c_        || _        g dg fS )rl  rM  )rn  rc   r   )r2   r  rn   r  rp  r   s         r"   r  zDefinition.indentq  s@     $ 9 9' B Bw(#R''r!   N)r   r   r   r5   rj  r  r    r!   r"   rO  rO  h  s8        88  
( ( ( ( (r!   rO  c                   D    e Zd ZdZdZ	 d Zd Zd ZeZd Z	d
dZ
d
dZd	S )r*  zO
    Second line of over- & underlined section title or transition marker.
    ru   c                    |d                                          }| j        j        rd| j        _        n(t          |          dk     r|                     |           | j        rX| j                                        \  }}t          j	        |d                   }||_
        |dz
  |_        | xj        |z  c_        d| _        g S )z0Transition marker at end of section or document.r   Fr,  r  ru   )r  rH   r>   ry   state_correctioneofcheckr^   ra   r   
transitionr@   rm   rc   )r2   rn   markerr  r  r  s         r"   rj  zLine.eof  s    !!##9- 	+16DI..[[1__!!'***= 	&-AACCLC)GAJ???J #J%kJOKK:%KK	r!   c                 4   | j                                         \  }}|d                                         }t          |          dk     r|                     |           t          j        |          }||_        |dz
  |_        | xj	        |z  c_	        g dg fS )zTransition marker.r   r,  r  ru   rX   )
r^   ra   r  ry   r  r   r  r@   rm   rc   )r2   r  rn   r  r  r  r  r  s           r"   r  z
Line.blank  s    )==??W!!##v;;??!!'***%777

!A+
z!62~r!   c                    | j                                         dz
  }|d         }|j        }d}	 | j                                         }n# t          $ r |dz   |z   }t          |                                          dk     r|                     |||d           nG| j        	                    dt          j        ||          |          }	| xj        |	z  c_        g d	g fcY S Y nw xY w|d|d|}
|                                }|                                }| j        d
         d                             |          s|dz   |z   dz   |z   }t          |                                          dk     r|                     |||d           n| j        	                    dt          j        |
|
          |          }	| xj        |	z  c_        g d	g fS ||k    r|dz   |z   dz   |z   }t          |                                          dk     r|                     |||d           nE| j        	                    dt          j        |
|
          |          }	| xj        |	z  c_        g d	g fS |                                }g }t          |          t          |          k    r|dz   |z   dz   |z   }t          |                                          dk     r|                     |||d           nE| j                            dt          j        |
|
          |          }	|                    |	           |d         |d         f}d| _        |                     |                                |
||dz   |           d| _        g d	g fS )z#Potential over- & underlined title.ru   r   r   r   r,  rv   zIncomplete section title.r   rX   rg  z6Missing matching underline for section title overline.z$Title overline & underline mismatch.zTitle overline too short.)r^   r   r  r   rg   ry   r   short_overliner:   rk   r   r   rc   ro   r  r   r   r}   r  r   r  )r2   r  rn   r  r   overliner   rg  r  r,  r@   r   r   s                r"   r   z	Line.text  s   #335591:		&*4466II 
	& 
	& 
	& 4%/I8??$$%%))##GYBBBBm**/'	9== + ! ! s"62~%%% CB
	& "*555))<??$$$$&&	,Q/55i@@ 	& 4%/$6BI8??$$%%))##GYBBBBm**L'77 + ! ! s"62~%"" 4%/$6BI8??$$%%))##GYBBBBm**<)&&99! + # # s"62~%X.. 4%/$6BI8??$$%%))##GYBBBBm++1)&&99! , # # $$$!il+U\\^^VUFQJIII62~s   A	 	BC#"C#c                 r   |d         }|dz   | j         j        z   }| j                                         dz
  }t          |                                          dk     r|                     |||d           | j                            dt          j	        ||          |          }| xj
        |z  c_
        g dg fS )Nr   r   ru   r,  z+Invalid section title or transition marker.r   rX   )r^   rm   r   ry   r   r  r:   r   r   r   rc   )r2   r  rn   r  r  r  r   r,  s           r"   rg  zLine.underline  s    1:tOd&8&==	#33559x  !!A%%FA>>>m!!;!)Y77 "   	s62~r!   c                     | j                             d|          }| xj        |z  c_        |                     ||           d S )Nz`Possible incomplete section title.
Treating the overline as ordinary text because it's so short.r   )r:   r
  rc   r  )r2   rn   r  r   r   r,  s         r"   r  zLine.short_overline  sT    m  3 !   	sgu-----r!   c                 n    | j                             |           g |d d <   t          j        dd          )NrX   r   )r^   r   r   StateCorrection)r2   rn   r   s      r"   r  zLine.state_correction  s9    ((///
*66:::r!   N)ru   )r   r   r   r5   r  rj  r  r   r  rg  r  r  r    r!   r"   r*  r*  y  s          HJ  $
 
 
< < <| F  . . . .; ; ; ; ; ;r!   r*  c                   \    e Zd ZdZdej        z  ddZdZddZd Z	d Z
d	 Zd
 Zd Zd ZdS )rv  z
    Nested parse handler for quoted (unindented) literal blocks.

    Special-purpose.  Not for inclusion in `state_classes`.
    z(%(nonalphanum7bit)s)r   )initial_quotedr   Fc                 Z    t                               | ||           g | _        d | _        d S r/   )rV   r4   r   initial_linenor]   s      r"   r4   zQuotedLiteralBlock.__init__  s/    $u555"r!   c                     |rt           ||g fS r/   r  rh  s       r"   r  zQuotedLiteralBlock.blank  s     	+NJ**r!   c                    |rk| j                             | j                  \  }}d                    |          }t	          j        ||          }||_        ||_        | xj        |z  c_        nZ| xj        | j	        
                    d| j                                                   z  c_        | j                                          | xj        | j        z  c_        g S )Nr   z#Literal block expected; none found.r   )r^   ra   r  r   r   r   r@   rm   rc   r:   r   r   r   r   )r2   rn   r  r  r   r   s         r"   rj  zQuotedLiteralBlock.eof  s     	/-AA8<8KM MLC99W%%D!/d;;M#&M !(MKK=(KKKKK4=005'7799 1   KK ,,...t}$	r!   c                     |s
J d            | j                             | j                            d| j                                                             | j                                         t          )Nz7QuotedLiteralBlock.indent: context should not be empty!r{  r   r   r}   r:   r   r^   r   r   rg   rh  s       r"   r  zQuotedLiteralBlock.indent$  s     	& 	& % 	& 	& 	&M 9%)%7%G%G%I%I   K K	L 	L 	L 	((***r!   c                 4   |                      d           |j        d         }t          j        t          j        |                    }|                     d|| j        | j        j        f           | j	        
                                | _        |j        g|g fS )z7Match arbitrary quote character on the first line only.r  r   quoted)remove_transitionr  r   r   r4  add_transitionr  rl   r   r^   r   r  )r2   r  rn   r  quoter  s         r"   r  z!QuotedLiteralBlock.initial_quoted-  s    /000Q*RYu--..H$dk4>3JK	M 	M 	M"0@@BB~z2--r!   c                 @    |                     |j                   ||g fS )z,Match consistent quotes on subsequent lines.)r}   r  rh  s       r"   r  zQuotedLiteralBlock.quoted8  s#    u|$$$
B&&r!   c                     |rd| j                             | j                            d| j                                                             | j                                         t          )Nz#Inconsistent literal block quoting.r   r  rh  s       r"   r   zQuotedLiteralBlock.text=  st     	/M  ##$I)-);)K)K)M)M $ O OP P P ,,...r!   Nr   )r   r   r   r5   rX   r3  r  r5  r4   r  rj  r  r  r  r   r    r!   r"   rv  rv    s          #;TY"F H4# # # #
+ + +  $  	. 	. 	.' ' '
    r!   rv  rT   )Cr5   __docformat__r   typesr   r   r  r   r   r   r	   r
   docutils.statemachiner   r   docutils.nodesr   r   r   r   r  r   r   r   r   docutils.utilsr   r   r   r   r   r   r   r%   r'   r)   	Exceptionr+   r-   r7   rR   rV   r   rF   r  r  r  r  rX   r7  rE  r  rM  r  r&  r7  r<  r  rR  r#  r  ry  r  rO  r*  rv  rZ   r    r!   r"   <module>r     sP  
` `D # 
			 * * * * * * * * / / / / / / / / / / 0 0 0 0 0 0 0 0 9 9 9 9 9 9 9 9 A A A A A A > > > > > > > >     J J J J J J J J J J J J 4 4 4 4 4 4 4 4 ? ? ? ? ? ? ? ? ? ? 3 3 3 3 3 3 # " " " ") " " " 2 2 2 2 2) 2 2 2 9 9 9 9 9 9 9 9 ) ) ) ) )" ) ) ) % % % % %Y % % %* * * * * * * *$% $% $% $% $%n $% $% $%N       4i2 i2 i2 i2 i2w i2 i2 i2X   .W	+ W	+ W	+ W	+ W	+ W	+ W	+ W	+t "%S!     "%S!    & & &Q* Q* Q* Q* Q*8 Q* Q* Q*h*+' +' +' +' +'$ +' +' +'\) ) ) ) )d ) ) )X" " " " " " " "0 0 0 0 0_ 0 0 0" " " " "_ " " "0	" 	" 	" 	" 	" 	" 	" 	"" " " " " " " "* * * * */; * * *"    y   (" " " " " " " " * * * * * * * **    d   4# # # # #8 # # #D    d   .( ( ( ( ( ( ( ("; ; ; ; ;? ; ; ;DH H H H H H H HV z>>9Y(8(DT?KN E Dr!   