
    ዕh܊                    
   d Z dZdZdj                   eee            ZdZddlZddl	Z	ddl
Z
ddlZddlZddlmZmZ ddlmZmZ ddlZdd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z# ddlm$Z$ ddl%m&Z&m'Z' ddl(m)Z) ed   Z*e+eef   Z,e#e-e   e,f   Z.ee/ej`                  e#eeejb                  gef   f   f      Z2dZ3 e
jh                  d      Z5dZ6 e)d      Z7dedefdZ8dD  ci c]  } |  e8|        c} Z9 ejt                  d      Z; G d de<      Z=dde6ddddddf	dedede>d e?d!ee*   d"ee.   d#ee2   d$ee   d%ee   d&e>dd'fd(Z@de6dddddddf	d)ede>d e?d!ee*   d"ee.   d#ee2   d$ee   d%ee   d&e>d*e>dd'fd+ZA G d, d-e&      ZBd.eBfd/ZC G d0 d1      ZD G d2 d3eD      ZE G d4 d5e      ZF G d6 d7eF      ZG G d8 d9e"d:      ZH G d; d<eF      ZI G d= d>eF      ZJ G d? d@eF      ZK G dA dBe"d:      ZL G dC dDeF      ZM G dE dFeG      ZN G dG dHeF      ZO G dI dJeF      ZP G dK dLeF      ZQ G dM dNeF      ZR G dO dPeHd:      ZS G dQ dReI      ZT G dS dTeO      ZU G dU dVeG      ZV G dW dXeF      ZW G dY dZeF      ZX G d[ d\eF      ZY G d] d^eF      ZZ G d_ d`eF      Z[ G da dbeF      Z\ G dc ddeF      Z] G de dfe"d:      Z^ G dg dheF      Z_ G di djeF      Z`eJj                          eKj                          eMj                          eNj                          eOj                          ePj                          eQj                          eRj                          eTj                          eVj                          eUj                          eWj                          eXj                          eYj                          eZj                          e[j                          e\j                          e]j                          e_j                          e`j                          dke#e-e/e?eef      df   dee   fdlZb G dm d'e      Zc ejt                  dn      Zd ejt                  do      ZedpedefdqZfdredefdsZgdedej`                  fdtZhddue-e   dve?dwe>de-e   fdxZidd)edve?dwe>defdyZj G dz d{      Zkd e?dej`                  fd|Zl ekel      Zld e?dej`                  fd}Zm ekem      Zmdd~ede>defdZndedefdZo	 	 dd~ed!e#e*e>df   dee   fdZp G d dej                        Zrd ZsddZteudk(  r# ej                   etej                               yyc c} w )a  A fast and complete Python implementation of Markdown.

[from http://daringfireball.net/projects/markdown/]
> Markdown is a text-to-HTML filter; it translates an easy-to-read /
> easy-to-write structured text format into HTML.  Markdown's text
> format is most similar to that of plain text email, and supports
> features such as headers, *emphasis*, code blocks, blockquotes, and
> links.
>
> Markdown's syntax is designed not as a generic markup language, but
> specifically to serve as a front-end to (X)HTML. You can use span-level
> HTML tags anywhere in a Markdown document, and you can use block level
> HTML tags (like <div> and <table> as well).

Module usage:

    >>> import markdown2
    >>> markdown2.markdown("*boo!*")  # or use `html = markdown_path(PATH)`
    u'<p><em>boo!</em></p>\n'

    >>> markdowner = Markdown()
    >>> markdowner.convert("*boo!*")
    u'<p><em>boo!</em></p>\n'
    >>> markdowner.convert("**boom!**")
    u'<p><strong>boom!</strong></p>\n'

This implementation of Markdown implements the full "core" syntax plus a
number of extras (e.g., code syntax coloring, footnotes) as described on
<https://github.com/trentm/python-markdown2/wiki/Extras>.
ao  A fast and complete Python implementation of Markdown, a
text-to-HTML conversion tool for web writers.

Supported extra syntax options (see -x|--extras option below and
see <https://github.com/trentm/python-markdown2/wiki/Extras> for details):

* admonitions: Enable parsing of RST admonitions.
* breaks: Control where hard breaks are inserted in the markdown.
  Options include:
  - on_newline: Replace single new line characters with <br> when True
  - on_backslash: Replace backslashes at the end of a line with <br>
* break-on-newline: Alias for the on_newline option in the breaks extra.
* code-friendly: Disable _ and __ for em and strong.
* cuddled-lists: Allow lists to be cuddled to the preceding paragraph.
* fenced-code-blocks: Allows a code block to not have to be indented
  by fencing it with '```' on a line before and after. Based on
  <http://github.github.com/github-flavored-markdown/> with support for
  syntax highlighting.
* footnotes: Support footnotes as in use on daringfireball.net and
  implemented in other Markdown processors (tho not in Markdown.pl v1.0.1).
* header-ids: Adds "id" attributes to headers. The id value is a slug of
  the header text.
* highlightjs-lang: Allows specifying the language which used for syntax
  highlighting when using fenced-code-blocks and highlightjs.
* html-classes: Takes a dict mapping html tag names (lowercase) to a
  string to use for a "class" tag attribute. Currently only supports "img",
  "table", "thead", "pre", "code", "ul" and "ol" tags. Add an issue if you require
  this for other tags.
* link-patterns: Auto-link given regex patterns in text (e.g. bug number
  references, revision number references).
* link-shortrefs: allow shortcut reference links, not followed by `[]` or
  a link label.
* markdown-file-links: Replace links to `.md` files with `.html` links
* markdown-in-html: Allow the use of `markdown="1"` in a block HTML tag to
  have markdown processing be done on its contents. Similar to
  <http://michelf.com/projects/php-markdown/extra/#markdown-attr> but with
  some limitations.
* metadata: Extract metadata from a leading '---'-fenced block.
  See <https://github.com/trentm/python-markdown2/issues/77> for details.
* middle-word-em: Allows or disallows emphasis syntax in the middle of words,
  defaulting to allow. Disabling this means that `this_text_here` will not be
  converted to `this<em>text</em>here`.
* nofollow: Add `rel="nofollow"` to add `<a>` tags with an href. See
  <http://en.wikipedia.org/wiki/Nofollow>.
* numbering: Support of generic counters.  Non standard extension to
  allow sequential numbering of figures, tables, equations, exhibits etc.
* pyshell: Treats unindented Python interactive shell sessions as <code>
  blocks.
* smarty-pants: Replaces ' and " with curly quotation marks or curly
  apostrophes.  Replaces --, ---, ..., and . . . with en dashes, em dashes,
  and ellipses.
* spoiler: A special kind of blockquote commonly hidden behind a
  click on SO. Syntax per <http://meta.stackexchange.com/a/72878>.
* strike: text inside of double tilde is ~~strikethrough~~
* tag-friendly: Requires atx style headers to have a space between the # and
  the header text. Useful for applications that require twitter style tags to
  pass through the parser.
* tables: Tables using the same format as GFM
  <https://help.github.com/articles/github-flavored-markdown#tables> and
  PHP-Markdown Extra <https://michelf.ca/projects/php-markdown/extra/#table>.
* toc: The returned HTML string gets a new "toc_html" attribute which is
  a Table of Contents for the document. (experimental)
* use-file-vars: Look for an Emacs-style markdown-extras file variable to turn
  on Extras.
* wiki-tables: Google Code Wiki-style tables. See
  <http://code.google.com/p/support/wiki/WikiSyntax#Tables>.
* wavedrom: Support for generating Wavedrom digital timing diagrams
* xml: Passes one-liner processing instructions and namespaced XML tags.
)         .z
Trent Mick    N)defaultdictOrderedDict)ABCabstractmethod)Iterable)sha256)random)
AnyCallableDictListLiteralOptionalTupleType	TypedDictUnion)
Collection)IntEnumauto)urandomreplaceescapeFmarkdownr      sreturnc                 l    dt        t        | j                  d      z         j                         dd  z   S )Nzmd5-utf-8    )r   SECRET_SALTencode	hexdigest)r!   s    U/var/www/html/syllabuild_admin/backend/venv/lib/python3.12/site-packages/markdown2.py
_hash_textr*      s0    F;')::;EEGLLL    z\`*_{}[]()>#+-.!z!&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)c                       e Zd Zy)MarkdownErrorN)__name__
__module____qualname__ r+   r)   r-   r-      s    r+   r-   r$   pathencoding	html4tags	tab_width	safe_modeextraslink_patternsfootnote_titlefootnote_return_symboluse_file_varsUnicodeWithAttrsc
           
          t        j                  | d|      }
|
j                         }|
j                          t	        ||||||||	      j                  |      S )Nr)r4   r5   r6   r7   r8   r9   r:   r;   )codecsopenreadcloseMarkdownconvert)r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   fptexts               r)   markdown_pathrG      sW     
T3	)B779DHHJi9'"/#1+A"/1
 29?r+   rF   clic
                 H    t        |||||||||		      j                  |       S )N)	r4   r5   r6   r7   r8   r9   r:   r;   rH   )rC   rD   )
rF   r4   r5   r6   r7   r8   r9   r:   r;   rH   s
             r)   r   r      s5     i9'"/#1+A"/S:
 ;B'$-Hr+   c                       e Z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 e       Z e       Z e       Zy)StageN)r.   r/   r0   r   
PREPROCESS	HASH_HTML	LINK_DEFSBLOCK_GAMUTHEADERSLISTSCODE_BLOCKSBLOCK_QUOTES
PARAGRAPHS
SPAN_GAMUT
CODE_SPANSESCAPE_SPECIALLINKSITALIC_AND_BOLDPOSTPROCESSUNHASH_HTMLr1   r+   r)   rK   rK      sr    JII&KfGFE&K6LJJJVNFEfO&K&Kr+   rK   stagec                       fd}|S )zd
    Decorator that handles executing relevant `Extra`s before and after this `Stage` executes.
    c                 H     t        j                         d fd       }|S )Nc                 n   | _         dz
  | _        t        j                  v rpt        j                     d   D ]W  }|j                  | j
                  vr| j
                  |j                     }|j                  |      sG|j                  |      }Y | _         | |g|i |}dz   | _        t        j                  v rpt        j                     d   D ]W  }|j                  | j
                  vr| j
                  |j                     }|j                  |      sG|j                  |      }Y |S )Ng      ?r      )r\   orderExtra_exec_ordernameextra_classestestrun)mdrF   argskwargsklassextrafuncr\   s         r)   innerz*mark_stage.<locals>.wrapper.<locals>.inner   s$   BHs{BH)))"..u5a8 /Ezz)9)99 ,,UZZ8Ezz$'$yy/ BHD24262Ds{BH)))"..u5a8 /Ezz)9)99 ,,UZZ8Ezz$'$yy/ Kr+   )rh   rC   )	functoolswraps)rm   rn   r\   s   ` r)   wrapperzmark_stage.<locals>.wrapper   s%    			 
	6 r+   r1   )r\   rq   s   ` r)   
mark_stagerr      s    > Nr+   c                   4   e Zd ZU eed<   eedf   ed<   eeef   ed<   eeef   ed<   eeef   ed<   eeef   ed<   dZeed	<   d
Zeed<   e	e
   ed<   eeeeef      ed<   dZeed<   	 eed<   	  ej$                  dej&                        Zdedddddddf	dedede	e
   de	e   de	e   de	e   de	e   dedefdZd Zd Z ej$                  dej8                  ej:                  z        Zded d!fd"Z e ejB                        ded efd#       Z" e ejF                        ded efd$       Z$ ej$                  d%jK                  d&d'      ejL                  ej:                  z        Z' ej$                  d(ejL                        Z( ej$                  d)ejL                        Z) ej$                  d*ejL                        Z* ej$                  d+ejL                        Z+ded efd,Z, ej$                  d-ejZ                        Z. ej$                  d.ej8                  ejL                  z  ej^                  z  ej:                  z        Z0d/ejb                  d efd0Z2ded eeef   fd1Z3d2ed efd3Z4ded efd4Z5d5Z6d6Z7e7e6z  Z7 ej$                  d7e7z  ejp                  ej&                  z        Z9d8Z:e:e6z  Z:d9Z; ej$                  d:e:z  ejp                  ej&                  z        Z< ej$                  d;      Z=	 dd/e>ejb                  ef   d<ed efd=Z? e ej                        dded<ed efd>       ZA	 dded?ed@eBegef   dAed ef
dBZCdCeded efdDZD e ej                        ded efdE       ZFd/ejb                  d efdFZGd/ejb                  d efdGZHded efdHZI ej$                  dIej&                        ZJ e ej                        ded efdJ       ZL e ej                        ded efdK       ZN ej$                  dLejp                        ZO e ej                        ded efdM       ZQdN ZR e ej                        ded efdO       ZSdded efdPZTdQed efdRZU ej$                  dSejp                  ej                  z        ZW ej$                  dTejp                  ej                  z        ZX ej$                  dU      ZY ej$                  dV      ZZdedWed efdXZ[dedWedYedZed ef
d[Z\ ej$                  d\ejp                        Z]d]ed efd^Z^d_Z_e`d`        Za e ej                        ded efda       Zc	 ddedbedce	e   d efddZdded efdeZedfedgedhed dfdiZfdjZg ej$                  egdkz  ejp                  ej&                  z        Zh ej$                  egdlz  ejp                  ej&                  z        Zid/ejb                  d efdmZj ej$                  dnejp                  ej&                  z        Zkd/ejb                  d efdoZl e ej                        ded efdp       ZndqZodreoz  Zpdseoz  ZqdtZrd/ejb                  d efduZs e ej                        ded efdv       Zu ej$                  dwjK                  epep      ej&                  ejp                  z  ej                  z        Zv ej$                  dxej&                  ejp                  z  ej                  z        ZwdyZxd/ejb                  d efdzZydZzd/ejb                  d efd{Z{d|ed efd}Z|d~efdZ}ded efdZ~d/ejb                  d efdZded efdZ e ej                        ded efd       Z ej$                  dejp                  ej                  z        Zd/ejb                  d efdZ e ej
                        ded efd       Zded efdZ ej$                  dej                        Z ej$                  dej                        Z e ej                        ded efd       ZdZ ej$                  edz  ej&                  ejp                  z        Z ej$                  edz  ej&                  ejp                  z        Z ej$                  dej&                        Z ej$                  dej&                        Z ej$                  dej&                        Z ej$                  dej                        Zd/ejb                  d efdZd/ejb                  d efdZ e ej*                        ded efd       Z e ej.                        ded efd       Zded efdZ ej$                  dej4                        Z ej$                  dej4                        Zded efdZ ej$                  d      Zded efdZded efdZ ej$                  dej4                        Zd/ejb                  d efdZ ej$                  dej4                  ejp                  z  ejF                  z        Zd/ejb                  d efdZded efdZded efdZded efdZded efdZded efdZe	 	 ddede	e   de	e   d eeef   fd       Ze	 	 ddedededed ef
d       Zed/ejb                  ded efd       Zy)rC   r7   rb   re   urlstitleshtml_blocks
html_spansz
{(#HTML#)}html_removed_textz[HTML_REMOVED]html_removed_text_compatr6   _tocr   r\   ra   z^[ \t]+$FNr4   r5   r8   r9   r:   r;   rH   c
                    |rd| _         nd| _         || _        |dz  | _        |du rd| _        n|| _        t	        | dd       i | _        n:t        | j
                  t              s | j
                  D 
ci c]  }
|
d  c}
| _        |r;t        |t              s|D 
ci c]  }
|
d  }}
| j
                  j                  |       t        | j
                  t              sJ d| j
                  v rXd| j
                  vrd | j
                  d<   | j
                  d   d	| _	        n$| j
                  d   j                  d
d	      | _	        d| j
                  v r=t        | j
                  d   t              s d| j
                  d   dd| j
                  d<   d| j
                  v r.| j
                  j                  di        d| j
                  d   d<   d| j
                  v r/|xs | j
                  d   }|t        d      || j
                  d<   | j
                  j                         | _        || _        || _        || _        || _        t'        j(                  d|z  t&        j*                        | _        |	| _        t0        j                         | _        i | _        d| j
                  v r1t7        d      | j2                  d<   t7        d      | j2                  d<   y y c c}
w c c}
w )N>z /> Tr   r7   toc
header-ids   depthF)mixedprefixreset-countzbreak-on-newlinebreaks
on_newlinelink-patternszQIf the 'link-patterns' extra is used, an argument for 'link_patterns' is requiredz^(\t|[ ]{1,%d})smarty-pants"')empty_element_suffixr5   tabr6   getattrr7   
isinstancedictupdate
_toc_depthget
setdefaultr-   copy_instance_extrasr8   r9   r:   r;   recompileM_outdent_rerH   g_escape_table_escape_table_code_tabler*   )selfr4   r5   r6   r7   r8   r9   r:   r;   rH   es              r)   __init__zMarkdown.__init__3  s    (+D%(-D%"s?
 &DN&DN 44(0DKDKK. -1KK8q1d78DKfd++12a!T'22KKv&$++t,,,DKK4;;.,0L){{5!)"#"&++e"4"8"8!"D4;;&dkk,7>""kk,7#'-L) ,KK""8R026DKK!,/dkk))IT[[-IM$ $$wxx+8DKK( $ 0 0 2*,&<#*::&89&DbddK+002T[[(&0oDs#&0oDs# )c 9 3s   3
K
Kc                     i | _         i | _        i | _        i | _        d| _        | j
                  j                         | _        | j                          g | _	        y Nr   )
rt   ru   rv   rw   
list_levelr   r   r7   _setup_extrasrz   r   s    r)   resetzMarkdown.reset  sO    	++002	r+   c                    d| j                   v r&t               | _        g | _        t	        d      | _        d| j                   v r?t        | d      r| j                   d   j                  dd      rt        t              | _
        d| j                   v ri | _        i | _        t        j                  j                         D ]D  \  }}|| j                   vr || | j                   j                  |i             | j                  |<   F y )N	footnotesz<<footnote>>r   _count_from_header_idr   Fmetadata)r7   r   r   footnote_idsr*   _footnote_markerhasattrr   r   intr   r   re   rb   	_registryitems)r   rd   rk   s      r)   r   zMarkdown._setup_extras  s    $++% )]DN "D$.~$>D!4;;&4!89T[[=V=Z=Z[hjo=p-8-=*$,.DM ??002 	PKD%4;;&',TDKKOOD"4M'ODt$	Pr+   a  
        <(a)
        (
            [^>]*
            href=   # href is required
            ['"]?   # HTML5 attribute values do not have to be quoted
            [^#'"]  # We don't want to match href values that start with # (like footnotes)
        )
        rF   r"   r<   c                 j     j                          t        t              st        d       j                  r j                  j                   j                         j                        }d|v rgt        j                  d      }|j                  |d         D ];  }d|v r"|j                  dd      \  }}	 t        |      }n|d}}| j                  |<   =  j                          j                  dd      j                  d	d      d
z   j!                         j"                  j                  d      d j                  v r j%                         j'                         j(                  r j+                         j-                  d      d j                  v r j/                         j1                         j3                        d j                  v r: fd}t        j
                  d j4                  z  |       j7                         j9                         j;                         j=                         j(                  r&j                   j>                   j@                        d j                  v }d j                  v }	|r|	r jB                  j                  d      n=|r jB                  j                  d      n|	r jB                  j                  d      d j                  v r jD                  r j                  d   jG                  d      r!fd}
 jD                  jI                  |
       tK         jD                         _&         jN                  s. j                  d   0 j                  d   jG                  dd      r jL                   d dz  tQ              }d j                  v r jD                  r jL                  |_)        d j                  v r jT                  |_*        |S # t        $ r Y ew xY w)zConvert the given text.r$   zmarkdown-extrasz[ ,]+=r`   N



 r   Trawr   c                     | j                  d      }j                  j                  |       t        t	        j                              S Nr`   )groupr   appendstrlen)match	normed_idr   s     r)   footnote_subz&Markdown.convert.<locals>.footnote_sub  s:    !KKN	!!((33t00122r+   z%s-(.*?)(?=</a></sup>)ztarget-blank-linksnofollowz-<\1 rel="nofollow noopener" target="_blank"\2z$<\1 rel="noopener" target="_blank"\2z<\1 rel="nofollow"\2r~   r   r   c           	          t        j                  d| d   | d   t        j                  | d         fz  t         j                        }|r|j	                         S dS )z+Sort the TOC by order of appearance in textz#^<(h%d).*?id=(["\'])%s\2.*>%s</\1>$r   r`   r   )r   searchr   r   start)entryr   rF   s     r)   toc_sortz"Markdown.convert.<locals>.toc_sort!  sZ    II>%(ERSHVXV_V_`efg`hViAjjbddE
 -25;;=8q8r+   keyprependF)+r   r   r   r;   _emacs_oneliner_vars_patsub_emacs_vars_oneliner_sub_get_emacs_varsr   r   splitr   
ValueErrorr7   r   r   _detab_ws_only_line_re_extract_metadata
preprocessr6   _hash_html_spans_hash_html_blocks_strip_footnote_definitions_strip_link_definitions_run_block_gamutr   _add_footnotespostprocess_unescape_special_chars_unhash_html_spansrx   ry   _a_nofollow_or_blank_linksrz   r   sortcalculate_toc_html	_toc_htmlrH   r<   toc_htmlr   )r   rF   
emacs_varssplitterr   enameeargr   do_target_blank_linksdo_nofollow_linksr   rvs   ``          r)   rD   zMarkdown.convert  s    	

$$tW%D0044T5R5RTXYD--d3J J.::g.!
3D(EF 	.Aax&'ggc1ot!#&t9D '(t)-DKK&	.   ||FD)||D$' 	 {{4  $$((T2 $))$/Dt$>>((.D %%d%5 $++% 33D9D++D1$$T*$++%3
 663d6K6KK\[_`D&&t,D%++D1&&t,>><< 6 68U8UVD 4 C&$++5 %622667gimnD"22667^`deD22667NPTUDDKKDII{{<(,,W59 		8,/		:DN xxDKK.:t{{5?Q?U?UV_af?g..)D62 d#DKKDII..BK$--BK	O  * ! !s   <P%%	P21P2c                     |S )zA hook for subclasses to do some postprocessing of the html, if
        desired. This is called before unescaping of special chars and
        unhashing of raw HTML spans.
        r1   r   rF   s     r)   r   zMarkdown.postprocess=  	     r+   c                     |S )zA hook for subclasses to do some preprocessing of the Markdown, if
        desired. This is called after basic formatting of the text, but prior
        to any extras, safe mode, etc. processing.
        r1   r   s     r)   r   zMarkdown.preprocessE  r   r+   a  
        ^{0}(  # optional opening fence
            (?:
                {1}:(?:\n+[ \t]+.*)+  # indented lists
            )|(?:
                (?:{1}:\s+>(?:\n\s+.*)+?)  # multiline long descriptions
                (?=\n{1}:\s*.*\n|\s*\Z)  # match up until the start of the next key:value definition or the end of the input text
            )|(?:
                {1}:(?! >).*\n?  # simple key:value pair, leading spaces allowed
            )
        ){0}  # optional closing fence
        z(?:---[\ \t]*\n)?z[\S \t]*\w[\S \t]*\s*zK^-(?:[ \t]*([^\n]*)(?:[ \t]*[:-][ \t]*(\S+))?)(?:\n((?:[ \t]+[^\n]+\n?)+))?z9^([^:\n]+)[ \t]*:[ \t]*([^\n]*)(?:((?:\n[ \t]+[^\n]+)+))?z^---[\ \t]*\nz^
c                 >   	
 |j                  d      r-t        j                   j                  |d      }|d   }|d   }n,t        j                   j                  |d      }|d   }|d   }t        j
                   j                  |      }|s|S dt        dt        t        t           t        t        t        f   f   f	 
fd	|D ]  }|j                  d	d      \  }

d d
 dk(  r8t        
d
d        j                          j                  |j                         <   X
dk(  rd j                  |j                         <   {
d   dk(  r$ 	
       j                  |j                         <   
j                          j                  |j                         <    |S )N---r   )maxsplitr`   r   valuer"   c                 `   | j                         }| j                  d t        |       t        |      z
   d      dd  }|j                  d      rg }t	        j
                  j                  |      D ]  }|d   r-|d   s(|d   s#|j                  |d   j                                5|d   dk(  r-|d   s(|d   r#|j                  |d   j                                j|d   r;|d   r6|j                  |d   j                         |d   j                         i       |d   s%|d   s |d   r|j                   |d                Ԍ |S t	        j
                  j                  |      D ci c]7  }|d   j                         |d   r|d   j                         n
 |d         9 c}S c c}w )Nr   r`   -r   r   r|   )
lstripr   r   
startswithr   findall_key_val_list_patr   strip_key_val_dict_pat)r   vsr>   r   parse_structured_valuer   vs       r)   r   z:Markdown._extract_metadata.<locals>.parse_structured_value  s   Bq!73u:B#78$?CB }}S!!  ZZ(>(>C EQxaqq!12qSqeAhq!12qeAh%(.."2E!HNN4D!EF"1XeAh58!7a!AB   "$D,B,BB!G  !HNN$ 8 a(3E!H=>  s   ,<F+:   z >
r   r   )r   r   r   _meta_data_fence_pattern_meta_data_newliner   _meta_data_patternr   r   listr   r   _dedentr   r   )r   rF   fence_splitsmetadata_contenttailmetadata_splitr   itemkr   r   s   `        @@r)   r   zMarkdown._extract_metadataq  st   ??5!88D$A$A4RSTL+A?DXXd&=&=taPN-a0!!$D ::d&=&=?OPK"	# "	%S	4S>8Q2R "	H  	5D::c1%DAq !u+21QR5>+?+?+Aaggi( d+-aggi( 1+A!+Daggi( ,-779aggi(%	5( r+   zD((?:<!--)?\s*-\*-)\s*(?:(\S[^\r\n]*?)([\r\n]\s*)?)?(-\*-\s*(?:-->)?)z^
        (?P<prefix>(?:[^\r\n|\n|\r])*?)
        [\ \t]*Local\ Variables:[\ \t]*
        (?P<suffix>.*?)(?:\r\n|\n|\r)
        (?P<content>.*?\1End:)
        r   c                    |j                  d      j                         dk(  r|j                  d      j                         dk(  rt        j                  d|j                  d            d   }t        j                  d|j                  d            d   }dj	                  |d|j                  d      j                         d|      S |j                         \  }}|j                  || S )	Nr`   -*-r   z^\s*r   z\s*$z{}<!-- {} {} {} -->{}r   )r   r   r   r   formatspanstring)r   r   lead_wstail_wsr   ends         r)   r   z!Markdown._emacs_vars_oneliner_sub  s    ;;q>!U*u{{1~/C/C/E/Njj%++a.9!<Gjj%++a.9!<G*11'5%++a.BVBVBXZ_ahiiZZ\
s||E3''r+   c                 $   i }t        dd      }|d| }d|v r| j                  j                  |      }|r|j                  d      }d|vsJ |j	                  d      D cg c]"  }|j                         r|j                         $ }}t        |      dk(  rd|d	   vr|d	   j                         |d
<   nL|D ]G  }		 |	j                         j	                  dd      \  }
}|j                         ||
j                         <   I || d }d|v r| j                  j                  |      }|r|j                  d      }|j                  d      }|j                  d      j                  d      }t        |      D ]y  \  }}|j                  |      s t        j                  d|d|d       i c S |t        |      dz
  k7  sI|j                  |      r[t        j                  d|d|d       i c S  d}|dd D ]  }|r|t        |      d }|r|dt        |        }|j                         }|r:|}
|j                  d      r|dd j!                         }nd}||
xx   d|z   z  cc<   p	 |j	                  dd      \  }
}|j                         }|j                  d      r|dd j!                         }|
}nd}|||
<    t#        |j%                               D ]b  \  }}t        |      dkD  s|j                  d      r|j                  d      s$|j                  d      sI|j                  d      s[|dd ||<   d |S c c}w # t        $ r t        j                  d|	       Y w xY w# t        $ r t        j                  d|z         Y w xY w)a0  Return a dictionary of emacs-style local variables.

        Parsing is done loosely according to this spec (and according to
        some in-practice deviations from this):
        http://www.gnu.org/software/emacs/manual/html_node/emacs/Specifying-File-Variables.html#Specifying-File-Variables
        r      Nr  r   ;r`   r   r   modez-emacs variables error: malformed -*- line: %rzLocal Variablesr   suffixcontentFzemacs variables error: line 'z' does not use proper prefix 'r   z' does not use proper suffix '\r}   zClocal variables error: missing colon in local variables entry: '%s'r   )powr   r   r   r   r   r   r   logdebuglower_emacs_local_vars_pat
splitlines	enumerater   endswithrstripr  r   )r   rF   r   SIZEheadr   emacs_vars_strr!   emacs_var_strsemacs_var_strvariabler   r  r   r  linesilinecontinued_forvarvals                        r)   r   zMarkdown._get_emacs_vars  s    
1bz ET{D=1188>E!&Q>1115C5I5I#5N "0%&WWY #$'') "0 "0~&!+>!;L0L
 *8):)@)@)BJv&)7 	E%.;.A.A.C.I.I#q.QOHe 8={{}
8>>#34	E TEF|$..55d;EX.X.I.99%@  )/ "GAt??62		%)6#3 4  "	 CJqL(v1F		%)6#3 4  "	" !%!#2J 5D#CKL1#Mc&k\2::<D$#0==.#'9#3#3#5D,0M"8,d
:,%.2jja.@OHe !& >>$/$)#2J$5$5$7E,4M,0M/4
8,95> Z--/0 	,HC3x!|!4c9J..%#,,s*;"%a)
3	,
 i"0  * %II '12?A$%h  * %II 'GIM'N O$%s*   'L?:#M*M*M'&M'*!NNr+  c                     d|vr|S |j                  dd      \  }}|d| j                  t        |      | j                  z  z
  z  z  }||z   }| j                  |      S )zRRecusively convert tabs to spaces in a single line.

        Called from _detab().	r`   r}   )r   r5   r   _detab_line)r   r+  chunk1chunk2outputs        r)   r1  zMarkdown._detab_line;  sd     tKD!,3$..3v;+GGHI&''r+   c                     d|vr|S g }|j                         D ]"  }|j                  | j                  |             $ dj                  |      S )a  Iterate text line by line and convert tabs to spaces.

            >>> m = Markdown()
            >>> m._detab("\tfoo")
            '    foo'
            >>> m._detab("  \tfoo")
            '    foo'
            >>> m._detab("\t  foo")
            '      foo'
            >>> m._detab("  foo")
            '  foo'
            >>> m._detab("  foo\n\tbar\tblam")
            '  foo\n    bar blam'
        r0  r   )r  r   r1  join)r   rF   r4  r+  s       r)   r   zMarkdown._detabF  sR     tKOO% 	2DMM$**401	2yy  r+   zT|address|article|aside|canvas|figcaption|figure|footer|header|main|nav|section|videozblockquote|body|dd|del|div|dl|dt|fieldset|form|h[1-6]|head|hr|html|iframe|ins|li|math|noscript|ol|p|pre|script|style|table|tfoot|ula  
        (                       # save in \1
            ^                   # start of line  (with re.M)
            <(%s)               # start tag = \2
            \b                  # word break
            (.*\n)*?            # any number of lines, minimally matching
            </\2>               # the matching end tag
            [ \t]*              # trailing spaces/tabs
            (?=\n+|\Z)          # followed by a newline or end of document
        )
        zTblockquote|div|dl|fieldset|form|h[1-6]|iframe|math|noscript|ol|p|pre|script|table|ulza|abbr|acronym|b|bdo|big|br|button|cite|code|dfn|em|i|img|input|kbd|label|map|object|output|q|samp|script|select|small|span|strong|sub|sup|textarea|time|tt|vara  
        (                       # save in \1
            ^                   # start of line  (with re.M)
            <(%s)               # start tag = \2
            \b                  # word break
            (.*\n)*?            # any number of lines, minimally matching
            .*</\2>             # the matching end tag
            [ \t]*              # trailing spaces/tabs
            (?=\n+|\Z)          # followed by a newline or end of document
        )
        z\s+markdown=("1"|'1')r   c                    t        |t              r|}d }n#|j                  d      }	 |j                  d      }|s+t	        j
                  d|      }|J |j                  d      }|r| j                  r| j                  |      }nd| j                  v rDd|v r?|j                  dd      d   }| j                  j                  |      }|rx|j                  d      }t        t        d t	        j                  d|z  |d                     |dd  z   }|d d	 t        t        d t	        j                  d
|z  |d	                     z   }|d   }dj                  |dd	       }|d	   }	|d |j                          ||j!                         d  z   }t#        |      }
|| j$                  |
<   t#        |	      }|	| j$                  |<   dj                  d|
d|d|dg      S | j                  j'                  di       j'                  d      rA| j(                  j                  |      r&| j(                  j+                  | j,                  |      }t#        |      }|| j$                  |<   d|z   dz   S # t        $ r d }Y =w xY w)Nr`   r   z.*?<(\S).*?\s*>markdown-in-htmlz	markdown=r   r   z(.*?<%s.*markdown=.*?>)r  z(\s*?</%s>.*?$)r   r   r   r   )r   r   r   
IndexErrorr   r   r6   _sanitize_htmlr7   r   _html_markdown_attr_rer   r  filterr6  r   r  r*   rv   r   	_h_tag_rer   
_h_tag_sub)r   r   r   htmltagm
first_liner)  middle	last_linef_keyl_keyr   s                r)   _hash_html_block_subzMarkdown._hash_html_block_sub  si   
 eS!DC;;q>Dkk!n +T2A= =''!*C4>>&&t,D4;;.;$3FD!,Q/J++22:>A

4(VD2884NQT4TV[\]V^+_abejklkmenncr
T&rxx@RUX@XZ_`bZc7d*e%ff"1X
52;/!"I	'
3j6JJ
":.*4  '"9-*3  'wwFF6 # $ $ [[__\2.227;@T@TUY@Z>>%%doot<D $|f$$M  s   I( (I76I7c                 "    d|vr|S t         j                  |       j                  | j                        } j                  j                  |      } j                  | j                   fd      }d|v r't         j                        }|j                  |      }d|v rd}	 	 |j                  d|      }	 |j                  d|      dz   }|}|rYt         j                  d	z
        D ]  }||d	z
     d
k7  r n|d	z  }|dk(  s n |dk(  rn|d	k(  r|d   dk(  rd}n||dz
  | dk(  rnn|t        |      k  r||   dvrn|d	z  }|t        |      k  r|||dz    dvr||| }|r j                  r j                  |      }t        |      }	| j                   |	<   |d| dz   |	z   dz   ||d z   }d j"                  v r't%         j                        }
|
j                  |      }|S # t        $ r Y Bw xY w# t        $ r Y Qw xY w)a  Hashify HTML blocks

        We only want to do this for block-level HTML tags, such as headers,
        lists, and tables. That's because we still want to wrap <p>s around
        "paragraphs" that are wrapped in non-block-level tags, such as anchors,
        phrase emphasis, and spans. The list of tags we're looking for is
        hard-coded.

        @param raw {boolean} indicates if these are raw HTML blocks in
            the original source. It makes a difference in "safe" mode.
        <r   c                 2     j                  |             S N)_run_span_gamut)thash_html_block_subr   s    r)   <lambda>z,Markdown._hash_html_blocks.<locals>.<lambda>  s    )$*>*>q*AB r+   <hrz<!--r   -->r   r`   r}   r   r   r    	)r   r   r   Nxml)_curryrG  _strict_tag_block_sub_block_tags_a_liberal_tag_block_rer   
_span_tags_hr_tag_re_from_tab_widthr5   indexr   ranger   r6   r:  r*   rv   r7   _xml_oneliner_re_from_tab_width)r   rF   r   
_hr_tag_rer   	start_idxend_idxr*  r?  r   _xml_oneliner_rerN  s   `          @r)   r   zMarkdown._hash_html_blocks  s    d?K %T%>%>CH ))$0B0BDWX ))--.A4H ))$//B
 D=24>>BJ>>"5t<D T>E $

65 9I"jj	:Q>G
   "4>>A#56 "	A.#5!!Q	$>!" !A~"aDGtO$%	ik)4> D	)G}E1qLG D	)
 	*2DD Ig.4>>..t4D &(,  %JY'&036?$wx.Pe h DKK  ?t~~N#''(;TBDw "  " s$   .G3 H 3	G?>G?	HHhtml_tags_recallbackallow_indentc                    d}|}d}d}|j                  d      D ]  }	t        j                  dj                  |rdnd|      |	      }
||	z  }|
rc|	j	                  d|
j                  d      z        r|dz  }n:| j                  |
j                  d      |	      rd	}
n|dz  }|
j                  d      }|dk(  s|
r ||j                  d
            }|}||z  }d} ||z  }|S )a  
        Finds and substitutes HTML blocks within blocks of text

        Args:
            text: the text to search
            html_tags_re: a regex pattern of HTML block tags to match against.
                For example, `Markdown._block_tags_a`
            callback: callback function that receives the found HTML text block and returns a new str
            allow_indent: allow matching HTML blocks that are not completely outdented
        r   r   Tz0^(\s{{0,{}}})(?:</code>(?=</pre>))?(</?({})\b>?)0z%s</r`   r   Nr   )r  r   r   r  r   r   _tag_is_closedr"  )r   rF   ra  rb  rc  	tag_countcurrent_tagblockresultchunk	is_markups              r)   rU  zMarkdown._strict_tag_block_sub0  s   " 	"__T* 	ECJJQ]2cfhstv{I UNE##FY__Q-?$?@NI **9??1+=uE$(	!Q	&/ooa&8A~$U\\$%78E*%/	2 	%r+   tag_namec                     t        t        j                  d|z  |            t        t        j                  d|z  |            k(  S )Nz<%s(?:.*?)>z</%s>)r   r   r   )r   rm  rF   s      r)   rf  zMarkdown._tag_is_closedc  s:    2::mh6=>#bjjQX[cQceiFjBkkkr+   c                     | j                   dz
  }t        j                  d|z  t        j                  t        j                  z  t        j
                  z        }|j                  | j                  |      S )Nr`   a  
            ^[ ]{0,%d}\[(.+)\]: # id = \1
              [ \t]*
              \n?               # maybe *one* newline
              [ \t]*
            <?(.+?)>?           # url = \2
              [ \t]*
            (?:
                \n?             # maybe one newline
                [ \t]*
                (?<=\s)         # lookbehind for whitespace
                ['"(]
                ([^\n]*)        # title = \3
                ['")]
                [ \t]*
            )?  # title is optional
            (?:\n+|\Z)
            )r5   r   r   Xr   Ur   _extract_link_def_sub)r   rF   less_than_tab_link_def_res       r)   r   z Markdown._strip_link_definitionsg  sf     * zz #"  ## " "$rtt!3#5$  : :DAAr+   c                     |j                         \  }}}|j                         }| j                  |      | j                  |<   |r|| j                  |<   yNr   )groupsr  _encode_amps_and_anglesrt   ru   )r   r   idurltitler   s         r)   rr  zMarkdown._extract_link_def_sub  sJ    Chhj55c:		#$DKKr+   c                     |j                         \  }}t        ||j                  d             j                         }t	        j
                  dd|      }|dz   | j                  |<   y)Nr   )skip_first_line\Wr   r   r   )rw  r  r   r   r   r   r   )r   r   ry  rF   r   s        r)   _extract_footnote_def_subz"Markdown._extract_footnote_def_sub  s[    <<>Dt1F-FGMMOFF5#r*	 %)6My!r+   c                     | j                   dz
  }t        j                  d|| j                   | j                   fz  t        j                  t        j                  z        }|j                  | j                  |      S )a  A footnote definition looks like this:

            [^note-id]: Text of the note.

                May include one or more indented paragraphs.

        Where,
        - The 'note-id' can be pretty much anything, though typically it
          is the number of the footnote.
        - The first paragraph may start on the next line, like so:

            [^note-id]:
                Text of the note.
        r`   a  
            ^[ ]{0,%d}\[\^(.+)\]:   # id = \1
            [ \t]*
            (                       # footnote text = \2
              # First line need not start with the spaces.
              (?:\s*.*\n+)
              (?:
                (?:[ ]{%d} | \t)  # Subsequent lines must be indented.
                .*\n+
              )*
            )
            # Lookahead for non-space at line-start, or end of doc.
            (?:(?=^[ ]{0,%d}\S)|\Z)
            )r5   r   r   rp  r   r   r  )r   rF   rs  footnote_def_res       r)   r   z$Markdown._strip_footnote_definitions  sk     *** & !$..$..A&B DD244K ""4#A#A4HHr+   z)^[ ]{0,3}([-_*])[ ]{0,2}(\1[ ]{0,2}){2,}$c                 8   | j                  |      }d| j                  z   dz   }t        j                  | j                  ||      }| j                  |      }| j                  |      }| j                  |      }| j                  |      }| j                  |      }|S )Nz
<hrr   )
_do_headersr   r   r   _hr_re	_do_lists_do_code_blocks_do_block_quotesr   _form_paragraphs)r   rF   hrs      r)   r   zMarkdown._run_block_gamut  s    
 % T...t3vvdkk2t,~~d###D)$$T* %%d+$$T*r+   c                    | j                  |      }| j                  |      }| j                  |      }| j                  |      }| j	                  |      }| j                  |      }t        j                  dd| j                  z  |      }|S )Nz  {2,}\n(?!\<(?:\/?(ul|ol|li))\>)<br%s
)	_do_code_spans_escape_special_chars	_do_links_do_auto_linksrx  _do_italics_and_boldr   r   r   r   s     r)   rL  zMarkdown._run_span_gamut  s    
 ""4())$/ ~~d#
 ""4(++D1((. vv99tG`G`;`bfgr+   a4  
        (
            \\*  # escapes
            (?:
                # tag
                </?
                (?:\w+)         # tag name
                (?:             # attributes
                    \s+                           # whitespace after tag
                    (?:[^\t<>"'=/]+:)?
                    [^<>"'=/]+=                   # attr name
                    (?:"[^"]*?"|'[^']*?'|[^<>"'=/\s]+)  # value, quoted or unquoted. If unquoted, no spaces allowed
                )*
                \s*/?>
                |
                # auto-link (e.g., <http://www.activestate.com/>)
                <[\w~:/?#\[\]@!$&'\(\)*+,;%=\.\\-]+>
                |
                <!--.*?-->      # comment
                |
                <\?.*?\?>       # processing instruction
            )
        )
        c           	      4   t        j                  d      }g }d}| j                  j                  |      D ]  }|r|j	                  |      r|j                  |      dd  xs d|f\  }}|j                  |j                  d| j                  d         |j                  d| j                  d         j                  d| j                  d         z          n0|j                  | j                  |j                  d	d
                   | } dj                  |      S )Nz^((?:\\\\)*(?!\\))Fr`   r   z\\r  *_z\<&lt;)
r   r   _sorta_html_tokenize_rer   r   r   r   r   _encode_backslash_escapesr6  )r   rF   lead_escape_reescapedis_html_markuptoken
escape_seqs          r)   r  zMarkdown._escape_special_chars
  s    $9:1177= 	0E ."6"6u"= %3$8$8$?$C$RE{!
E&&vt/A/A$/GHmmC););C)@A#GC););C)@AB t==emmESY>Z[\!//N%	0& wwwr+   c                     d|v r| j                   j                  |      ryd|v r| j                  j                  |      ryy)Nr   T@F)_auto_link_rer   _auto_email_link_rer   s     r)   _is_auto_linkzMarkdown._is_auto_link*  s?    $;4--33D9D[T55;;DAr+   c           
         	 	fd} fd}g } j                   j                  |      	d}t        	      D ],  \  }}|r  j                  |      s |||      s ||      }|r|j	                   j                   j                  |j                  d                         |j	                   j                  |j                  d                   |j	                   j                   j                  |j                  d                         nP|j	                   j                   j                  |                   n |j	                   j                  |             | }/ dj                  |      S )Nc                     	 |dk(  r	| | dz    }n|dk(  r| dz
  | dz    }nyt        j                  ddj                  |            S # t         $ r Y yw xY w)	N<code>r   </code>r   r`   Fz <code>md5-[A-Fa-f0-9]{32}</code>r   )r9  r   r   r6  )rZ  r  peek_tokenssplit_tokenss      r)   _is_code_spanz0Markdown._hash_html_spans.<locals>._is_code_span5  sp    H$".ueai"@Ki'".uqy%!)"DK  88?AUVV  s   A 	AAc                 P    j                   dk(  ry t        j                  d|       S )Nr   z(<!--)(.*)(-->))r6   r   r   )r  r   s    r)   _is_commentz.Markdown._hash_html_spans.<locals>._is_commentB  s$    ~~*88.66r+   Fr`   r   r   r   )
r  r   r   r  r   
_hash_spanr:  r   _encode_incomplete_tagsr6  )
r   rF   r  r  tokensr  rZ  r  
is_commentr  s
   `        @r)   r   zMarkdown._hash_html_spans1  s9   	W	7 3399$?%l3 	0LE5d&8&8&?V[]bHc(/
MM$//$2E2EjFVFVWXFY2Z"[\MM$"5"5j6F6Fq6I"JKMM$//$2E2EjFVFVWXFY2Z"[\MM$//$2E2Ee2L"MNd::5AB!//N	0 wwvr+   c                     d}||k7  r|r=t        | j                  j                               D ]  \  }}|j                  ||      } |r=t        | j                  j                               D ]  \  }}|j                  ||      } |}||k7  r|S )z
        Recursively unhash a block of text

        Args:
            spans: unhash anything from `self.html_spans`
            code: unhash code blocks
        r   )r  rw   r   r   r   )r   rF   spanscodeorigr   	sanitizeds          r)   r   zMarkdown._unhash_html_spansZ  s     dl&*4??+@+@+B&C 8NC<<Y7D8!%d&6&6&<&<&>!? 3ID#<<T2D3D dl r+   r!   c                     | j                   dk(  r| j                  S | j                   dk(  r"g d}|D ]  \  }}|j                  ||      } |S t        d| j                   z        )Nr   r   )&&amp;)rI  r  )r|   &gt;zAinvalid value for 'safe_mode': %r (must be 'escape' or 'replace'))r6   rx   r   r-   )r   r!   replacementsbeforeafters        r)   r:  zMarkdown._sanitize_htmlm  sx    >>Y&)))^^x'L
 ". -IIfe,-H !9;?>>!J K Kr+   z
            (                   # \1
              [ \t]+
              (['"])            # quote char = \2
              (?P<title>.*?)
              \2
            )?                  # title is optional
          \)$
        z
          # Match tail of: [text][id]
          [ ]?          # one optional space
          (?:\n[ ]*)?   # one optional newline followed by spaces
          \[
            (?P<id>.*?)
          \]
        z\s*z<(.*)>.*r   c                 t    | j                   j                  ||      }|r|j                         S t        |      S )zlReturns the index of the first non-whitespace character in text
        after (and including) start
        )_whitespacer   r  r   )r   rF   r   r   s       r)   _find_non_whitespacezMarkdown._find_non_whitespace  s3       &&tU3#uyy{2T2r+   open_cclose_cc                     |}t        |      }d}|dkD  r0||k  r+||   |k(  r|dz  }n||   |k(  r|dz  }|dz  }|dkD  r||k  r+|S )zReturns the index where the open_c and close_c characters balance
        out - the same number of open_c and close_c are encountered - or the
        end of string if it's reached before the balance point is found.
        r`   r   r   )r   rF   r   r  r  r*  lcounts           r)   _find_balancedzMarkdown._find_balanced  sm    
 IaiAEAw& 
aG#
FA aiAE r+   z
        data:
        # in format type/subtype;parameter=optional
        (?P<mime>\w+/[\w+\.-]+(?:;\w+=[\w+\.-]+)?)?
        # optional base64 token
        (?P<token>;base64)?
        ,(?P<data>.*)
    rz  c                     | j                   j                  |      }d}|<|j                  d      xs d}|j                  d      r|j                  d      dk(  rd}t	        || j
                  |      }t        |      }|| j                  |<   |S )	z
        Function that passes a URL through `_html_escape_url` to remove any nasty characters,
        and then hashes the now "safe" URL to prevent other safety mechanisms from tampering
        with it (eg: escaping "&" in URL parameters)
        Nmimer   zimage/r  z;base64base64)r6   charset)_data_url_rer   r   r   _html_escape_urlr6   r*   r   )r   rz  data_urlr  r  r   s         r)   _protect_urlzMarkdown._protect_url  s     $$**3/>>&)/RDx(X^^G-D	-Q sdnngNo"%3
r+   z#(?:https?|ftp):\/\/|(?:mailto|tel):c                     d}d}dj                  ||      }d||z   z  }t        j                  dj                  | j                  |||      t        j                        S )aZ  
        _safe_href is adapted from pagedown's Markdown.Sanitizer.js
        From: https://github.com/StackExchange/pagedown/blob/master/LICENSE.txt
        Original Showdown code copyright (c) 2007 John Fraser
        Modifications and bugfixes (c) 2009 Dana Robinson
        Modifications and bugfixes (c) 2009-2014 Stack Exchange Inc.
        z-\wz$#/\.!#$%&\(\)\+,/:;=\?@\[\]^`\{\}\|~z5(?:[{}]+(?:\.[{}]+)*)(?:(?<!tel):\d+/?)?(?![^:/]*:/*)z[%s]*z%^(?:({})?({})({})|(#|\.{{,2}}/)({}))$)r  r   r   _safe_protocolsI)r   safe	less_safedomainfragments        r)   
_safe_hrefzMarkdown._safe_href  sr     ;	IPPQUW[\ti/0zzBII$J^J^`fhprz{}  ~B  ~B  C  	Cr+   c                 b    t        | d      }|j                  |      r|j                  |      }|S )a  Turn Markdown link shortcuts into XHTML <a> and <img> tags.

        This is a combination of Markdown.pl's _DoAnchors() and
        _DoImages(). They are done together because that simplified the
        approach. It was necessary to use a different approach than
        Markdown.pl because of the lack of atomic matching support in
        Python's regex engine used in $g_nested_brackets.
        N)LinkProcessorrf   rg   )r   rF   link_processors      r)   r  zMarkdown._do_links  s3     'tT2t$!%%d+Dr+   r   nc                     t        |      }|rt        |t              r|dz   |z   }| j                  |xx   dz  cc<   dt	        |      k(  s| j                  |   dkD  r|d| j                  |   z  z  }|S )a  Generate a header id attribute value from the given header
        HTML content.

        This is only called if the "header-ids" extra is enabled.
        Subclasses may override this for different header ids.

        @param text {str} The text of the header tag
        @param prefix {str} The requested prefix for header ids. This is the
            value of the "header-ids" extra key, if any. Otherwise, None.
        @param n {int} (unused) The <hN> tag number, i.e. `1` for an <h1> tag.
        @returns {str} The value for the header tag's "id" attribute. Return
            None to not have an id attribute and to exclude this header from
            the TOC (if the "toc" extra is specified).
        r   r`   r   z-%s)_slugifyr   r   r   r   )r   rF   r   r  	header_ids        r)   header_id_from_textzMarkdown.header_id_from_text  s{    & TN	j-y0I""9-2-I$"<"<Y"G!"K!;!;I!FFFIr+   c                     t        |      }| j                  d   j                  d      }|rt        |t              r|dz   |z   }|| j
                  v xs |t        d | j                        v S )Nr   r   r   c                     | d   S r   r1   )xs    r)   rO  z,Markdown._header_id_exists.<locals>.<lambda>  s    UVWXUY r+   )r  r7   r   r   r   r   maprz   )r   rF   r  r   s       r)   _header_id_existszMarkdown._header_id_exists  sg    TN	\*..x8j-y0ID666e)s>[_[d[dGe:eer+   levelry  rd   c                     || j                   kD  ry | j                  g | _        | j                  j                  ||| j                  |      f       y rK  )r   rz   r   r   )r   r  ry  rd   s       r)   _toc_add_entryzMarkdown._toc_add_entry  sF    4??"99DI		%T%A%A$%GHIr+   a=  
        (^(.+)[ \t]{0,99}\n(=+|-+)[ \t]*\n+)
        |
        (^(\#{1,6})  # \1 = string of #'s
        [ \t]%s
        (.+?)       # \2 = Header text
        [ \t]{0,99}
        (?<!\\)     # ensure not an escaped trailing '#'
        \#*         # optional closing #'s (not counted)
        \n+
        )
        r  +c                    |j                  d      %|j                  d      dk(  r|j                  d      S |j                  d      ,ddd|j                  d      d      }|j                  d      }n+t        |j                  d            }|j                  d      }| j                  j                  d	      }|rt	        ||z   d      }d
}d| j                  v r6| j                  || j                  d   j                  d      |      }|rd|z  }| j                  |      }d| j                  v rr| j                  |||       d||||fz  S )z#Handles processing markdown headersr`   r   r   r   )r   r   r   r   r   zdemote-headersr   r   r    id="%s"r~   z<h%d%s>%s</h%d>

)r   r   r7   r   minr  rL  r  )r   r   r  header_groupdemote_headersheader_id_attrr  r?  s           r)   _h_subzMarkdown._h_sub$  s9   ;;q>%%++a.C*?;;q>![[^'a Q!23A ;;q>L EKKN#A ;;q>L)9:A&*A4;;&00L)--h7<I!+i!7##L1DKKI9d3$>4'CCCr+   z\
        ^<h([1-6])(.*)>  # \1 tag num, \2 attrs
        (.*)  # \3 text
        </h\1>
    c                 X   |j                   |j                         |j                          }t        |j	                  d            }t        j                  d|j	                  d      xs d      xs d}|r|j	                  d      xs d}|j                  d      }|j	                  d      }|r| j                  |      r|S |xs/ | j                  || j                  d   j                  d      |      }d	| j                  v r| j                  |||       |r|s|d
d d|z  z   |dd
 z   S |S )zIDifferent to `_h_sub` in that this function handles existing HTML headersr`   z.*?id=(\S+)?.*r   r   z'" r   r   r   r~   Nr  )r  r   r  r   r   r   r   r   r  r  r7   r   r  )r   r   rF   h_levelid_attrh_textr  s          r)   r>  zMarkdown._h_tag_subE  s   ||EKKM599;7ekk!n%88-u{{1~/CDJmmA&,"G--'Q t--g6K qt77L@Y@]@]^f@gipq	DKKF;W8j944tABx??r+   c                     d| j                   v r&| j                  j                  | j                  |      S | j                  j                  | j                  |      S )Nztag-friendly)r7   _h_re_tag_friendlyr   r  _h_rer   s     r)   r  zMarkdown._do_headers^  sF      T[[(**..t{{DAAzz~~dkk400r+   z*+-z(?:[%s]|\d+\.)z(?:[%s])z	(?:\d+\.)c                    |j                  d      }|j                  d      | j                  v xr dxs d}|dk(  r,|j                  d      dk7  rd|j                  d      d d z  }nd}|| j                  |      z   }| j                  |      }| j                  rd	j                  ||||      S d
j                  ||||      S )Nr`   r   ulolz1.z start="%s"r  r   z<{}{}>
{}</{}>
z<{}{}>
{}</{}>

)r   _marker_ul_chars_html_class_str_from_tag_process_list_itemsr   r  )r   r   lstlst_typelst_optsrj  s         r)   	_list_subzMarkdown._list_subw  s    kk!n;;q>T%:%::CtKttA$ 6$u{{1~cr'::HHd;;HEE))#.??&--h&(SS(//(FHUUr+   c                 0   d}	 g }| j                   | j                  fD ]  }| j                  dz
  }|| j                  k(  r| j                   n| j                  }d||||fz  }| j                  rJt	        j
                  d|z   t        j                  t        j                  z  t        j                  z        }nIt	        j
                  d|z   t        j                  t        j                  z  t        j                  z        }|j                  ||      }	|	s|j                  |	j                         |	f        |s	 |S |j                          |d   d   }	|	j                         \  }
}| j                  |	      }|d |
 |z   ||d  z   }|
t        |      z   })Nr   r`   a]  
                    (                   # \1 = whole list
                      (                 # \2
                        ([ ]{0,%d})     # \3 = the indentation level of the list item marker
                        (%s)            # \4 = first list item marker
                        [ \t]+
                        (?!\ *\4\ )     # '- - - ...' isn't a list. See 'not_quite_a_list' test case.
                      )
                      (?:.+?)
                      (                 # \5
                          \Z
                        |
                          \n{2,}
                          (?=\S)
                          (?!           # Negative lookahead for another list item marker
                            [ \t]*
                            %s[ \t]+
                          )
                        |
                          \n+
                          (?=
                            \3          # lookahead for a different style of list item marker
                            %s[ \t]+
                          )
                      )
                    )
                ^z(?:(?<=\n\n)|\A\n?))
_marker_ul
_marker_olr5   r   r   r   rp  r   Sr   r   r   r   r  r  r   )r   rF   poshits
marker_patrs  other_marker_pat
whole_listlist_rer   r   r  rC  s                r)   r  zMarkdown._do_lists  sv   
  D#@ %8
 $ 26@DOO6S4??Y]YhYh 4 %j*>NO5P
6 ?? jjZrtt9KLG jj)?
)J)+rtt);=GtS1KK 67K%8L   IIKGAJEJE3^^E*F<&(4:5D#f+%Ce r+   aD  
        (\n)?                   # leading line = \1
        (^[ \t]*)               # leading whitespace = \2
        (?P<marker>{}) [ \t]+   # list marker = \3
        ((?:.+?)                # list item text = \4
        (\n{{1,2}}))              # eols = \5
        (?= \n* (\Z | \2 (?P<next_marker>{}) [ \t]+))
        zr
        (\[[\ xX]\])[ \t]+       # tasklist marker = \1
        (.*)                   # list item text = \2
    zE<input type="checkbox" class="task-list-item-checkbox" %sdisabled> %sc                     |j                  d      }|j                  d      }|dv r| j                  d|fz  S |dk(  r| j                  d|fz  S y)Nr`   r   )z[x]z[X]zchecked z[ ]r   )r   _task_list_warpper_str)r   r   marker	item_texts       r)   _task_list_item_subzMarkdown._task_list_item_sub  s[    QKKN	]"..*i1HHHu_.."i@@ r+   c                    |j                  d      }|j                  d      }|sd|v s| j                  r3| j                  |d| j                        d   }| j	                  |      }nL| j                  | j                  |d      d         }|j                  d      r|d d }| j                  |      }t        |j                  d	            d
k(  | _        d| j                  v r&| j                  j                  | j                  |      }d|z  S )Nr   r`   r   r}   )min_outdentmax_outdent)r  r   r  r   r   	task_listz<li>%s</li>
)r   _last_li_endswith_two_eols_uniform_outdentr   r   r  r!  rL  r   r7   _task_list_item_rer   r  )r   r   r  leading_lines       r)   _list_item_subzMarkdown._list_item_sub  s    {{1~{{1~6T>T-L-L((3DHH(UVWXD((.D >>$"7"7#"7"Nq"QRD}}T"CRy''-D+.u{{1~+>!+C'$++%**..t/G/GND%%r+   list_strc                     | xj                   dz  c_         d| _        |j                  d      dz   }| j                  j	                  | j
                  |      }| xj                   dz  c_         |S )Nr`   Fr   )r   r  r"  _list_item_rer   r  )r   r  s     r)   r  zMarkdown._process_list_items  s^    0 	1*/'??4(4/%%))$*=*=xH1r+   
lexer_namec                     	 ddl m}m} 	 |j	                  |      S # t        $ r Y yw xY w# |j
                  $ r Y yw xY w)zy
        Returns:
            `pygments.Lexer` or None if a lexer matching `lexer_name` is
            not found
        r   )lexersutilN)pygmentsr  r  ImportErrorget_lexer_by_nameClassNotFound)r   r  r  r  s       r)   _get_pygments_lexerzMarkdown._get_pygments_lexer  sM    	-	++J77  		 !! 		s    + 	((==	codeblockc                     ddl }ddl} G d d|j                  j                        }|j	                  dd        |di |}|j                  |||      S )a-  
        TODO: this function is only referenced by the `FencedCodeBlocks`
        extra. May be worth moving over there

        Args:
            codeblock: the codeblock to highlight
            lexer (pygments.Lexer): lexer to use
            formatter_opts: pygments HtmlFormatter options
        r   Nc                        e Zd Zd Zd ZddZy)8Markdown._color_with_pygments.<locals>.HtmlCodeFormatterc              3   4   K   d |E d{    d y7 	w)zgA function for use in a Pygments Formatter which
                wraps in <code> tags.
                )r   r  N)r   r  r1   r   rn   s     r)   
_wrap_codezCMarkdown._color_with_pygments.<locals>.HtmlCodeFormatter._wrap_code6  s"      "!   "" !   

c              3   4   K   d |E d {    d y 7 	w)N)r   r   r1   r(  s     r)   _add_newlinezEMarkdown._color_with_pygments.<locals>.HtmlCodeFormatter._add_newline>  s         !r*  Nc           	          |/| j                  | j                  | j                  |                  S | j                  | j                  | j                  | j                  |                        S )z,Return the source with a code, pre, and div.)r,  	_wrap_prer)  	_wrap_div)r   sourceoutfiles      r)   wrapz=Markdown._color_with_pygments.<locals>.HtmlCodeFormatter.wrapD  sY    ?,,T^^DOOF<S-TUU  >>$*;*;DNN4??[aKb<c*deer+   rK  )r.   r/   r0   r)  r,  r2  r1   r+   r)   HtmlCodeFormatterr&  5  s    #fr+   r3  cssclass
codehiliter1   )r  pygments.formatters
formattersHtmlFormatterr   	highlight)r   r#  lexerformatter_optsr  r3  	formatters          r)   _color_with_pygmentszMarkdown._color_with_pygments#  sX     	"	f 3 3 A A 	f0 	!!*l;%77	!!)UI>>r+   c                 6   |j                  d      }| j                  |      }| j                  |      }|j                  d      }|j	                         }| j                  d      }| j                  d      }| j                  |      }dj                  |||      S )Nr`   r   prer  z!
<pre{}><code{}>{}
</code></pre>
)r   _outdentr   r   r"  r  _encode_coder  )r   r   r#  pre_class_strcode_class_strs        r)   _code_block_subzMarkdown._code_block_subQ  s    KKN	MM),	KK	*	$$T*	$$&	55e<66v>%%i0	5<<>96 	6r+   r@  c                     d| j                   vry	 | j                   d   }t        |t              r||v rd||   z  S y# t        $ r Y yw xY w)zoGet the appropriate ' class="..."' string (note the leading
        space), if any, for the given tag.
        zhtml-classesr   z class="%s")r7   r   r   	TypeError)r   r@  html_classes_from_tags      r)   r  z!Markdown._html_class_str_from_tag`  sf     ,	F$(KK$?! /6//(+@+EEE  		s   = 	A	A	c                     t        j                  d| j                  | j                  fz  t         j                  t         j                  z        }|j                  | j                  |      S )z&Process Markdown `<pre><code>` blocks.a<  
            (?:\n\n|\A\n?)
            (               # $1 = the code block -- one or more lines, starting with a space/tab
              (?:
                (?:[ ]{%d} | \t)  # Lines must start with a tab or a tab-width of spaces
                .*\n+
              )+
            )
            ((?=^[ ]{0,%d}\S)|\Z)   # Lookahead for non-space at line-start, or end of doc
            # Lookahead to make sure this block isn't already in a code block.
            # Needed when syntax highlighting is being used.
            (?!([^<]|<(/?)span)*\</code\>)
            )r   r   r5   r   rp  r   rD  )r   rF   code_block_res      r)   r  zMarkdown._do_code_blocksp  sZ     

 $ >>4>>2$3 DD244K   !5!5t<<r+   a
  
            (?<!\\)
            (`+)        # \1 = Opening run of `
            (?!`)       # See Note A test/tm-cases/escapes.text
            (.+?)       # \2 = The code block
            (?<!`)
            \1          # Matching closer
            (?!`)
        c                     |j                  d      j                  d      }| j                  |      }dj                  | j	                  d      |      S )Nr   rR  z<code{}>{}</code>r  )r   r   rA  r  r  )r   r   cs      r)   _code_span_subzMarkdown._code_span_sub  sI    KKN  'a "))$*G*G*OQRSSr+   c                 N    | j                   j                  | j                  |      S rK  )_code_span_rer   rL  r   s     r)   r  zMarkdown._do_code_spans  s#    0 !!%%d&9&94@@r+   c                 z    g d}|D ]  \  }}|j                  ||      } t        |      }|| j                  |<   |S )zEncode/escape certain characters inside Markdown code runs.
        The point is that in code, these characters are literals,
        and lose their special Markdown meanings.
        r  )r   r*   r   )r   rF   r  r  r  hasheds         r)   rA  zMarkdown._encode_code  sM    

 * 	/MFE<<.D	/D!!'r+   z"(\*\*|__)(?=\S)(.+?[*_]?)(?<=\S)\1z(\*|_)(?=\S)(.*?\S)\1c                 v    | j                   j                  d|      }| j                  j                  d|      }|S )Nz<strong>\2</strong>z<em>\2</em>)
_strong_rer   _em_rer   s     r)   r  zMarkdown._do_italics_and_bold  s4     ""#94@{{~t4r+   a&  
        (                           # Wrap whole match in \1
          (
            ^[ \t]*>%s[ \t]?        # '>' at the start of a line
              .+\n                  # rest of the first line
            (.+\n)*                 # subsequent consecutive lines
          )+
        )
    r   z[ 	]*?!?z^[ 	]*>[ 	]?z^[ 	]*>[ 	]*?![ 	]?z"\A(?:^[ \t]*>[ \t]*?!.*[\n\r]*)+\Zz(\s*<pre>.+?</pre>)c                 N    t        j                  dd|j                  d            S )Nz(?m)^  r   r`   )r   r   r   r   r   s     r)   _dedent_two_spaces_subzMarkdown._dedent_two_spaces_sub  s    vvj"ekk!n55r+   c                    |j                  d      }d| j                  v xr | j                  j                  |      }|r| j                  j                  d|      }n| j                  j                  d|      }| j                  j                  d|      }| j                  |      }t        j
                  dd|      }| j                  j                  | j                  |      }|rd|z  S d|z  S )Nr`   spoilerr   z(?m)^  z/<blockquote class="spoiler">
%s
</blockquote>

z<blockquote>
%s
</blockquote>

)r   r7   _bq_all_lines_spoilersr   _bq_one_level_re_spoilerr   _bq_one_level_rer   r   r   _html_pre_block_rerV  )r   r   bq
is_spoilers       r)   _block_quote_subzMarkdown._block_quote_sub  s    [[^$++-W$2M2M2S2STV2W
..222r:B&&**2r2B""&&r2.""2&VVGT2&$$(()D)DbIH2MM82==r+   c                     d|vr|S d| j                   v r&| j                  j                  | j                  |      S | j                  j                  | j                  |      S )Nr|   rX  )r7   _block_quote_re_spoilerr   r`  _block_quote_rer   s     r)   r  zMarkdown._do_block_quotes  sX    d?K#//33D4I4I4PP''++D,A,A4HHr+   c                    |j                  d      }g }t        t        j                  d|            D ]|  \  }}|| j                  v r|j                  | j                  |          4d }d| j                  v r| j                  j                  |dz         }|rt        |j                  d            dk  r|j                  d      r)|j                  d      d   |j                  d      d   k(  s|j                  d      S|j                         }| j                  ||d        j                  d      }t        j                  d	|      r|d | }n|}d }| j                  |      }|j                  d
| j!                  d      z  |j#                  d      z   dz          |sl|j                  |        dj%                  |      S )Nr   z\n{2,}zcuddled-listsr   r   next_markerr  r  z^<(?:ul|ol).*?>z<p%s>prR  </p>r   )r   r   r   r   rv   r   r7   r  r   r   r   r   r  r"  r   rL  r  r   r6  )r   rF   grafsr*  grafcuddled_listlir   s           r)   r  zMarkdown._form_paragraphs  s    zz$  )T!:; %	/GAtt'''T--d34#"dkk1 ++224$;?B s288A;/14%'XXm%<(ASTVAW[][c[cdq[rsu[vAv$&HH]$;$C !#
'+~~d56l'C'J'J4'P88$6E#'<D $0D+/L ++D1Wt'D'DS'IIDKKX]L^^agghLL.K%	/N {{5!!r+   c                      j                   rdd j                  z   dg} j                  sd _         j                  sd _         j                  j                   fd       t         j                        D ]  \  }}|dk7  r|j                  d	       |j                  d
|z         |j                   j                   j                   |                	 d j                  z   dz    j                  z   dz   ||dz   fz  }|d   j                  d      r|d   d t        d        dz   |z   dz   |d<   n|j                  d|z         |j                  d        |j                  d       |j                  d       |dz   dj                  |      z   S |S # t        $ r" t        j                  d       d||dz   fz  }Y w xY w)Nz<div class="footnotes">rP  z<ol>z%Jump back to footnote %d in the text.z&#8617;c                 h    t        j                  j                               j                  |       S rK  )r  r   keysrZ  )ar   s    r)   rO  z)Markdown._add_footnotes.<locals>.<lambda>A  s%    dnn6I6I6K1L1R1RST1U r+   r   r   r   z<li id="fn-%s">z4<a href="#fnref-%s" class="footnoteBackLink" title=""></a>r`   zHFootnote error. `footnote_title` must include parameter. Using defaults.zf<a href="#fnref-%s" class="footnoteBackLink" title="Jump back to footnote %d in the text.">&#8617;</a>r  rg  z&#160;z

<p>%s</p></li>z</ol>z</div>r   r   )r   r   r9   r:   r   r   r   r   r   rF  r  r  r!  r   r6  )r   rF   footerr*  ry  backlinks   `     r)   r   zMarkdown._add_footnotes1  s   >>)111F &&&M#...7+
 ""'U"V"4#4#45 '26MM"%/"45d33DNN24FGH3!&(,(;(;!<>B!C !77!8 #	!# (*1Q3i	 0H ":&&v.!'Mc&k\!:""#%-".06"7F2J MM-(":;g&1'2 MM'"MM(#&=499V#444K% ! 3II H I!& *,QqS	!2H3s   *F(GGz<(?![a-z/?\$!])z(?<![a-z0-9?!/'"-])>c                     t         j                  d|      }| j                  j                  d|      }| j                  j                  d|      }|S )Nr  r  r  )_AMPERSAND_REr   _naked_lt_re_naked_gt_rer   s     r)   rx  z Markdown._encode_amps_and_anglesd  sO       $/   $$VT2
   $$VT2r+   z'<(!--|/?\w+?(?!\w)\s*?.+?(?:[\s/]+?|$))c                     | j                   dvr|S | j                  |      r|S d }| j                  j                  ||      S )Nr   c                 B    | j                         j                  dd      S )NrI  r  )r   r   )r   s    r)   incomplete_tags_subz=Markdown._encode_incomplete_tags.<locals>.incomplete_tags_sub{  s    ;;=((f55r+   )r6   r  _incomplete_tags_rer   )r   rF   r{  s      r)   r  z Markdown._encode_incomplete_tagst  sH    >>!66Kd#K	6 ''++,?FFr+   c                     t        | j                  j                               D ]  \  }}|j                  d|z   |      } |S )Nr  )r  r   r   r   )r   rF   chr   s       r)   r  z"Markdown._encode_backslash_escapes  sB    t11779: 	1JB<<R0D	1r+   z<((https?|ftp):[^\'">\s]+)>c                 f    |j                  d      }dj                  | j                  |      |      S )Nr`   <a href="{}">{}</a>)r   r  r  )r   r   g1s      r)   _auto_link_subzMarkdown._auto_link_sub  s-    [[^$++D,=,=b,A2FFr+   z
          <
           (?:mailto:)?
          (
              [-.\w]+
              \@
              [-\w]+(\.[-\w]+)*\.[a-z]+
          )
          >
        c                 `    | j                  | j                  |j                  d                  S r   )_encode_email_addressr   r   rU  s     r)   _auto_email_link_subzMarkdown._auto_email_link_sub  s+    ))((Q8: 	:r+   c                     | j                   j                  | j                  |      }| j                  j                  | j                  |      }|S rK  )r  r   r  r  r  r   s     r)   r  zMarkdown._do_auto_links  sC    !!%%d&9&94@''++D,E,EtLr+   addrc                     d|z   D cg c]  }t        |       }}ddj                  |      ddj                  |dd        d}|S c c}w )Nzmailto:	<a href="r   rp     rq  ) _xml_encode_email_char_at_randomr6  )r   r  r~  charss       r)   r  zMarkdown._encode_email_address  sZ     %t+- 2"5 - - ''%."''%)"46-s   Ac                 :   t        | j                  j                               t        | j                  j                               z   }|t        d | j                  j                         D              z  }	 |}|D ]  \  }}|j                  ||      } ||k(  r	 |S ')Nc              3   D   K   | ]  }t        t        |              y wrK  )tuplereversed).0r*  s     r)   	<genexpr>z3Markdown._unescape_special_chars.<locals>.<genexpr>  s     Nx{+Ns    )r  r   r   r   rv   r   )r   rF   hashmap	orig_textr~  hashs         r)   r   z Markdown._unescape_special_chars  s    **0023eD<L<L<R<R<T6UU5NT5E5E5K5K5MNNNI# .D||D"-.y  r+   c                 :    | j                   j                  d|      S rv  )r   r   r   s     r)   r@  zMarkdown._outdent  s    ##B--r+   c                 :    t        |      }|| j                  |<   |S )z
        Wrapper around `_hash_text` that also adds the hash to `self.hash_spans`,
        meaning it will be automatically unhashed during conversion.
        )r*   rw   )r   rF   r   s      r)   r  zMarkdown._hash_span  s!    
 #
r+   r  r  c                    | j                         D cg c]  }|rt        j                  d|      d   nd! }}|D cg c]  }||	 }}|sd| fS t        |      }|$t        |D cg c]
  }||k\  s	| c}xs |g      }|t        ||      }g }t	        || j                  d            D ]t  \  }	}|j                  |      r#|j                  |j                  |dd             :|	(|	|k  r#|j                  |j                  |	dd             d|j                  |       v |dj                  |      fS c c}w c c}w c c}w )aS  
        Removes the smallest common leading indentation from each (non empty)
        line of `text` and returns said indent along with the outdented text.

        Args:
            min_outdent: make sure the smallest common whitespace is at least this size
            max_outdent: the maximum amount a line can be outdented by
        z^[ \t]*r   Nr   Tr`   )	r  r   r   r  zipr   r   r   r6  )
rF   r  r  r+  
whitespacer*  whitespace_not_emptyoutdent	outdentedline_wss
             r)   r  zMarkdown._uniform_outdent  s^   $ ).
 04BJJz4(+=.

 .
 ,6GaGG $t8O *+"&:Oa;>N1O`T_S`aG"';/G	 T__T-BC 	'MGTw'  gr1!=>$7):  gr1!=>  &	' 	***;.
  H Ps   $D7D<D<'
E2Eindentinclude_empty_linesindent_empty_linesc                     g }| j                  d      D ]N  }|j                         s|r|j                  ||z          *|r|j                  |       >|j                  d       P dj                  |      S )aO  
        Uniformly indent a block of text by a fixed amount

        Args:
            text: the text to indent
            indent: a string containing the indent to apply
            include_empty_lines: don't remove whitespace only lines
            indent_empty_lines: indent whitespace only lines with the rest of the text
        Tr   )r  r   r   r6  )rF   r  r  r  blocksr+  s         r)   _uniform_indentzMarkdown._uniform_indent  sh      OOD) 	"Dzz|1ftm,$d#b!	" wwvr+   substrc                     t        j                  t        j                  |      |       D ]N  }|j                         \  }}||j	                         cxk  r|k  r y ||j                         cxk  r|k  sL y P y)zV
        Checks if a regex match overlaps with a substring in the given text.
        TF)r   finditerr   r  r   r  )rF   r   r  instancer   r  s         r)   _match_overlaps_substrzMarkdown._match_overlaps_substr	  sq    
 BIIf$5t< 	H!JE3,, -		*s* +		 r+   )F)TFrK  NN)FF)r.   r/   r0   _extras_dict__annotations__r   r   rx   ry   r   
_safe_moder  r  r   r   rK   floatr   r   r   r   DEFAULT_TAB_WIDTHbool_extras_param_link_patternsr   r   r   
IGNORECASEVERBOSEr   rD   rr   rZ   r   rL   r   r  	MULTILINEr  r   r   r   r   r   UNICODEr   DOTALLr  Matchr   r   r1  r   
_html5tagsrV  rp  _strict_tag_block_re_block_tags_brX  rW  r;  r   rG  rM   r   r   rU  rf  rN   r   rr  r  r   r  rO   r   rU   rL  r  rW   r  r  r   r   r:  r  _inline_link_title_tail_of_reference_link_rer  _strip_anglebracketsr  r  r  r  r  propertyr  rX   r  r  r  r  
_h_re_baser  r  r  r=  r>  rP   r  r  _marker_anyr   r  r  rQ   r  r  r  r
  r  r  r  r  r"  r=  rD  r  rR   r  rN  rL  rV   r  rA  rR  rS  rY   r  _block_quote_baserc  rb  r\  r[  rZ  r]  rV  r`  rS   r  rT   r  r   r  rw  rx  rx  r|  r  r  r  r  rq  r  r  r  r  r   r@  r  staticmethodr  r  r  r1   r+   r)   rC   rC     s    W%%
sCx.cNc3hS#X)s)$4c4
##
uS#s]#
$$ JL=L "rzz+rtt4  **.*.26(,04#T6T6 T6 J'	T6
 'T6  /T6 !T6 !)T6 T6 T6lP2 ", - 	

"
"CC C$6 CJ !!"   #   !s s  "& $ % F')ABBLLSUS]S]D] #

V
 #

Dbll  *rzz*:BLLI#E2<<8Hc Hc HT  *rzz*qsus}s}~ 'BJJ (
 ]]R\\)BII5

BD(bhh (3 (eC eDcN eN	( 	( 	(!3 !3 !0 hJ ZMZM%2:: 
' 
' 	rtt kMZM	M 
 'BJJ 
( 
( 	rtt (RZZ$&
 2%RXXs]#2% 2% 
	2%h  rc r r r !rr #11 1 C5#:&	1
 1 
1fls l# l$ l  BC BC B !B6288  rxx C I I IB RZZDbddKF!!"S S  #<   !C C  "4 )bjj *. TT/2 $$% #  #   & >  &S &S & !&Ps s &K K K  $ % TTBDD[ ", - TTBDD[" "**V$K%2::k23 3S 3S 33 s C # RU $ 2::  
L  " =OC C" c c  "   C= 
	:fc fd fJC JS J J JJ BJJzC'5E#J$4bddRTTkBDBHH D D6 

  
	I S 2 1 1 1 1& #&66K..JJVrxx VC V$ 9c 9c 9 9v BJJ   F;,
rttbddM $ % 
rtt	
 f	 	c 	 "'&BHH & &&C C >c ,?,?
 
,?\6RXX 6# 6C C   !!"=C =C = #=4 BJJ   TTBDD[MTBHH T T
   !A3 A3 A "A2  & A244HJRZZ0"$$7F%%&   ' !bjj!2R!7EO(bjj):[)H"$$QSQUQU+V!rzz"2BDD9)rzz*BBDDI'RZZ(MrttT#$:BDDA6BHH 6 6>bhh >3 >* ""#IS IS I $I   !-"S -"S -" "-"^.3 .3 .` 2::0"$$7L2::9244@LC C  %"**%OP
GC 
GC 
Gc c 
 BJJ=rttDMGBHH G G %"** 	& TTBDD[244	!:"(( :s :3 3 
# # (C C .S .S .s s   &*%),+,+c],+ c],+ 
sCx	,+ ,+\  %*#(	 " !	
 
 2 
BHH 
c 
d 
 
r+   rC   c                       e Zd ZdZddgZy)MarkdownWithExtrasa  A markdowner class that enables most extras:

    - footnotes
    - fenced-code-blocks (only highlights code if 'pygments' Python module on path)

    These are not included:
    - pyshell (specific to Python-related documenting)
    - code-friendly (because it *disables* part of the syntax)
    - link-patterns (because you need to specify some actual
      link-patterns anyway)
    r   fenced-code-blocksN)r.   r/   r0   __doc__r7   r1   r+   r)   r  r  "	  s    
 /0Fr+   r  c                      e Zd ZU i Zeeed    f   ed<   i Zee	e
eed       eed       f   f   ed<   eed<   	 e
eee	ed    f      eee	ed    f      f   ed<   	 dedee   fdZed        Zed	        Zed
edefd       Zd
edefdZy)rb   r   rc   rd   ra   rh   optionsc                 4    || _         ||| _        yi | _        y)z
        Args:
            md: An instance of `Markdown`
            options: a dict of settings to alter the extra's behaviour
        N)rh   r  )r   rh   r  s      r)   r   zExtra.__init__G	  s     ")"5w2r+   c                     | j                   | j                  v r| j                  | j                   = t        j                  j	                         D ]$  }|D ]  }| |v s|j                  |        | |v r & y)z\
        Removes the class from the extras registry and unsets its execution order.
        N)rd   r   rb   rc   valuesremove)cls
exec_ordersections      r)   
deregisterzExtra.deregisterP	  sm    
 88s}}$chh'++224 	(J% (WnNN3' Wn(	(r+   c                    | | j                   | j                  <   t        g | j                  d   | j                  d         D ])  \  }}|t	        | j                  d         k  }t        |t              sjt        |t              rZt        j                  j                         D ]8  }|D ]1  }||v s|j                  |      }|s|dz  }|j                  ||        3 : t        j                  j                  |g g f       | t        j                  |   |rdnd   v r|r(t        j                  |   d   j                  d|        t        j                  |   d   j                  |        , y)z
        Registers the class for use with `Markdown` and calculates its execution order based on
        the `order` class attribute.
        r   r`   N)r   rd   r   ra   r   r   rK   
issubclassrb   rc   r  rZ  insertr   r   )r  rZ  r  r  exec_ordersr  to_indexs          r)   registerzExtra.register^	  sK    #&chh$%Csyy|%Cciil%CD 	;KE4S1..FdE*z$/F#(#4#4#;#;#= :K#. :7?'.}}T':H#) (A#NN8S9:: !!,,TB8<%++D1v!1EE%%d+A.55a=%%d+A.55c:+	;r+   rF   r"   c                      y)z
        Run the extra against the given text.

        Returns:
            The new text after being modified by the extra
        Nr1   r   s     r)   rg   z	Extra.run}	  s     	r+   c                      y)z
        Check a section of markdown to see if this extra should be run upon it.
        The default implementation will always return True but it's recommended to override
        this behaviour to improve performance.
        Tr1   r   s     r)   rf   z
Extra.test	  s     r+   N)r.   r/   r0   r   r   r   typer  rc   rK   r  r  r   r   rC   r   r   classmethodr  r  r
   rg   r  rf   r1   r+   r)   rb   rb   8	  s   *,ItCg&',PRKeU4W#6T']8K#KLLMR
I E%g"678*U5RVW^R_K_E`:aabb
>8 >htn > ( ( ; ;<      r+   rb   c                        e Zd ZdZdZej                  fej                  ffZej                  Z
ej                  Zdedee   f fdZd Zedej&                  defd	       Zdej&                  defd
Zd Z xZS )ItalicAndBoldProcessora  
    An ABC that provides hooks for dealing with italics and bold syntax.
    This class is set to trigger both before AND after the italics and bold stage.
    This allows any child classes to intercept instances of bold or italic syntax and
    change the output or hash it to prevent it from being processed.

    After the I&B stage any hashes in the `hash_tables` instance variable are replaced.
    zitalic-and-bold-processorrh   r  c                 4    t         |   ||       i | _        y rK  )superr   
hash_tabler   rh   r  	__class__s      r)   r   zItalicAndBoldProcessor.__init__	  s    W%r+   c                 v   | j                   j                  t        j                  k  rN| j                  j                  | j
                  |      }| j                  j                  | j
                  |      }|S d}||k7  r<|}| j                  j                         D ]  \  }}|j                  ||      } ||k7  r<|S rv  )
rh   ra   rK   rY   	strong_rer   em_rer  r   r   )r   rF   r  r   r  s        r)   rg   zItalicAndBoldProcessor.run	  s    77==5000>>%%dhh5D::>>$((D1D  It# 	#'??#8#8#: 5KC<<V4D5 t# r+   r   r"   c                 X    |j                   |j                         |j                          S rK  )r  r   r  rU  s     r)   r   zItalicAndBoldProcessor.sub	  s!     ||EKKM599;77r+   c                     |j                   |j                         |j                          }t        |      }|| j                  |<   |S rK  )r  r   r  r*   r  )r   r   r  r   s       r)   sub_hashzItalicAndBoldProcessor.sub_hash	  s;    ekkmUYY[9 %
r+   c                     | j                   j                  t        j                  k  r
d|v xs d|v S | j                  xr t        j                  d|      S )Nr  r  zmd5-[0-9a-z]{32})rh   ra   rK   rY   r  r   r   r   s     r)   rf   zItalicAndBoldProcessor.test	  sF    77==5000$;-#+-G299-@$#GGr+   )r.   r/   r0   r  rd   rK   rY   ra   rC   rR  r  rS  r  r   r   r   rg   r
   r   r  r   r   r  rf   __classcell__r  s   @r)   r  r  	  s     'D""$u'<'<&>>E##IOOE8 htn  8 8c 8 8bhh 3 Hr+   r  c                   :    e Zd ZU dZee   ed<   	 eed<   	 eed<   y)_LinkProcessorExtraOptsz%Options for the `LinkProcessor` extratagsinlinerefN)r.   r/   r0   r  r   r   r  r  r1   r+   r)   r  r  	  s!    /
s)ONL8	I;r+   r  )totalc                   n    e Zd ZU dZej
                  fej                  ffZee	d<   de
dee   f fdZdedededeeeeee   ef      fd	Zded
ededeeej&                     ef   fdZded
ededeeeee   ee   ef      fdZdeded
edeeef   fdZdeded
edeeef   fdZdefdZd Z xZS )r  zlink-processorr  rh   c                 2    |xs i }t         |   ||       y rK  r  r   r  s      r)   r   zLinkProcessor.__init__	  s    -RW%r+   rF   
_link_textr^  r"   c                    | j                   j                  ||dz         }|t        |      k(  ry|}||   dk(  }|r!| j                   j                  ||dz   dd      }| j                   j                  ||dd      }| j                   j                  j                  |||      }|sy|||j                          |j                  d      }	}|r&| j                   j                  j                  d|      }|||	|fS )	az  
        Parse a string and extract a link from it. This can be an inline anchor or an image.

        Args:
            text: the whole text containing the link
            link_text: the human readable text inside the link
            start_idx: the index of the link within `text`

        Returns:
            None if a link was not able to be parsed from `text`.
            If successful, a tuple is returned containing:

            1. potentially modified version of the `text` param
            2. the URL
            3. the title (can be None if not present)
            4. the index where the link ends within text
        r`   NrI  r|   ()r{  z\1)
rh   r  r   r  r  r   r   r   r  r   )
r   rF   r  r^  idxr_  has_anglebracketsr   rz  r{  s
             r)   parse_inline_anchor_or_imagez*LinkProcessor.parse_inline_anchor_or_image	  s    $ gg**4Q?#d) I,gg,,T719c3GG''((wSA**11$WE#ekkm,ekk'.BU''..225#>CS%((r+   	link_textc                 ^   d}|rt        j                  d||d       r| j                  j                  j                  |d|  d||d  |      }|rZ|j	                  d      j                         xs |j                         | j                  j                  v r|d|  d||d  }||fS d}||fS )a  
        Detects shortref links within a string and converts them to normal references

        Args:
            text: the whole text containing the link
            link_text: the human readable text inside the link
            start_idx: the index of the link within `text`

        Returns:
            A tuple containing:

            1. A potential `re.Match` against the link reference within `text` (will be None if not found)
            2. potentially modified version of the `text` param
        Nz[ ]?(?:\n[ ]*)?(?!\[)z[]ry  )r   r   rh   r  r   r  rt   )r   rF   r  r^  r   s        r)   process_link_shortrefsz$LinkProcessor.process_link_shortrefs	  s     ":D<LMGG66<<Zi@P?QQSTXYbYcTdSe=fhqrE
 KK%++-B1Btww||S":I./r$yz2B1CDD d{ !Ed{r+   c                    d}d| j                   j                  v r| j                  |||      \  }}|xs& | j                   j                  j	                  ||      }|sy|j                  d      j                         xs |j                         }| j                   j                  j                  |      }| j                   j                  j                  |      }|j                         }||||fS )a  
        Parse a string and extract a link from it. This can be a reference anchor or image.

        Args:
            text: the whole text containing the link
            link_text: the human readable text inside the link
            start_idx: the index of the link within `text`

        Returns:
            None if a link was not able to be parsed from `text`.
            If successful, a tuple is returned containing:

            1. potentially modified version of the `text` param
            2. the URL (can be None if the reference doesn't exist)
            3. the title (can be None if not present)
            4. the index where the link ends within text
        Nzlink-shortrefsry  )rh   r7   r  r  r   r   r  rt   r   ru   r  )	r   rF   r  r^  r   link_idrz  r{  url_end_idxs	            r)   parse_ref_anchor_or_ref_imagez+LinkProcessor.parse_ref_anchor_or_ref_image
  s    $ tww~~-55dIyQKE4R;;AA$	R++d#))+@y/@ggllw'""7+iikS%,,r+   rz  
title_attrc                    | j                   j                  d      }d| j                   j                  |       d| j                   j                  t	        |             d| | | j                   j
                   }|t        |      fS )a!  
        Takes a URL, title and link text and returns an HTML `<img>` tag

        Args:
            url: the image URL/src
            title_attr: a string containing the title attribute of the tag (eg: `' title="..."'`)
            link_text: the human readable text portion of the link

        Returns:
            A tuple containing:

            1. The HTML string
            2. The length of the opening HTML tag in the string. For `<img>` it's the whole string.
               This section will be skipped by the link processor
        imgz
<img src="z" alt="r   )rh   r  r  r  _xml_escape_attrr   r   )r   rz  r  r  img_class_strrj  s         r)   process_imagezLinkProcessor.process_image9
  s      88?--c23 4WW''(8(CDEQl=/$''*F*F)GI 	
 s6{""r+   c                     | j                   j                  r,| j                   j                  j                  |      sd| d}n"d| j                   j	                  |       d| d}| | dt        |      fS )a  
        Takes a URL, title and link text and returns an HTML `<a>` tag

        Args:
            url: the URL
            title_attr: a string containing the title attribute of the tag (eg: `' title="..."'`)
            link_text: the human readable text portion of the link

        Returns:
            A tuple containing:

            1. The HTML string
            2. The length of the opening HTML tag in the string. This section will be skipped
               by the link processor
        z<a href="#"r|   r  r   rq  )rh   r6   r  r   r  r   )r   rz  r  r  result_heads        r)   process_anchorzLinkProcessor.process_anchorQ
  su      77TWW%7%7%=%=c%B'
|15K%dgg&:&:3&?%@*QOKyk.K0@@@r+   c           	         d}d}d}	 	 |j                  d|      }t        |      }d}t        |dz   t	        ||z   |            D ]$  }||   }	|	dk(  r|dz  }|dk  s n|	dk(  s |dz  }& |dz   }j||dz   | }
| j
                  j                  r6| j
                  j                  |
      }
| j
                  j                  |
      }
d| j
                  j                  v r|
j                  d      rnt        j                  d	d
|
dd        }|| j
                  j                  v r5d| d| d| j
                  j                   d
| d	}|d | |z   ||dz   d  z   }n|dz   }U|dz  }|||dz    dk(  rd| j                  j!                  dd      s|dz   }| j#                  ||
|      }|s|dz   }|\  }}}}| j
                  j                  |d      }nL| j                  j!                  dd      s|dz   }| j%                  ||
|      }|s|dz   }|\  }}}}||}|j'                  d| j
                  j(                  d         j'                  d| j
                  j(                  d         }|r`t+        |      j'                  d| j
                  j(                  d         j'                  d| j
                  j(                  d         }d| d}nd}|dkD  xr ||dz
     dk(  }|rBd| j                  j!                  ddg      vr|dz   }|dz  }| j-                  |||
      \  }}nI||k\  r=d| j                  j!                  ddg      vr|dz   }J| j/                  |||
      \  }}n|dz   }hd| j
                  j                  v r)|j'                  d| j
                  j(                  d         }||z   }|t        |      z   }|d | |z   ||d  z   }# t        $ r Y |S w xY w)Ni  r   T[r`   ]r   r  r~  r   z$<sup class="footnote-ref" id="fnref-z"><a href="#fn-rp  z
</a></sup>r  r  )r  r  r  r  z title="r   r   !r  r  ro  r   )rZ  r   r   r[  r  rh   r6   r   r   r7   r   r   r   r   r   r  r   r  r  r   r   r  r  r  )r   rF   MAX_LINK_TEXT_SENTINELanchor_allowed_poscurr_posr^  text_lengthbracket_depthrf  r~  r  r   rj  parsedrz  r{  r  	title_stris_imgskips                       r)   rg   zLinkProcessor.runh
  sy   !%
   JJsH5	 d)K MAI 66D  !W9!Q&M$q(3Y!Q&M %q=Y]A.I ww   GG44Y?	 GG66yA	 dggnn,1E1Ec1JFF5#y}=	 1 11>yk J((1{"TWW5M5M4NaPY{Zdf 
  
+f4tAaCDzAD  !1uH FA
 Aa!e}#||''$7(1}H::4AN(1}H06-c5+gg0040@ ||''t4(1}H;;D)QO(1}H06-c5+;  !H
 dgg33C89dgg33C89 
 $U+WS$''"7"7"<=WS$''"7"7"<= 
 'ugQ/		 ]?tIaK'8C'?F 0 0% AA(1}HQ	#11#y)L00dll..vu==(1}H#223	9M %q=/TWW-B-B3-GH
 !4'H!*S[!8
#f,tKL/AADm $  J Ms   O 	O O c                     d|v xs d|v S )Nr  r  r1   r   s     r)   rf   zLinkProcessor.test  s    d{)cTk)r+   )r.   r/   r0   rd   rK   rY   rW   ra   r  r  rC   r   r   r   r   r   r   r  r   r  r  r  r  r  rg   rf   r  r  s   @r)   r  r  	  s   D""$u';';&==E$$&8 &htn & )  )#  )RU  )Zbchilnqs{|  tA  CF  jF  dG  [H  )D3 3 3 SXYabdbjbjYkmpYpSq @!-# !-# !-RU !-Zbchilnvwzn{  ~F  GJ  ~K  MP  jP  dQ  [R !-F# ## ## #%PSUXPX/ #0A# A3 A3 A5QTVYQY? A.b bH*r+   r  c                       e Zd ZdZdZej                  ej                  fdfZdZ	 e
j                  de	z  e
j                  e
j                  z  e
j                  z        Zd Zde
j"                  defd	Zd
 Zy)Admonitionsz+
    Enable parsing of RST admonitions
    admonitionsr1   zIadmonition|attention|caution|danger|error|hint|important|note|tip|warningaP  
        ^(\ *)\.\.\ (%s)::\ *                # $1 leading indent, $2 the admonition
        (.*)?                                # $3 admonition title
        ((?:\s*\n\1\ {3,}.*)+?)              # $4 admonition body (required)
        (?=\s*(?:\Z|\n{4,}|\n\1?\ {0,2}\S))  # until EOF, 3 blank lines or something less indented
        c                 <    | j                   j                  |      d uS rK  )admonitions_rer   r   s     r)   rf   zAdmonitions.test'  s    ""))$/t;;r+   r   r"   c                    |j                         \  }}}}d|z  }|j                         dk(  rd}nd|j                         z  }|rd|z  }| j                  j                  d| j                  j	                  |      d   z        }| j                  j                  dj                  |||      | j                  j                  d      }d	j                  ||      }| j                  j                  ||d      S )
Nz<strong>%s</strong>
admonitionzadmonition %s<em>%s</em>
%s
r`   z
{}
{}

{}
Fz<aside class="{}">
{}</aside>)rw  r  rh   r   r  r  r  r   )	r   r   lead_indentadmonition_namer{  bodyadmonition_typeadmonition_classr   s	            r)   r   zAdmonitions.sub*  s    49LLN1_eT//A   "l2+.1F1F1HH !E)E ww''4773K3KD3QRS3T(TU WW,,##OUDAGGKK


 6<<=MzZ
ww&&z;FFr+   c                 N    | j                   j                  | j                  |      S rK  )r  r   r   s     r)   rg   zAdmonitions.runF  s    ""&&txx66r+   N)r.   r/   r0   r  rd   rK   rO   rN   ra   r  r   r   r  r  r  r  rf   r  r   r   rg   r1   r+   r)   r  r    s     D0"4E^KRZZ !
 ! 	$rzz1N<G Gc G87r+   r  c                       e Zd ZdZdZdej                  ffZ ej                  dej                        Zd Zdej                  defdZd	 Zy
)Alertsz
    Markdown Alerts as per
    https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
    alertsr1   z
        <blockquote>\s*
        <p>
        \[!(?P<type>NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]
        (?P<closing_tag></p>[ \t]*\n?)?
        (?P<contents>[\s\S]+?)
        </blockquote>
    c                 
    d|v S )Nz<blockquote>r1   r   s     r)   rf   zAlerts.test]  s    %%r+   r   r"   c                     |d   j                         }d|d   j                          d}|d   j                         }|d   rd| d| d| d	S d| d| d
| d	S )Nr  z<em>z</em>contentsclosing_tagz<div class="alert z">
r   
</div>z
<p>)r  r{  r   )r   r   typheadingr.  s        r)   r   z
Alerts.sub`  s    Fm!!#v,,./u5$**,'uD	H:XNN'uD	xjQQr+   c                 N    | j                   j                  | j                  |      S rK  )alert_rer   r   s     r)   rg   z
Alerts.runi  s    }}  400r+   N)r.   r/   r0   r  rd   rK   rS   ra   r   r   rp  r4  rf   r  r   r   rg   r1   r+   r)   r*  r*  J  sc    
 D##&&Erzz  
H&R Rc R1r+   r*  c                   (    e Zd ZU dZeed<   	 eed<   y)_BreaksExtraOptszOptions for the `Breaks` extraon_backslashr   Nr.   r/   r0   r  r  r  r1   r+   r)   r6  r6  m  s    (<@r+   r6  c                   @    e Zd ZU dZdej
                  ffZeed<   d Z	y)Breaksr   r1   r  c                    | j                   j                  dd      }| j                   j                  dd      }|r|rd}n|rd}n|rd}nd}d| j                  j                  z  }t	        j
                  |d	z   ||      }|S )
Nr7  Fr   z *\\?z(?: *\\| {2,})z *z {2,}r  z\n(?!\<(?:\/?(ul|ol|li))\>))r  r   rh   r   r   r   )r   rF   r7  r   pattern	break_tags         r)   rg   z
Breaks.runz  s~    ||''>\\%%lE:
JG'GGG < <<	vvg >>	4Pr+   N)
r.   r/   r0   rd   rK   rY   ra   r6  r  rg   r1   r+   r)   r:  r:  u  s%    D&&((Er+   r:  c                   D     e Zd ZdZdZdej                  def fdZ xZ	S )CodeFriendlyz-
    Disable _ and __ for em and strong.
    zcode-friendlyr   r"   c                 V   |j                  d      }|j                  |j                         |j                          }d|v rt	        |      }|| j
                  |<   |S d|v r:|t        |      t        |        }t	        |      }|| j
                  |<   ||z   |z   S t        | !  |      S )Nr`   r  )	r   r  r   r  r*   r  r   r  r   )r   r   syntaxrF   r   r  s        r)   r   zCodeFriendly.sub  s    QLL		<&=T"C#'DOOC JD[Fc&k\2DT"C#'DOOC C<&((w{5!!r+   )
r.   r/   r0   r  rd   r   r  r   r   r  r  s   @r)   r?  r?    s+     D" "c " "r+   r?  c                   *   e Zd ZdZdZej                  ej                  fej                  ffZ	 e
j                  de
j                  e
j                  z  e
j                  z        Zd ZdededefdZd	edeeef   fd
Zde
j*                  defdZd Zy)FencedCodeBlocksz
    Allows a code block to not have to be indented
    by fencing it with '```' on a line before and after. Based on
    <http://github.github.com/github-flavored-markdown/> with support for
    syntax highlighting.
    r  a"  
        (?:\n+|\A\n?|(?<=\n))
        (^[ \t]*`{3,})\s{0,99}?([\w+-]+)?\s{0,99}?\n  # $1 = opening fence (captured for back-referencing), $2 = optional lang
        (.*?)                             # $3 = code block content
        \1[ \t]*\n                      # closing fence
        c                 R   d|vry| j                   j                  t        j                  k(  r| j                   j                  sy| j                   j                  t        j
                  k(  r| j                   j                  ry| j                   j                  t        j                  k(  S )Nz```FT)rh   r\   rK   rL   r6   rN   rO   r   s     r)   rf   zFencedCodeBlocks.test  sn    77==E,,,TWW5F5F77==EOO+0A0Aww}} 1 111r+   r#  leading_indentr"   c                      j                   j                  d   xs i } fd} j                   j                  ||      \  }} ||      }  j                   j                  ||fi |}d j                   j	                  ||d      z  S )z
        Args:
            codeblock: the codeblock to format
            leading_indent: the indentation to prefix the block with
            lexer (pygments.Lexer): the lexer to use
        r  c                     t        j                  j                  j                               D ]  \  }}| j	                  ||      }  g d}|D ]  \  }}| j	                  ||      }  | S )N))r  r  )r  rI  )r  r|   )r  rh   rw   r   r   )r#  r   r  r  oldnewr   s         r)   unhash_codez@FencedCodeBlocks._code_block_with_lexer_sub.<locals>.unhash_code  st    "&tww'9'9'?'?'A"B >Y%--c9=	>L
 ) 8S%--c37	8r+   r  r"  T)rh   r7   r  r=  r  )r   r#  rE  r:  r;  rJ  r  coloreds   `       r)   _code_block_with_lexer_subz+FencedCodeBlocks._code_block_with_lexer_sub  s     (<=C
	 ww//	~/V9	*	.$''..y% A1?A $''11'>4PPPr+   r  c                     | j                   j                  d      }d| j                   j                  v r|rdj                  ||      }n| j                   j                  d      }dj                  ||      dfS )aT  
        Returns the tags that the encoded code block will be wrapped in, based
        upon the lexer name.

        This function can be overridden by subclasses to piggy-back off of the
        fenced code blocks syntax (see `Mermaid` extra).

        Returns:
            The opening and closing tags, as strings within a tuple
        r?  highlightjs-langz class="{} language-{}"r  z<pre{}><code{}>z</code></pre>)rh   r  r7   r  )r   r  	pre_class
code_classs       r)   r  zFencedCodeBlocks.tags  sh     GG44U;	/J299*jQJ99&AJ!((J?QQr+   r   c                    |j                  d      }|j                  d      }|d d }|rd| j                  j                  vrv| j                  j                  |      }|rYdt	        |j                  d            t	        |j                  d      j                               z
  z  }| j                  |||      S dt	        |j                  d            t	        |j                  d      j                               z
  z  }|r | j                  j                  ||      \  }}| j                  j                  |      }| j                  |      }dj                  ||d	   |||d         S )
Nr   r   r  rO  r}   r`   rK  z
{}{}{}
{}{}
r   )r   rh   r7   r"  r   r   rM  r  rA  r  r  )r   r   r  r#  r:  rE  r  s          r)   r   zFencedCodeBlocks.sub  s7   [[^
KKN	crN	 ,DGGNNBGG//
;E!$c%++a.&9CA@U@U@W<X&X!Y66y.RWXX EKKN 3c%++a.:O:O:Q6R RS(,(@(@Xf(@(g%NIGG((3	yy$!((a)^]abc]deer+   c                 N    | j                   j                  | j                  |      S rK  )fenced_code_block_rer   r   s     r)   rg   zFencedCodeBlocks.run  s    ((,,TXXt<<r+   N)r.   r/   r0   r  rd   rK   rN   rO   rL   ra   r   r   r   rp  r  rT  rf   r   rM  r  r  r  r   rg   r1   r+   r)   rC  rC    s      D__e//053C3C2EEE%2:: '
 TTBDD[244!2!Q!Q !Q
 
!QFRs RuS#X R$f fc f0=r+   rC  c                   J   e Zd ZdZdZej                  efdfZ e	j                  d      Z e	j                  de	j                        Z e	j                  de	j                        Z e	j                  de	j                        Z e	j                  d      Zd	Zi Zd
 Zd Zd Zd Zy	)LatexzP
    Convert $ and $$ to <math> and </math> tags for inline and block math.
    latexr1   z(?<!\$)\$(?!\$)(.*?)\$z\$\$(.*?)\$\$z<pre>(.*?)</pre>z```(.*?)```z(?<!`)(`)(.*?)(?<!`)\1(?!`)Nc                 V    | j                   j                  |j                  d            S r   )	converterrD   r   rU  s     r)   _convert_single_matchzLatex._convert_single_match#  s    ~~%%ekk!n55r+   c                 z    | j                   j                  |j                  d      j                  dd      d      S )Nr`   z\nr   ri  )display)rY  rD   r   r   rU  s     r)   _convert_double_matchzLatex._convert_double_match&  s2    ~~%%ekk!n&<&<UB&GQX%YYr+   c                 t    dt        | j                         d}|j                  d      | j                  |<   |S )Nz<!--CODE_BLOCK_rQ  r   )r   code_blocksr   )r   r   placeholders      r)   code_placeholderzLatex.code_placeholder)  s:    'D,<,<(='>cB(-A%r+   c                 F   	 dd l }|j                  | _        | j                  j	                  | j
                  |      }| j                  j	                  | j
                  |      }| j                  j	                  | j
                  |      }| j                  j	                  | j                  |      }| j                  j	                  | j                  |      }| j                  j                         D ]  \  }}|j                  ||      } |S # t        $ r t        d      w xY w)Nr   zFThe "latex" extra requires the "latex2mathml" package to be installed.)latex2mathml.converterrY  r  _pre_code_block_rer   ra  
_single_re
_triple_re_single_dollar_rerZ  _double_dollar_rer]  r_  r   r   )r   rF   latex2mathmlr`  
code_blocks        r)   rg   z	Latex.run.  s   	h))33DN
 &&**4+@+@$G""4#8#8$?""4#8#8$?%%))$*D*DdK%%))$*D*DdK (,'7'7'='='? 	9#K<<Z8D	9   	hfgg	hs   D D )r.   r/   r0   r  rd   rK   rR   rC  ra   r   r   rg  r  rh  rd  rf  re  rY  r_  rZ  r]  ra  rg   r1   r+   r)   rV  rV    s     D 0125E"

#<="

#3RYY? $$7CNBII6J:;JIK6Z
r+   rV  c                   n    e Zd ZU dZdZej                  fdfZee	d<    e
j                  d      Zd Zd Zy)	LinkPatternszn
    Auto-link given regex patterns in text (e.g. bug number
    references, revision number references).
    r   r1   r  z!?\[.*?\]\(.*?\)c                 l    i } j                   D ]  \  }}g }|j                        D ]_  t         fd|D              rt        |      r	 |      }nj	                  |      }|j                  j                         |f       a t        |      D ]_  \  \  }dz
   dk(  rdz    dk(  r!dz
   dk(  sdz    dk(  r8dz
   d	k(  r#dz    d	k(  rd dz
    z   dz   d  z   fd
} j                  j                   j                  fD ]=  }|j                        D ]%  t        fdj                  D              s#d} n = n |r|j                  dd      j                  d j                  j                  d         j                  d j                  j                  d         }	dj                  |	       }
t        |
      }|
||<   d  |z   d  z   b  t!        |j#                               D ]  \  }}
j                  ||
       S )Nc              3   X   K   | ]!  }j                   j                  |       # y wrK  )rh   r  )r  hr   r   rF   s     r)   r  z#LinkPatterns.run.<locals>.<genexpr>T  s$     ^!tww55dE1E^s   '*r`   r  r  r   z](z")r   z"""Fc              3   B   K   | ]  }|d    k  xr |d   k    yw)r   r`   Nr1   )r  r>   r  r   s     r)   r  z#LinkPatterns.run.<locals>.<genexpr>o  s)     S1! =#1+ =Ss   Tr   &quot;r  r  r  )r  r  anycallableexpandr   r  r  rh   r  _basic_link_reregsr   r   r  r*   r  r   )r   rF   link_from_hashregexreplr  hrefis_inside_linklink_reescaped_hreflinkr  r  r   r   s   ``          @@@r)   rg   zLinkPatterns.runO  s   << 2	8KE4L- :^~^^D>;D <<-D##UZZ\4$89: '/|&< '8"d 	%(C/DS1W4E4L 	%(D0DS1W4E4M 	%(E1d3sQw6G56P
+d5o=S1WXND "' $ 5 5t7J7JK 	G!(!1!1$!7 !S

SS .2N!! !	 " LLh/ dgg&;&;C&@A dgg&;&;C&@A	 
 -33L$uS/R!$''+t$FU|d*T#$Z7O'82	8f ~3356 	,JD$<<d+D	,r+   c                      yNTr1   r   s     r)   rf   zLinkPatterns.test      r+   N)r.   r/   r0   r  rd   rK   rX   ra   r  r  r   r   ru  rg   rf   r1   r+   r)   rl  rl  D  s@     D[[NBERZZ 34N7rr+   rl  c                   >    e Zd ZdZdZdej                  ffZd Zd Z	y)MarkdownInHTMLz
    Allow the use of `markdown="1"` in a block HTML tag to
    have markdown processing be done on its contents. Similar to
    <http://michelf.com/projects/php-markdown/extra/#markdown-attr> but with
    some limitations.
    r8  r1   c                 r      fd} j                   j                  | j                   j                  |d      S )Nc                     j                   j                  |       \  }} j                   j                  |       } j                   j                  | |dd      } | S )NTF)r  r  )rh   r  rG  r  )ri  r  r   s     r)   rb  z$MarkdownInHTML.run.<locals>.callback  sR     GG44U;MFEGG007EGG++E6thm+nELr+   T)rh   rU  rV  )r   rF   rb  s   `  r)   rg   zMarkdownInHTML.run  s0    	 ww,,T4773H3H(TXYYr+   c                      yr  r1   r   s     r)   rf   zMarkdownInHTML.test  r  r+   N)
r.   r/   r0   r  rd   rK   rM   ra   rg   rf   r1   r+   r)   r  r    s*     D""EZr+   r  c                       e Zd ZU dZeed<   y)_MarkdownFileLinksExtraOptsz)Options for the `MarkdownFileLinks` extra	link_defsNr8  r1   r+   r)   r  r    s    3ODr+   r  c                        e Zd ZU dZdZej                  fej                  ffZe	e
d<   dedee   f fdZdededef fd	Zdef fd
Z fdZ xZS )MarkdownFileLinksz9
    Replace links to `.md` files with `.html` links
    zmarkdown-file-linksr  rh   c                 >    dgdd|xs i }t         |   ||       y )Nro  F)r  r  r  r  s      r)   r   zMarkdownFileLinks.__init__  s'    5B7=bBW%r+   rF   r  r^  c                     t         |   |||      }|r|d   r|d   j                  d      sy |d   j                  d      dz   }|d   |g|dd  S )Nr`   .md.htmlr   r   )r  r  r!  removesuffix)r   rF   r  r^  rj  rz  r  s         r)   r  z.MarkdownFileLinks.parse_inline_anchor_or_image  sh    5dJ	RVAYfQi.@.@.G Qi$$U+g5ay#*qr
**r+   c                    t         j                  | j                  j                  cxkD  rt         j                  kD  rn n| j
                  j                  dd      ri| j                  j                  j                         D ]B  \  }}|j                  d      s|j                  d      dz   | j                  j                  |<   D t        | 1  |      S )Nr  Tr  r  )rK   rX   rh   ra   rN   r  r   rt   r   r!  r  r  rg   )r   rF   r   rz  r  s       r)   rg   zMarkdownFileLinks.run  s    ;;88T\\=M=Mk[_=` GGLL..0 JS<<&(+(8(8(?'(IDGGLL%J w{4  r+   c                 .    t         |   |      xr d|v S )Nr  )r  rf   r   rF   r  s     r)   rf   zMarkdownFileLinks.test  s    w|D!3etm3r+   )r.   r/   r0   r  rd   rK   rX   rN   ra   r  r  rC   r   r   r   r   r   r  rg   rf   r  r  s   @r)   r  r    st     !D[[NU__..E((&8 &htn &
+ +# +RU +! !4 4r+   r  c                   ,     e Zd ZdZefdfZ fdZ xZS )Mermaidmermaidr1   c                 .    |dk(  ryt         |   |      S )Nr  )z.<pre class="mermaid-pre"><div class="mermaid">z</div></pre>)r  r  )r   r  r  s     r)   r  zMermaid.tags  s    "Uw|J''r+   )r.   r/   r0   rd   rC  ra   r  r  r  s   @r)   r  r    s    D#E( (r+   r  c                        e Zd ZdZdZefej                  ffZde	de
eedf   f fdZ fdZdej                   d	ef fd
Z xZS )MiddleWordEmz
    Allows or disallows emphasis syntax in the middle of words,
    defaulting to allow. Disabling this means that `this_text_here` will not be
    converted to `this<em>text</em>here`.
    zmiddle-word-emrh   r  Nc                    t        |t              rd|i}n|xs i }|j                  dd       t        |   ||       | j
                  | _        |d   st        j                  d| j
                  j                  z  | j
                  j                        | _        t        j                  dt        j                  t        j                  z        | _        yy)aq  
        Args:
            md: the markdown instance
            options: can be bool for backwards compatibility but will be converted to a dict
                in the constructor. All options are:
                - allowed (bool): whether to allow emphasis in the middle of a word.
                    If `options` is a bool it will be placed under this key.
        allowedTz(?<=\b)%s(?=\b)a  
                    (                # \1 - must be a single em char in the middle of a word
                        (?<![*_\s])  # cannot be preceeded by em character or whitespace (must be in middle of word)
                        [*_]         # em character
                        (?![*_])     # cannot be followed by another em char
                    )
                    (?=\S)           # em opening must be followed by non-whitespace text
                    (.*?\S)          # the emphasized text
                    \1               # closing char
                    (?!\s|$)         # must not be followed by whitespace (middle of word) or EOF
                N)r   r  r   r  r   r  liberal_em_rer   r   r<  flagsr  rp  r  s      r)   r   zMiddleWordEm.__init__  s     gt$ '*GmG9d+W%!ZZy!$69K9K$KTZZM]M]^DJ!#
 $$+"D "r+   c                     | j                   d   r|S t        | 	  |      }| j                  j                  | j                  j
                  k  r&| j                  j                  | j                  |      }|S )Nr  )	r  r  rg   rh   ra   r\   r  r   r  r  s     r)   rg   zMiddleWordEm.run  s]    <<	"K w{4 77==477==(%%))$-->Dr+   r   r"   c                     |j                  d      }t        |      dk7  rt        |   |      S d|j                  d      z  S )Nr`   r!  r   )r   r   r  r   )r   r   rA  r  s      r)   r   zMiddleWordEm.sub  s>    Qv;!7;u%%u{{1~--r+   )r.   r/   r0   r  rd   r?  rK   rY   ra   rC   r   r   r  r   rg   r   r  r   r   r  r  s   @r)   r  r    se    
 DOe3355E8 eD$4D.E B. .c . .r+   r  c                   8    e Zd ZdZdZej                  fdfZd Zy)	Numberingz
    Support of generic counters.  Non standard extension to
    allow sequential numbering of figures, tables, equations, exhibits etc.
    	numberingr1   c                    t        j                  dt         j                        }t        j                  d      }i }i }g }d}d}|j                  |      D ]  }	t	        |	j                               dk7  r |	j                  d      }
|	j                  d      j                         }|	j                  d      }|	j                  d      }|j                  |
d      }||
f||<   |j                  |	j                  d	      |j                  |
||||      |	j                  d	      f       |dz   ||
<    t        |      D ]  }|d |d	    |d   z   ||d   d  z   } t        t        |j                  |                  D ]  }	|j                  |	j                  d      d
      \  }}
|#|j                  |
|	j                  d      |      }n7|j                  |	j                  d      dd|	j                  d      z   dz         }d| j                  j                   v r)|j#                  d| j                  j$                  d         }|d |	j                          |z   ||	j                         d  z   } |S )Na(  
            \[\#(\w+) # the counter.  Open square plus hash plus a word \1
            ([^@]*)   # Some optional characters, that aren't an @. \2
            @(\w+)       # the id.  Should this be normed? \3
            ([^\]]*)\]   # The rest of the text up to the terminating ] \4
            z\[@(\w+)\s*\]z><figcaption class="{}" id="counter-ref-{}">{}{}{}</figcaption>z+<a class="{}" href="#counter-ref-{}">{}</a>r   r`   r   r   r   r  countererror?r   r   )r   r   r  r  r   rw  r   r   r   r   r   r  r  r  r  rh   r7   r   r   )r   rF   regex_defns
regex_subscounters
referencesr  definition_htmlreference_htmlr   countertext_beforeref_id
text_afternumberry  s                   r)   rg   zNumbering.run  sh   jj "
  ZZ 01

ZF ))$/ 	+E5<<>"a'kk!nG++a...0K[[^FQJ\\'1-F"('!2JvQ!0!7!78>8C8>8B	"D
 "'1!/ 0 !'
HW#	+$ \* 	=Da>DG+d478n<D	= d:#6#6t#<=> 	DE(nnU[[^\JOFG!%,,W-2[[^-35 &,,U[[^-;-05;;q>-AC-GI /||C)>)>s)CD'$.eiikl1CCD	D r+   N)	r.   r/   r0   r  rd   rK   rN   ra   rg   r1   r+   r)   r  r    s$    
 D__"E5r+   r  c                   b    e Zd ZdZdZdej                  ffZd Zde	j                  defdZd Zy	)
PyShellzS
    Treats unindented Python interactive shell sessions as <code>
    blocks.
    pyshellr1   c                 
    d|v S )Nz>>>r1   r   s     r)   rf   zPyShell.test`  s    }r+   r   r"   c                    d| j                   j                  v rHt        |j                  d            }| j                   j                  d   j                  d|z   dz         S |j                  d      j                  d      }t        |       d| j                   j                  z  }d|z   d|z   j                  |      z   dz   }|S )Nr  r   z	```pycon
z```
r}   r   )
rh   r7   r  r   re   rg   r  _dedentlinesr5   r6  )r   r   dedentedr)  r  r!   s         r)   r   zPyShell.subc  s    477>>1u{{1~.H77(()=>BB<RZCZ]dCdeeA))!,Utww(((f**512 r+   c                     | j                   j                  dz
  }t        j                  d|z  t        j                  t        j
                  z        }|j                  | j                  |      S )Nr`   z
            ^([ ]{0,%d})>>>[ ].*\n  # first line
            ^(\1[^\S\n]*\S.*\n)*    # any number of subsequent lines with at least one character
            (?=^\1?\n|\Z)           # ends with a blank line or end of document
            rh   r5   r   r   r   rp  r   )r   rF   rs  _pyshell_block_res       r)   rg   zPyShell.runp  s^    ))A-JJ (  	(  "$	. !$$TXXt44r+   N)r.   r/   r0   r  rd   rK   rQ   ra   rf   r   r  r   r   rg   r1   r+   r)   r  r  W  s?    
 DE c 5r+   r  c                   
   e Zd ZdZdZdej                  ffZ ej                  d      Z
 ej                  d      Z ej                  d      Z ej                  d      Z ej                  d      Zg d	Zd
edefdZd Zd Zy)SmartyPantsz
    Replaces ' and " with curly quotation marks or curly
    apostrophes.  Replaces --, ---, ..., and . . . with en dashes, em dashes,
    and ellipses.
    r   r1   z(?<!\S)'(?=\S)z(?<!\S)"(?=\S)z(?<=\S)'z(?<=\S)"(?=(\s|,|;|\.|\?|!|$))z'(\d\d)(?=(\s|,|;|\.|\?|!|$)))tistwastwerneathor  roundbouttwixtnufffraidsuprF   r"   c                     | j                   j                  d|      }| j                  D ]N  }|j                  d|z  d|z        }|j                  d|j	                         z  d|j	                         z        }P |S )Nz	&#8217;\1z'%sz	&#8217;%s)_apostrophe_year_rer   _contractionsr   
capitalize)r   rF   rK  s      r)   contractionszSmartyPants.contractions  sw    ''++L$?## 	.A<<	;?;D<< 6alln,.D	. r+   c                 (   d|v rI| j                  |      }| j                  j                  d|      }| j                  j                  d|      }d|v r8| j                  j                  d|      }| j
                  j                  d|      }|j                  dd      }|j                  d	d
      }|j                  dd      }|j                  dd      }|j                  dd      }d| j                  j                  v rd|v r|j                  dd      }|S )a  Fancifies 'single quotes', "double quotes", and apostrophes.
        Converts --, ---, and ... into en dashes, em dashes, and ellipses.

        Inspiration is: <http://daringfireball.net/projects/smartypants/>
        See "test/tm-cases/smarty_pants.text" for a full discussion of the
        support here and
        <http://code.google.com/p/python-markdown2/issues/detail?id=42> for a
        discussion of some diversion from the original SmartyPants.
        r   z&#8216;z&#8217;r   z&#8220;z&#8221;r   z&#8212;--z&#8211;...z&#8230;z . . . . . .r   zfootnote-refzclass="footnote-ref&#8221;zclass="footnote-ref")	r  _opening_single_quote_rer   _closing_single_quote_re_opening_double_quote_re_closing_double_quote_rer   rh   r7   r   s     r)   rg   zSmartyPants.run  s    $;$$T*D0044YED0044YED$;0044YED0044YED||E9-||D),||E9-||Iy1||GY/ $''..(^t-C << <>TUDr+   c                 ,    t        fddD              S )Nc              3   &   K   | ]  }|v  
 y wrK  r1   )r  r*  rF   s     r)   r  z#SmartyPants.test.<locals>.<genexpr>  s      19 s   )r   r   r  r  r  )rr  r   s    `r)   rf   zSmartyPants.test  s      '
   	r+   N)r.   r/   r0   r  rd   rK   rU   ra   r   r   r  r  r  r  r  r  r   r  rg   rf   r1   r+   r)   r  r  {  s    
 D!!##E)rzz*;<)rzz*;<)rzz+6)rzz*KL
 %"**%EF:M  Br+   r  c                   x    e Zd ZdZdZej                  fdfZ ej                  dej                        Zd Zd Zy)Strikez:
    Text inside of double tilde is ~~strikethrough~~
    striker1   z~~(?=\S)(.+?)(?<=\S)~~c                 :    | j                   j                  d|      S )Nz	<s>\1</s>)
_strike_rer   r   s     r)   rg   z
Strike.run  s    ""<66r+   c                 
    d|v S )Nz~~r1   r   s     r)   rf   zStrike.test      t|r+   N)r.   r/   r0   r  rd   rK   rY   ra   r   r   r  r  rg   rf   r1   r+   r)   r  r    sB     D""$b(E5rtt<J7r+   r  c                   \    e Zd ZdZdZdej                  ffZd Zde	j                  defdZy)	Tablesz
    Tables using the same format as GFM
    <https://help.github.com/articles/github-flavored-markdown#tables> and
    PHP-Markdown Extra <https://michelf.ca/projects/php-markdown/extra/#table>.
    tablesr1   c                     | j                   j                  dz
  }t        j                  d|||fz  t        j                  t        j
                  z        }|j                  | j                  |      S )zCopying PHP-Markdown and GFM table syntax. Some regex borrowed from
        https://github.com/michelf/php-markdown/blob/lib/Michelf/Markdown.php#L2538
        r`   a  
                (?:(?<=\n)|\A\n?)             # leading blank line

                ^[ ]{0,%d}                      # allowed whitespace
                (.*[|].*)[ ]*\n                   # $1: header row (at least one pipe)

                ^[ ]{0,%d}                      # allowed whitespace
                (                               # $2: underline row
                    # underline row with leading bar
                    (?:  \|\ *:?-+:?\ *  )+  \|? \s?[ ]*\n
                    |
                    # or, underline row without leading bar
                    (?:  \ *:?-+:?\ *\|  )+  (?:  \ *:?-+:?\ *  )? \s?[ ]*\n
                )

                (                               # $3: data rows
                    (?:
                        ^[ ]{0,%d}(?!\ )         # ensure line begins with 0 to less_than_tab spaces
                        .*\|.*[ ]*\n
                    )*
                )
            r  )r   rF   rs  table_res       r)   rg   z
Tables.run  sh     ))A-:: * !-?+@* BD+N, ||DHHd++r+   r   r"   c                    d}d}d}d}|j                         \  }}}t        j                  |t        j                  |dt        j                  |d|                  D 	cg c]'  }	t        j                  |d|	j	                               ) }
}	i }t        |
      D ]7  \  }}|d   dk(  r|d	   dk(  rd
||<   |d   dk(  rd||<   *|d	   dk(  s3d||<   9 d| j                  j                  d      z  d| j                  j                  d      z  dg}t        j                  |t        j                  |dt        j                  |d|                  D 	cg c]'  }	t        j                  |d|	j	                               ) }
}	t        |
      D ]O  \  }}|j                  dj                  |j                  |d      | j                  j                  |                   Q |j                  d       |j                  d       |j	                  d      }|r'|j                  d       |j                  d      D ]  }|j                  d       t        j                  |t        j                  |dt        j                  |d|                  D 	cg c]'  }	t        j                  |d|	j	                               ) }
}	t        |
      D ]O  \  }}|j                  dj                  |j                  |d      | j                  j                  |                   Q |j                  d        |j                  d       |j                  d       dj                  |      dz   S c c}	w c c}	w c c}	w )Nz	^\s+|\s+$z^\||\|$z^\||(?<![\`\\])\|z\\\|r   |r   r   r  z style="text-align:center;"z style="text-align:left;"z style="text-align:right;"	<table%s>table	<thead%s>thead<tr>z  <th{}>{}</th></tr></thead>r   <tbody>z  <td{}>{}</td></tbody></table>)rw  r   r   r   r   r   rh   r  r   r  r   rL  r6  )r   r   trim_space_retrim_bar_resplit_bar_reescape_bar_rer$  	underliner%  cellcolsalign_from_col_idxcol_idxcolhlinesr+  s                   r)   r   z
Tables.sub  s   $ + %i FHXXl\^\b\bcnprtvtztz  |I  KM  OX  uY  ]Z  F[  \T}c4::<8  \  \%dO 	KLGS1v}RC.K"7+Q3.I"7+RC.J"7+	K  @ @ II;Y]Y`Y`YyYy  {B  ZC  LC  EK  LEGXXl\^\b\bcnprtvtztz  |I  KM  OS  uT  ]U  FV  WT}c4::<8  W  W%dO 	LGSMM+22"&&w3'', 	
 	gj! zz$MM)$

4( 'f%MOXXVbdfdjdjkvxz|~  }C  }C  DQ  SU  W[  }\  e]  N^  _T}c4::<@  _  _$-dO LGSMM"3":":*..w;//4# 
 g&' MM*%j!yy 4''K \ W _s   ,M ,M%,M*N)r.   r/   r0   r  rd   rK   rQ   ra   rg   r   r  r   r   r1   r+   r)   r  r    s:    
 DE,:.( .(c .(r+   r  c                   t    e Zd ZdZdej
                  ffZ ej                  dej                        Z
d Zd Zy)TelegramSpoilerz
tg-spoilerr1   z\|\|\s?(.+?)\s?\|\|c                 :    | j                   j                  d|      S )Nz<tg-spoiler>\1</tg-spoiler>)_tg_spoiler_rer   r   s     r)   rg   zTelegramSpoiler.run1  s    ""&&'EtLLr+   c                 
    d|v S Nz||r1   r   s     r)   rf   zTelegramSpoiler.test4  r  r+   N)r.   r/   r0   rd   rK   rY   ra   r   r   r  r  rg   rf   r1   r+   r)   r  r  +  s<    D&&((ERZZ 6=NMr+   r  c                   x    e Zd ZdZdZej                  fdfZ ej                  dej                        Zd Zd Zy)	Underlinez7
    Text inside of double dash is --underlined--.
    r  r1   z.(?<!<!)--(?!>)(?=\S)(.+?)(?<=\S)(?<!<!)--(?!>)c                 :    | j                   j                  d|      S )Nz	<u>\1</u>)_underline_rer   r   s     r)   rg   zUnderline.runA  s    !!%%lD99r+   c                 
    d|v S )Nr  r1   r   s     r)   rf   zUnderline.testD  r  r+   N)r.   r/   r0   r  rd   rK   rY   ra   r   r   r  r  rg   rf   r1   r+   r)   r  r  8  sE     D""$b(EBJJPRTRVRVWM:r+   r  c                       e Zd ZU dZeed<   y)_WavedromExtraOptsz Options for the `Wavedrom` extraprefer_embed_svgNr8  r1   r+   r)   r  r  H  s    *r+   r  c                   p    e Zd ZU dZdZej                  efdfZe	e
d<   d Zdej                  defdZd	 Zy
)WavedromzA
    Support for generating Wavedrom digital timing diagrams
    wavedromr1   r  c                 t    t         j                  j                  |      }|d u xs |j                  d      dk(  S )Nr   r
  )rC  rT  r   r   )r   rF   r   s      r)   rf   zWavedrom.test[  s4     55<<TB}<A* <<r+   r   r"   c                    | j                   j                  |j                  d            \  }}d\  }}| j                  j	                  dd      }|r)	 dd l}|j                  |      j                         }d\  }}t        |      | j                   j                  |<   | j                   j                  dj                  || j                   j                  |   |      |d      S # t        $ r Y sw xY w)	Nr   )z<script type="WaveDrom">
z	</script>r  Tr   )z<div>r0  z
{}{}{}
)r  )rh   r  r   r  r   r
  rendertostringr  r*   r   r  r  )r   r   r#  wavesopen_tag	close_tag	embed_svgr
  s           r)   r   zWavedrom.sub_  s    !WW55ekk!nEUG) LL$$%7>	 .779&9#)
 (2%'8e$ww&&$''*?*?*F	RT ' 
 	
  s   (C" "	C.-C.c                 V    t         j                  j                  | j                  |      S rK  )rC  rT  r   r   s     r)   rg   zWavedrom.runx  s    44884HHr+   N)r.   r/   r0   r  rd   rK   rR   rC  ra   r  r  rf   r   r  r   r   rg   r1   r+   r)   r	  r	  S  sL     D 0125E=
 
c 
2Ir+   r	  c                   N    e Zd ZdZdZefdfZd Zdej                  de
fdZd Zy	)

WikiTableszk
    Google Code Wiki-style tables. See
    <http://code.google.com/p/support/wiki/WikiSyntax#Tables>.
    zwiki-tablesr1   c                     | j                   j                  dz
  }t        j                  d|z  t        j                  t        j
                  z        }|j                  | j                  |      S )Nr`   z
            (?:(?<=\n\n)|\A\n?)            # leading blank line
            ^([ ]{0,%d})\|\|.+?\|\|[ ]*\n  # first line
            (^\1\|\|.+?\|\|\n)*        # any number of subsequent lines
            r  )r   rF   rs  wiki_table_res       r)   rg   zWikiTables.run  s]    ))A-

 $  	$  "$	.
   400r+   r   r"   c                 |   	
 |j                  d      j                         }g }|j                  d      D ]e  }|j                         dd j                         }t        j                  d|      D cg c]  }|j                          }}|j                  |       g g 
d
 fd	}	 fd} |d j                  j                  d      z         |r|d   r~t        j                  d	|d   d         rb |d
 j                  j                  d      z  d        |dd       |d   D ]  	 |d |	       dd         |dd        |dd       |dd  }|rE |dd       |D ].  } |dd       |D ]  	 |d |	       dd         |dd       0  |dd        |d       dj                  
      dz   S c c}w )Nr   r   z(?<!\\)\|\|c                 \    j                  j                  j                  |z  | z          y rK  )r   rh   r   )r+  indentsr  r   s     r)   	add_hlinez!WikiTables.sub.<locals>.add_hline  s!    MM477;;0D89r+   c                     j                   j                  t        j                  dd      j	                  d            S )N^\s*~r   r}   )rh   rL  r   r   r   )rF   r  r   s    r)   format_cellz#WikiTables.sub.<locals>.format_cell  s0    77**266(B+E+K+KC+PQQr+   r  r  r  r  r  r`   r  z<th>z</th>r   r  r  r  z<td>z</td>r  r  r   )r   )
r   r   r  r   r   r   rh   r  r   r6  )r   r   ttextrowsr+  rK  rowr  r  r  r  s   `        @@r)   r   zWikiTables.sub  s   A$$&$$Q' 	D::<"%++-D&(hh~t&DE1779ECEKK	
 	:	R 	+ @ @ IIJDG471: >kDGG$D$DW$MMqQfa Q >DT!2 3591=>gq!j!$8Di# &&!$ BD[%6$7u=qAB'1%	&
 j!$*yy 4''A Fs   2F9c                 
    d|v S r  r1   r   s     r)   rf   zWikiTables.test  r  r+   N)r.   r/   r0   r  rd   r  ra   rg   r   r  r   r   rf   r1   r+   r)   r  r  |  s;     DIrME1%( %(c %(Nr+   r  r~   c                    | yfd}g }dg| D ]  \  }}}|d   kD  r+|j                  d |       z         j                  |       nq|d   k(  r|dxx   dz  cc<   n[|d   k  rSj                          |d   j                  d      s|dxx   dz  cc<   |j                  d |       z         |d   k  rS|j                  dj                   |       ||              t	              d	kD  rYj                          |d   j                  d      s|dxx   dz  cc<   |j                  d
 |       z         t	              d	kD  rYdj                  |      dz   S )zsReturn the HTML for the current TOC.

    This expects the `_toc` attribute to have been set on this instance.
    Nc                  &    dt               dz
  z  S )NrY  r`   r  )h_stacks   r)   r  z"calculate_toc_html.<locals>.indent  s    s7|a'((r+   r   r  z%s<ul>rr  z%s</ul></li>z{}<li><a href="#{}">{}</a>r`   z%s</ul>r   )r   popr!  r  r   r6  )r~   r  r)  r  ry  rd   r&  s         @r)   r   r     sa   
 {)EcG !r472;LLFH,-NN5!gbk!"I I'"+%Ry))'2"I(I^fh67	 '"+%
 	188Hb$  	!! g,
Ry!!'*"I IY)*	 g,

 99Ud""r+   c                   D    e Zd ZU dZdZeeeef      ed<   dZ	ee   ed<   y)r<   zA subclass of unicode used for the return value of conversion to
    possibly attach some attributes. E.g. the "toc_html" attribute when
    the "toc" extra is used.
    Nr   r   )
r.   r/   r0   r  r   r   r   r   r  r   r1   r+   r)   r<   r<     s.     *.HhtCH~&-"Hhsm"r+   z[^\w\s-]z[-\s]+r   c                     ddl }|j                  d|       j                  dd      j                         } t        j                  d|       j                         j                         } t        j                  d|       S )z
    Normalizes string, converts to lowercase, removes non-alpha characters,
    and converts spaces to hyphens.

    From Django's "django/template/defaultfilters.py".
    r   NNFKDr$   ignorer   r   )	unicodedata	normalizer'   decode_slugify_strip_rer   r   r  _slugify_hyphenate_re)r   r,  s     r)   r  r    sf     !!&%077JQQSE!!"e,224::<E $$S%00r+   functionc                       fd}|S )Nc                  \    j                         }|j                  |        | z   i |S rK  )r   r   )restkwrestcombinedri   r1  rj   s      r)   rj  z_curry.<locals>.result  s.    ;;=111r+   r1   )r1  ri   rj   rj  s   ``` r)   rT  rT    s    2 Mr+   c                 Z   | j                  d      r| j                  d      dk7  r| j                  d      }| d| | |dz   d }}t        j                  t        j                  t        j
                  t        j                  t        j                  d}d}|D ]  }	 |||   z  } t        j                  | d| |      S t        j                  t        j                  |             S # t        $ r< t        d|d| dd	j                  t        |j                                     d
      w xY w)z}'foo'    -> re.compile(re.escape('foo'))
       '/foo/'  -> re.compile('foo')
       '/foo/i' -> re.compile('foo', re.I)
    /r   r`   N)r*  r  r!   rA  uzunsupported regex flag: 'z' in 'z' (must be one of 'r   z'))r   rfindr   r  LOCALEr  r  r  KeyErrorr   r6  r  rn  r   r   )r!   r  r  	flags_strflag_from_charr  chars          r)   _regex_from_encoded_patternr@    s   
 	||CQWWS\Q.ggcl3x3q569
  	TDT--	T zz!Ac(E**zz"))A,''  T $(!RWWT.:M:M:O5P-Q"S T TTs   C%%AD*r)  tabsizer}  c           	         d}|rt        d||fz         d}t        |       D ]\  \  }}|dk(  r|rd}|D ]$  }|dk(  r|dz  }|dk(  r||||z  z
  z  }|dv r$ n :|rt        d	||fz         ||}Qt        ||      }^ |rt        d
|z         ||dkD  rt        |       D ]  \  }}|dk(  r|rd}	t        |      D ]  \  }
}|dk(  r|	dz  }	nC|dk(  r|	||	|z  z
  z  }	n2|dv r|rt        d|z         | |   |
d | |<    ^t        d|||fz        |rt        d|||	|fz         |	|k(  r| |   |
dz   d | |<    |	|kD  sd|	|z
  z  | |   |
dz   d z   | |<     |	s| |   |	d | |<    | S )a  _dedentlines(lines, tabsize=8, skip_first_line=False) -> dedented lines

        "lines" is a list of lines to dedent.
        "tabsize" is the tab width to use for indent width calculations.
        "skip_first_line" is a boolean indicating if the first line should
            be skipped for calculating the indent width and for dedenting.
            This is sometimes useful for docstrings and similar.

    Same as dedent() except operates on a sequence of lines. Note: the
    lines list is modified **in-place**.
    Fz3dedent: dedent(..., tabsize=%d, skip_first_line=%r)Nr   r}   r`   r0  r   zdedent: indent=%d: %rzdedent: margin=%rz"dedent: %r: EOL -> strip up to EOLzKunexpected non-whitespace char %r in line %r while removing %d-space marginzdedent: %r: %r -> removed %d/%d)printr   r  r   )r)  rA  r}  DEBUGmarginr*  r+  r  r~  removedjs              r)   r  r  8  s6    EC/*+ 	,FU# )46o 
	BSy!t'Vg%566v
	 )VTN:;>F(F))* !F*+fqj ' 	2GAtAv/G"4 229qLG4Zw'G*;<<G6\BTIJ$Qx|E!H$ &N(*D&'9&: ; ; ;!2w78 9f$$Qx!~E!Hv%"GFN3eAhqstnDE!H-20 $Qx1E!H;	2< Lr+   c                 b    | j                  d      }t        |||       dj                  |      S )a  _dedent(text, tabsize=8, skip_first_line=False) -> dedented text

        "text" is the text to dedent.
        "tabsize" is the tab width to use for indent width calculations.
        "skip_first_line" is a boolean indicating if the first line should
            be skipped for calculating the indent width and for dedenting.
            This is sometimes useful for docstrings and similar.

    textwrap.dedent(s), but don't expand tabs to spaces
    T)rA  r}  r   )r  r  r6  )rF   rA  r}  r)  s       r)   r  r    s,     OOD!EI775>r+   c                   "    e Zd ZdZd Zd Zd Zy)	_memoizedzDecorator that caches a function's return value each time it is called.
    If called later with the same arguments, the cached value is returned, and
    not re-evaluated.

    http://wiki.python.org/moin/PythonDecoratorLibrary
    c                      || _         i | _        y rK  )rm   cache)r   rm   s     r)   r   z_memoized.__init__  s    	
r+   c                     	 | j                   |   S # t        $ r#  | j                  | x| j                   |<   }|cY S t        $ r  | j                  | cY S w xY wrK  )rL  r<  rm   rF  )r   ri   r   s      r)   __call__z_memoized.__call__  sc    	$::d## 	'0tyy$'77DJJtuL 	$ 499d##	$s    )AAAc                 .    | j                   j                  S )z Return the function's docstring.)rm   r  r   s    r)   __repr__z_memoized.__repr__  s    yy   r+   N)r.   r/   r0   r  r   rN  rP  r1   r+   r)   rJ  rJ    s    	$!r+   rJ  c                 V    t        j                  d| dz
  z  t         j                        S )z,Standalone XML processing instruction regex.a  
        (?:
            (?<=\n\n)       # Starting after a blank line
            |               # or
            \A\n?           # the beginning of the doc
        )
        (                           # save in $1
            [ ]{0,%d}
            (?:
                <\?\w+\b\s+.*?\?>   # XML processing instruction
                |
                <\w+:\w+\b\s+.*?/>  # namespaced single tag
            )
            [ \t]*
            (?=\n{2,}|\Z)       # followed by a blank line or end of document
        )
        r`   r   r   rp  r5   s    r)   r\  r\    s/    ::   1}!   "tt!% %r+   c                 V    t        j                  d| dz
  z  t         j                        S )Na  
        (?:
            (?<=\n\n)       # Starting after a blank line
            |               # or
            \A\n?           # the beginning of the doc
        )
        (                       # save in \1
            [ ]{0,%d}
            <(hr)               # start tag = \2
            \b                  # word break
            ([^<>])*?           #
            /?>                 # the matching end tag
            [ \t]*
            (?=\n{2,}|\Z)       # followed by a blank line or end of document
        )
        r`   rR  rS  s    r)   rY  rY    s/    ::  1}  "tt% %r+   attrskip_single_quotec                     t         j                  d|       }| j                  dd      j                  dd      j                  dd      }|s|j                  dd	      }|S )
zEscape the given string for use in an HTML/XML tag attribute.

    By default this doesn't bother with escaping `'` to `&#39;`, presuming that
    the tag attribute is surrounded by double quotes.
    r  r   rq  rI  r  r|   r  r   &#39;)rv  r   r   )rU  rV  r  s      r)   r  r    s\     .G	h		f		f	  //#w/Nr+   r~  c                     t               }|dkD  r| dvr| S |dk  rdt        t        |             dd  z  S dt        |       z  S )Ng?z@_g?z&#%s;r`   )r   hexord)r~  r>   s     r)   r  r    sM    A 	3w2T>		
TSWab)))R  r+   r  c                     | j                  dd      j                  dd      j                  dd      }|r|j                  dd      }|S )	z
    Replace special characters that are potentially malicious in url string.

    Args:
        charset: don't escape characters from this charset. Currently the only
            exception is for '+' when charset=='base64'
    r   rq  rI  r  r|   r  r   rX  )r   )rU  r6   r  r  s       r)   r  r    sJ     	h		f		f	  //#w/Nr+   c                       e Zd ZdZd Zy)_NoReflowFormatterz;An argparse formatter that does NOT reflow the description.c                     |xs dS rv  r1   )r   descriptions     r)   format_descriptionz%_NoReflowFormatter.format_description  s     b r+   N)r.   r/   r0   r  ra  r1   r+   r)   r^  r^    s
    E!r+   r^  c                  ,    dd l } | j                          y r   )doctesttestmod)rc  s    r)   _testre    s    OOr+   c           
         | t         j                  } t        j                  j                  st        j
                          t        j                  dt        dt              }|j                  dddt                |j                  dd	d
       |j                  ddddt        j                  d       |j                  dd       |j                  dddd       |j                  ddddd       |j                  d d!d"d#$       |j                  d%d&       |j                  d'd(       |j                  d)dd*$       |j                  d+dd,$       |j                  d-t        d./       |j                  t        j                  dd0d d1       |j!                         }|j"                  }t$        j'                  |j(                         |j*                  r
t-               S |j.                  rni }|j.                  D ]\  }t1        j2                  d2      }|j5                  |      D ]1  }d3|v r"|j5                  d3d4      \  }}		 t7        |	      }	n|d }	}|	||<   3 ^ nd }|j:                  rg }
t=        |j:                        }	 t?        |jA                               D ]v  \  }}|jC                         s|jE                         jG                  d5      r7	 |jI                         jK                  d d4      \  }}|
jO                  tQ        |      |f       x 	 |jS                          nd }
d7d8l*m+}m,}m-}m.}  | | | |t^                          d9d:      }|sd;g}|D ]  }|d;k(  rt         j`                  jc                         }nAte        j<                  |d<|jf                        }|jc                         }|jS                          |jh                  rd7d=l5m6}m7} tq        d>        |d?|z  d@||d@A      }|j`                  js                  |ju                  d0             |j`                  jS                          |jv                  jc                         jy                  d0      }t         jv                  js                  |       tq        dB       t{        ||j|                  |j~                  ||
|j                  d@C      }|j                  r1t=        |j                  dD      5 }|js                  |       d d d        nt         jv                  js                  |       |r[dE|v rWt$        j                  dFt        |j                  ju                  t         jv                  jf                  xs d0dG            z          |jh                  s& | | | |t^                          d9      } | ||dH            r7t         j                  j                  d7|       d7dIlFmG}  ||      } |      } n|}} tq        dJ| |k(  z          y # t8        $ r Y w xY w# t8        $ r tM        d6|j:                  |d4z   |fz        w xY w# |jS                          w xY w# 1 sw Y   CxY w)KN	markdown2z%(prog)s [PATHS...])progr`  usageformatter_classz	--versionversionz	%(prog)s )actionrk  pathsr  zGoptional list of files to convert.If none are given, stdin will be used)nargshelpz-vz	--verbose	log_levelstore_constzmore verbose output)destrl  constro  z
--encodingz specify encoding of text content)ro  z--html4tags
store_trueFz'use HTML 4 style for empty element tags)rl  defaultro  z-sz--safeMODEr6   zgsanitize literal HTML: 'escape' escapes HTML meta chars, 'replace' replaces with an [HTML_REMOVED] note)metavarrr  ro  z-xz--extrasr   zPTurn on specific extra features (not part of the core Markdown spec). See above.)rl  ro  z--use-file-varszLook for and use Emacs-style 'markdown-extras' file var to turn on extras. See <https://github.com/trentm/python-markdown2/wiki/Extras>z--link-patterns-filezpath to a link pattern filez--self-testz'run internal self-tests (some doctests)z	--comparez-run against Markdown.pl as well (for testing)z--outputz"output to a file instead of stdout)r  ro  r$   )rp  comparer3   r6   r;   z[,;: ]+r   r`   #z$%s:%d: invalid link pattern line: %rr   )abspathdirnameexistsr6  rf   zMarkdown.plr   r>   )PIPEPopenz==== Markdown.pl ====zperl %sT)shellstdinstdout	close_fdsz==== markdown2.py ====)r4   r6   r7   r8   r;   rH   wr~   z
toc_html: xmlcharrefreplaceztest_markdown2.py)norm_html_from_htmlz==== match? %r ====)HsysargvloggingroothandlersbasicConfigargparseArgumentParser
cmdln_descr^  add_argument__version__rD  r   set_defaultsINFO
parse_argsrm  r  setLevelrp  	self_testre  r7   r   r   r   r   r   link_patterns_filer@   r   	readlinesr   r   r   r"  rsplitr-   r   r@  rB   os.pathrz  r{  r|  r6  __file__r  rA   r?   r3   rx  
subprocessr}  r~  rC  writer'   r  r.  r   r4   r6   r;   r4  r  r   r2   r  test_markdown2r  )!r  parseroptsrm  r7   r!   r   r   r   r   r8   fr*  r+  patrz  rz  r{  r|  r6  markdown_plr2   rF   rE   r}  r~  rf  	perl_htmlr?  test_dirr  	norm_htmlnorm_perl_htmls!                                    r)   mainr    s   |xx<<  $$j8M*F I"+K= 9  ;
sD  
 k*'--0  2 =  ?
lED  F
h[1  2 jA  B )V  W .8  :
lD  F
LJ  L

3WX
',,!(D  ODJJELL ~~w{{ 	%Azz),H^^A& 	%!8"#''#q/KE4"4y #$T4E $u	%	% (()	$Q[[]3 >4zz|;;=++C0P $ 4 4T1 =IC $$05t<>> GGI66wwwx'89:F$&K (I3;99>>#DT36B779DHHJ<<.)*i+-Td^bcAGGMM$++g./GGMMO..w7IJJY'*+nnnn,, ;;dkk3' 1  JJT"evoIIlDMM(()<)<)GI\]^_ `<<GGGH,=$>?HHd8%89:8,>/5	!4Y!? 	!*'>Y+FGHQ(IE & & " P'(N+/+B+BAaC*N)O P PP GGI@ sC   XAX< #X8X< Y	XX(X99X< <YY	__main__)   F)T)FNrK  )xr  r  __version_info__r6  r  r   r  
__author__r  r?   r  r   r  collectionsr   r   abcr	   r
   ro   collections.abcr   hashlibr   r   typingr   r   r   r   r   r   r   r   r   r   r   enumr   r   osr   r  r   r  r  r  r  Patternr  r  rD  	getLoggerr  r  r&   r*   r   r   rv  	Exceptionr-   r  r   rG   r   rK   rr   rC   r  rb   r  r  r  r  r*  r6  r:  r?  rC  rV  rl  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r   r<   r/  r0  r  rT  r@  r  r  rJ  r\  rY  r  r  r  RawDescriptionHelpFormatterr^  re  r  r.   exitr  )r~  s   0r)   <module>r     s   >D
V  hhs3 012
    	 
 0 #  $   ^ ^ ^ &   ()
CH~d3i-.%

E#x
C7P2P,Q QRS 	g
#  bkM# M# M
 "#
 jn$ #
 

?@	I 	 &&*&*.2$(,0?
?? ? 	?
 
#? ]#? N+? SM? %SM? ? ?2 &&*&*.2$(+/H
HH H 
#	H
 ]#H N+H SMH %SMH H 
H H(G ,#e #LP  P f@1 1,UC Up.HU .Hb<iu <B*E B*R
37% 37l 1U  1FAy AU 0") "0i=u i=X0E 0fE5 EPU .E"9 E!4 !4H( (<.) <.~> >B!5e !5HF% FRU  T(U T(n
e 
  % &Iu &IR9 9z                                       	                    	        
   #E$uS#s]';"<d"BC #QT #D#s # BJJ{+ "

9- 
1C 
1C 
1X 8 (3 (2:: (<HS	 HC Hd HW[\_W` HV#  $ 3  ! !6%s %rzz %& #,,K"L % % %" &&?@ 3 4 3 "! ! !  05!
Zt+, c].!== !
FIR zCHHT#((^ S@#s   0U