
    Mi                    <   S r SrSrSR                  \" \\5      5      rSrSSKrSSK	r	SSK
r
SSKrSSKrSSKJrJr  SSKJrJr  SSKrSS	KJrJr  SS
KJr  SSKJr  SSKJrJrJrJrJrJ r J!r!J"r"J#r#J$r$J%r%  SSKJ&r&  SSK'J(r(J)r)  SSK*J+r+  \S   r,\-\\4   r.\$\/\   \.4   r0\\1\Rd                  \   \$\\\Rf                  \   /\4   4   4      r4Sr5\
Rl                  " S5      r7Sr8\+" S5      r9S\S\4S jr:S V s0 s H  n U \:" U 5      _M     sn r;Sr<\Rz                  " S\<-  5      r>\Rz                  " S\<-  5      r? " S S\@5      rASS\8SSSSSS4	S\S \S!\BS"\CS#\ \,   S$\ \0   S%\ \4   S&\ \   S'\ \   S(\BSS)4S* jjrDS\8SSSSSSS4	S+\S!\BS"\CS#\ \,   S$\ \0   S%\ \4   S&\ \   S'\ \   S(\BS,\BSS)4S- jjrE " S. S/\(5      rFS0\F4S1 jrG " S2 S35      rH " S4 S5\H5      rI " S6 S7\5      rJ " S8 S9\J5      rK " S: S;\J5      rL " S< S=\#SS>9rM " S? S@\J5      rN " SA SB\J5      rO " SC SD\J5      rP " SE SF\#SS>9rQ " SG SH\J5      rR " SI SJ\L5      rS " SK SL\J5      rT " SM SN\J5      rU " SO SP\J5      rV " SQ SR\J5      rW " SS ST\MSS>9rX " SU SV\N5      rY " SW SX\T5      rZ " SY SZ\L5      r[ " S[ S\\J5      r\ " S] S^\J5      r] " S_ S`\J5      r^ " Sa Sb\J5      r_ " Sc Sd\J5      r` " Se Sf\J5      ra " Sg Sh\J5      rb " Si Sj\#SS>9rc " Sk Sl\J5      rd " Sm Sn\J5      re\OR                  5         \PR                  5         \RR                  5         \SR                  5         \TR                  5         \UR                  5         \VR                  5         \WR                  5         \YR                  5         \[R                  5         \ZR                  5         \\R                  5         \]R                  5         \^R                  5         \_R                  5         \`R                  5         \aR                  5         \bR                  5         \dR                  5         \eR                  5         So\$\/\1\C\\4      S4   S\ \   4Sp jrg " Sq S)\5      rh\Rz                  " Sr5      ri\Rz                  " Ss5      rjSt\S\4Su jrkSv\S\4Sw jrlS\S\Rd                  \   4Sx jrmSSy\/\   Sz\CS{\BS\/\   4S| jjrnSS+\Sz\CS{\BS\4S} jjro " S~ S5      rpS"\CS\Rd                  \   4S jrq\p" \q5      rqS"\CS\Rd                  \   4S jrr\p" \r5      rrSS\S\BS\4S jjrsS\S\4S jrt  SS\S#\$\,\BS4   S\ \   4S jjru " S S\R                  5      rwS rxSS jry\zS:X  a#  \R                  " \y" \R                  5      5        ggs  sn f )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.
)      r   .z
Trent Mick    N)defaultdictOrderedDict)ABCabstractmethod)IterableIterator)sha256)random)AnyCallableDictListLiteralOptionalTupleType	TypedDictUnioncast)
Collection)IntEnumauto)urandomreplaceescapeFmarkdown      sreturnc                 l    S[        [        U R                  S5      -   5      R                  5       SS  -   $ )Nzmd5-utf-8    )r   SECRET_SALTencode	hexdigest)r#   s    c/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/markdown2.py
_hash_textr,      s0    F;')::;EEGLLL    z\`*_{}[]()>#+-.!z#?[xX]?(?:[0-9a-fA-F]+|\w+);z&(?!%s)z(?:\\\\)*\\&(%s)c                       \ rS rSrSrg)MarkdownError    N)__name__
__module____qualname____firstlineno____static_attributes__r1   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
                     [         R                  " U SU5      n
U
R                  5       nU
R                  5         [	        X#XEUUUU	S9R                  U5      $ )Nr)r9   r:   r;   r<   r=   r>   r?   r@   )codecsopenreadcloseMarkdownconvert)r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   fptexts               r+   markdown_pathrL      sS     
T3	)B779DHHJi'"/#1+A"/1
 29?r-   rK   clic
                 <    [        XX4UUUXS9	R                  U 5      $ )N)	r9   r:   r;   r<   r=   r>   r?   r@   rM   )rH   rI   )
rK   r9   r:   r;   r<   r=   r>   r?   r@   rM   s
             r+   r    r       s/     i'"/#1+A"/:
 ;B'$-Hr-   c                       \ rS rSr\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r	\" 5       r
\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       r\" 5       rSrg)Stage   r1   N)r2   r3   r4   r5   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_HTMLr6   r1   r-   r+   rP   rP      sr    JII&KfGFE&K6LJJJVNFEfO&K&Kr-   rP   stagec                    ^  U 4S jnU$ )z\
Decorator that handles executing relevant `Extra`s before and after this `Stage` executes.
c                 N   >^  [         R                  " T 5      SU U4S jj5       nU$ )Nc                   > TU l         TS-
  U l        T[        R                  ;   a{  [        R                  T   S    Ha  nUR                  U R
                  ;  a  M  U R
                  UR                     nUR                  U5      (       d  MP  UR                  U5      nMc     TU l        T" X/UQ70 UD6nTS-   U l        T[        R                  ;   a{  [        R                  T   S    Ha  nUR                  U R
                  ;  a  M  U R
                  UR                     nUR                  U5      (       d  MP  UR                  U5      nMc     U$ )Ng      ?r      )rb   orderExtra_exec_ordernameextra_classestestrun)mdrK   argskwargsklassextrafuncrb   s         r+   inner*mark_stage.<locals>.wrapper.<locals>.inner   s   BHs{BH)))"..u5a8Ezz)9)99 ,,UZZ8Ezz$''$yy 9 BH24262Ds{BH)))"..u5a8Ezz)9)99 ,,UZZ8Ezz$''$yy 9 Kr-   )rn   rH   )	functoolswraps)rs   rt   rb   s   ` r+   wrappermark_stage.<locals>.wrapper   s%    			 
	6 r-   r1   )rb   rx   s   ` r+   
mark_stagerz      s    > Nr-   c                      \ rS rSr% \\S'   \\S4   \S'   \\\4   \S'   \\\4   \S'   \\\4   \S'   \\\4   \S'   S	r\\S
'   Sr	\\S'   \
\   \S'   \\\\\4      \S'   Sr\\S'    \\S'    \R&                  " S\R(                  5      rS\SSSSSSS4	S\S\S\
\   S\
\   S\
\   S\
\   S\
\   S\S\4S jjrS rS r\R&                  " S\R:                  \R<                  -  5      rS \S!S"4S# jr S$ r!\"" \RF                  5      S \S!\4S% j5       r$\"" \RJ                  5      S \S!\4S& j5       r&\R&                  " S'RO                  S(S)5      \RP                  \R<                  -  5      r)\R&                  " S*\RP                  5      r*\R&                  " S+\RP                  5      r+\R&                  " S,\RP                  5      r,\R&                  " S-\RP                  5      r-S \S!\4S. jr.\R&                  " S/\R^                  5      r0\R&                  " S0\R:                  \RP                  -  \Rb                  -  \R<                  -  5      r2S1\Rf                  \   S!\4S2 jr4S \S!\\\4   4S3 jr5S4\S!\4S5 jr6S \S!\4S6 jr7S7r8S8r9\9\8-  r9\R&                  " S9\9-  \Rt                  \R(                  -  5      r;S:r<\<\8-  r<S;r=\R&                  " S<\<-  \Rt                  \R(                  -  5      r>\R&                  " S=5      r? SS1\@\Rf                  \   \4   S>\S!\4S? jjrA\"" \R                  5      SS \S>\S!\4S@ jj5       rC SS \SA\SB\D\/\4   SC\S!\4
SD jjrESE\S \S!\4SF jrF\"" \R                  5      S \S!\4SG j5       rHS1\Rf                  \   S!\4SH jrIS1\Rf                  \   S!\4SI jrJS \S!\4SJ jrK\R&                  " SK\R(                  5      rL\"" \R                  5      S \S!\4SL j5       rN\"" \R                  5      S \S!\4SM j5       rP\R&                  " SN\Rt                  5      rQ\R&                  " SO5      rR\"" \R                  5      S \S!\4SP j5       rTSQ rU\"" \R                  5      S \S!\4SR j5       rVSS \S!\4SS jjrWST\S!\4SU jrX\R&                  " SV\Rt                  \R                  -  5      rZ\R&                  " SW\Rt                  \R                  -  5      r[\R&                  " SX5      r\\R&                  " SY5      r]S \SZ\S!\4S[ jr^S \SZ\S\\S]\S!\4
S^ jr_\R&                  " S_\Rt                  5      r`S`\S!\4Sa jraSbrb\cSc 5       rd\"" \R                  5      S \S!\4Sd j5       rf SS \Se\Sf\
\   S!\4Sg jjrgS \S!\4Sh jrhSi\Sj\Sk\S!S4Sl jriSmrj\R&                  " \jSn-  \Rt                  \R(                  -  5      rk\R&                  " \jSo-  \Rt                  \R(                  -  5      rlS1\Rf                  \   S!\4Sp jrm\R&                  " Sq\Rt                  \R(                  -  5      rnS1\Rf                  \   S!\4Sr jro\"" \R                  5      S \S!\4Ss j5       rqStrrSu\r-  rsSv\r-  rtSwruS1\Rf                  \   S!\4Sx jrv\"" \R                  5      S \S!\4Sy j5       rx\R&                  " SzRO                  \s\s5      \R(                  \Rt                  -  \R                  -  5      ry\R&                  " S{\R(                  \Rt                  -  \R                  -  5      rzS|r{S1\Rf                  \   S!\4S} jr|Sr}S1\Rf                  \   S!\4S~ jr~S\S!\4S jrS\4S jrS\S!\4S jrS1\Rf                  \   S!\4S jrS\S!\4S jr\"" \GR                  5      S \S!\4S j5       r\R&                  " S\Rt                  \R                  -  5      rS1\Rf                  \   S!\4S jr\"" \GR                  5      S \S!\4S j5       rS \S!\4S jr\R&                  " S\R                  \Rt                  -  5      r\R&                  " S\R                  5      rSr\"" \GR                  5      S \S!\4S j5       rSr\R&                  " \S-  \R(                  \Rt                  -  5      r\R&                  " \S-  \R(                  \Rt                  -  5      r\R&                  " S\R(                  5      r\R&                  " S\R(                  5      r\R&                  " S\R(                  5      r\R&                  " S\R                  5      rS1\Rf                  \   S!\4S jrS1\Rf                  \   S!\4S jr\"" \GR2                  5      S \S!\4S j5       r\"" \GR6                  5      S \S!\4S j5       rS \S!\4S jr\R&                  " S\GR<                  5      r\R&                  " S\GR<                  5      rS \S!\4S jr\R&                  " S5      rS \S!\4S jrS \S!\4S jr\R&                  " S\GR<                  5      rS1\Rf                  \   S!\4S jr\R&                  " S\GR<                  \Rt                  -  \GRN                  -  5      rS1\Rf                  \   S!\4S jrS \S!\4S jrS\S!\4S jrS \S!\4S jrS \S!\4S jrSS \S\
\   S!\4S jjr\  SS \S\
\   S\
\   S!\\\4   4S jj5       r\  SS \S\S\S\S!\4
S jj5       r\S \S1\Rf                  \   S\S!\4S j5       rSrg)rH   i  r<   rh   rk   urlstitleshtml_blocks
html_spansz
{(#HTML#)}html_removed_textz[HTML_REMOVED]html_removed_text_compatr;   _tocr   rb   rg   z^[ \t]+$FNr9   r:   r=   r>   r?   r@   rM   c
                     U(       a  SU l         OSU l         X l        US-  U l        USL a  SU l        OX0l        [	        U SS 5      c  0 U l        OA[        U R
                  [        5      (       d"  U R
                   V
s0 s H  oS _M     sn
U l        U(       aB  [        U[        5      (       d  U V
s0 s H  oS _M     nn
U R
                  R                  U5        [        U R
                  [        5      (       d   eSU R
                  ;   a[  SU R
                  ;  a  S U R
                  S'   U R
                  S   c  S	U l	        O$U R
                  S   R                  S
S	5      U l	        SU R
                  ;   aB  [        U R
                  S   [        5      (       d   SU R
                  S   SS.U R
                  S'   SU R
                  ;   a.  U R
                  R                  S0 5        SU R
                  S   S'   SU R
                  ;   a4  U=(       d    U R
                  S   nUc  [        S5      eXPR
                  S'   U R
                  R                  5       U l        XPl        X`l        Xpl        Xl        [&        R(                  " SU-  [&        R*                  5      U l        Xl        [0        R                  5       U l        0 U l        SU R
                  ;   a1  [7        S5      U R2                  S'   [7        S5      U R2                  S'   g g s  sn
f s  sn
f )N>z /> Tr   r<   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_suffixr:   tabr;   getattrr<   
isinstancedictupdate
_toc_depthget
setdefaultr/   copy_instance_extrasr=   r>   r?   r@   recompileM_outdent_rerM   g_escape_table_escape_table_code_tabler,   )selfr9   r:   r;   r<   r=   r>   r?   r@   rM   es              r+   __init__Markdown.__init__5  s    (+D%(-D%"s?
 &DN&N 44(0DKDKK.. -1KK8Kqd7K8DKfd+++126aT'6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+8KK( $ 0 0 2*,&<#*::&89&DbddK+002T[[(&0oDs#&0oDs# )c 9 3s   =L1Lc                     0 U l         0 U l        0 U l        0 U l        SU l        U R
                  R                  5       U l        U R                  5         / U l	        g Nr   )
r|   r}   r~   r   
list_levelr   r   r<   _setup_extrasr   r   s    r+   resetMarkdown.reset  sO    	++002	r-   c                 ,   SU R                   ;   a&  [        5       U l        / U l        [	        S5      U l        SU R                   ;   aI  [        U S5      (       a$  U R                   S   R                  SS5      (       a  [        [        5      U l
        SU R                   ;   a  0 U l        0 U l        [        R                  R                  5        HE  u  pXR                   ;  a  M  U" X R                   R                  U0 5      5      U R                  U'   MG     g )N	footnotesz<<footnote>>r   _count_from_header_idr   Fmetadata)r<   r   r   footnote_idsr,   _footnote_markerhasattrr   r   intr   r   rk   rh   	_registryitems)r   rj   rq   s      r+   r   Markdown._setup_extras  s    $++% )]DN "D$.~$>D!4;;&4!899T[[=V=Z=Z[hjo=p=p-8-=*$,.DM ??002KD;;&',TKKOOD"4M'ODt$ 3r-   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)
        )
        rK   r$   rA   c                   ^ U R                  5         [        T[        5      (       d  [        TS5      mU R                  (       a  U R                  R                  U R                  T5      mU R                  T5      nSU;   ai  [        R                  " S5      nUR                  US   5       H;  nSU;   a!  UR                  SS5      u  pV [        U5      nOUSpeX`R                  U'   M=     U R                  5         TR                  SS5      mTR                  S	S5      mTS
-  mU R!                  T5      mU R"                  R                  ST5      mSU R                  ;   a  U R%                  T5      mU R'                  T5      mU R(                  (       a  U R+                  T5      mU R-                  TSS9mSU R                  ;   a  U R/                  T5      mU R1                  T5      mU R3                  T5      mSU R                  ;   a"  U R5                  T5      mU R7                  T5      mU R9                  T5      mU R;                  T5      mU R=                  T5      mU R(                  (       a&  TR                  U R>                  U R@                  5      mSU R                  ;   nSU R                  ;   nU(       a$  U(       a  U RB                  R                  ST5      mOGU(       a  U RB                  R                  ST5      mO#U(       a  U RB                  R                  ST5      mSU R                  ;   a  U RD                  (       a  U R                  S   RG                  S5      (       a  U4S jn	U RD                  RI                  U	S9  [K        U RD                  5      U l&        U RN                  (       d4  U R                  S   b5  U R                  S   RG                  SS5      (       a  U RL                   ST 3mTS-  m[Q        T5      n
SU R                  ;   a"  U RD                  (       a  U RL                  U
l)        SU R                  ;   a  U RT                  U
l*        U
$ ! [         a     GNf = f)zConvert the given text.r&   zmarkdown-extrasz[ ,]+=rf   N



 r   Trawr   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           	         > [         R                  " SU S   U S   [         R                  " U S   5      4-  T[         R                  5      nU(       a  UR	                  5       $ S$ )z+Sort the TOC by order of appearance in textz#^<(h%d).*?id=(["\'])%s\2.*>%s</\1>$r   rf   r   )r   searchr   r   start)entrymatchrK   s     r+   toc_sort"Markdown.convert.<locals>.toc_sort  sZ    II>%(ERSHVXV_V_`efg`hViAjjbddE
 -25;;=8q8r-   keyprependF)+r   r   strr@   _emacs_oneliner_vars_patsub_emacs_vars_oneliner_sub_get_emacs_varsr   r   splitr   
ValueErrorr<   r   r   _detab_ws_only_line_re_extract_metadata
preprocessr;   _hash_html_spans_hash_html_blocks_strip_footnote_definitions_strip_link_definitions_run_block_gamut_do_footnote_marker_add_footnotespostprocess_unescape_special_chars_unhash_html_spansr   r   _a_nofollow_or_blank_linksr   r   sortcalculate_toc_html	_toc_htmlrM   rA   toc_htmlr   )r   rK   
emacs_varssplitterr   enameeargdo_target_blank_linksdo_nofollow_linksr   rvs    `         r+   rI   Markdown.convert  s    	

$$$tW%D0044T5R5RTXYD--d3J J.::g.!
3D(EFAax&'ggc1o!#&t9D '(t)-KK& G   ||FD)||D$' 	 {{4  $$((T2 $))$/Dt$>>((.D %%d%5 $++% 33D9D++D1$$T*$++%++D1D&&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59 		8,/		:DN xxDKK.:t{{5?Q?U?UV_af?g?g..)D62 d#DKKDII..BK$--BK	E  * ! !s   	Q
Q)(Q)c                 X   ^  U 4S jn[         R                  " ST R                  -  X!5      $ )Nc                    > U R                  S5      nUTR                  ;  a  TR                  R                  U5        [        [	        TR                  5      5      $ Nrf   )groupr   appendr   len)r   	normed_idr   s     r+   footnote_sub2Markdown._do_footnote_marker.<locals>.footnote_sub;  sH    AI 1 11!!((3s4,,-..r-   z%s-(.*?)(?=</a></sup>))r   r   r   )r   rK   r   s   `  r+   r   Markdown._do_footnote_marker:  s'    	/ vv/$2G2GG\\r-   c                     U$ )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   rK   s     r+   r   Markdown.postprocessC  	     r-   c                     U$ )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   Markdown.preprocessK  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                 `  ^ ^	^
 UR                  S5      (       a+  [        R                  " T R                  USS9nUS   nUS   nO*[        R                  " T R                  USS9nUS   nUS   n[        R
                  " T R                  U5      nU(       d  U$ S[        S[        [        [           [        [        [        4   4   4U	U U
4S jjm	U H  nUR                  S	S5      u  nm
T
S S
 S:X  a9  [        T
S
S  5      R                  5       T R                  UR                  5       '   MZ  T
S:X  a  ST R                  UR                  5       '   M  T
S   S:X  a%  T	" T
5      T R                  UR                  5       '   M  T
R                  5       T R                  UR                  5       '   M     U$ )N---r   )maxsplitrf   r   valuer$   c                   > U R                  5       nU R                  TS [        U 5      [        U5      -
   S5      SS  nUR                  S5      (       Ga7  / n[        R
                  " TR                  U5       GH  nUS   (       a8  US   (       d.  US   (       d$  UR                  US   R                  5       5        MF  US   S:X  a8  US   (       d.  US   (       a$  UR                  US   R                  5       5        M  US   (       aA  US   (       a7  UR                  US   R                  5       US   R                  5       05        M  US   (       d1  US   (       d'  US   (       a  UR                  T" US   5      5        GM  GM     U$ [        R
                  " TR                  U5       Vs0 s H=  nUS   R                  5       US   (       a  US   R                  5       O
T" US   5      _M?     sn$ s  snf )Nr   rf   -r   r   r   )
lstripr   r   
startswithr   findall_key_val_list_patr   strip_key_val_dict_pat)r  vsrC   r   parse_structured_valuer   vs       r+   r  :Markdown._extract_metadata.<locals>.parse_structured_value  s   Bq!73u:B#78$?CB }}S!!!  ZZ(>(>CE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  "$D,B,BB!G "H !HNN$ 8 a(3E!H=>
 "H  s   0AG7:   z >
r   r   )r  r   r   _meta_data_fence_pattern_meta_data_newliner	  _meta_data_patternr   r   listr   r   _dedentr  r   )r   rK   fence_splitsmetadata_contenttailmetadata_splitr   itemkr  r  s   `        @@r+   r   Markdown._extract_metadataw  sw   ??5!!88D$A$A4RSTL+A?DXXd&=&=taPN-a0!!$D ::d&=&=?OPK"	# "	%S	4S>8Q2R "	 "	H D::c1%DAq !u+21QR5>+?+?+Aaggi( d+-aggi( 1+A!+Daggi( ,-779aggi(% ( 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                    UR                  S5      R                  5       S:X  a  UR                  S5      R                  5       S:X  a  [        R                  " SUR                  S5      5      S   n[        R                  " SUR                  S5      5      S   nSR	                  USUR                  S5      R                  5       SU5      $ UR                  5       u  pEUR                  XE $ )	Nrf   -*-r!   z^\s*r   z\s*$z{}<!-- {} {} {} -->{}r   )r   r  r   r	  formatspanstring)r   r   lead_wstail_wsr   ends         r+   r   !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\
||E''r-   c                    0 n[        SS5      nUSU nSU;   a  U R                  R                  U5      nU(       a  UR                  S5      nSU;  d   eUR	                  S5       Vs/ s H*  nUR                  5       (       d  M  UR                  5       PM,     nn[        U5      S:X  a   SUS	   ;  a  US	   R                  5       US
'   OLU HF  n	 U	R                  5       R	                  SS5      u  pUR                  5       X*R                  5       '   MH     X* S nSU;   Ga  U R                  R                  U5      nU(       Ga  UR                  S5      nUR                  S5      nUR                  S5      R                  S5      n[        U5       H  u  nnUR                  U5      (       d"  [        R                  SU< SU< S35        0 s  $ U[        U5      S-
  :w  d  MR  UR                  U5      (       a  Mj  [        R                  SU< SU< S35        0 s  $    SnUSS  H  nU(       a  U[        U5      S nU(       a  US[        U5      *  nUR                  5       nU(       a?  Un
UR                  S5      (       a  USS R!                  5       nOSnX*==   SU-   -  ss'   M   UR	                  SS5      u  pUR                  5       nUR                  S5      (       a  USS R!                  5       nU
nOSnXU
'   M     [#        UR%                  5       5       H{  u  nn[        U5      S:  d  M  UR                  S5      (       a  UR                  S5      (       d0  UR                  S5      (       d  M[  UR                  S5      (       d  Ms  USS UU'   M}     U$ s  snf ! [         a    [        R                  SU	5         GM  f = f! [         a    [        R                  SU-  5         GM  f = f)a  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   ;rf   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   rK   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   Markdown._get_emacs_vars  s    
1bz ET{D=1188>E!&Q>1115C5I5I#5N "05N%&WWY #,!'')5N "0~&!+>!;L0L
 *8):)@)@)BJv&)7%.;.A.A.C.I.I#q.QOH 8={{}
>>#34 *8 EF|$..55d;EX.X.I.99%@  )/GAt??622		%)6#3 4  "	 CJqL(v1F1F		%)6#3 4  "	  0 !%!#2JD#CKL1#Mc&k\2::<D$#0==..#'9#3#3#5D,0M",d
:,%.2jja.@OH !& >>$//$)#2J$5$5$7E,4M,0M/48,9 '> Z--/0HC3x!|!4!4c9J9J..%%#,,s*;*;"%a)
3 1
 i"0  * %II '12?A$%h  * %II 'GIM'N O$%s0   (N N "N%,O% O
	O
"O43O4rA  c                     SU;  a  U$ UR                  SS5      u  p#USU R                  [        U5      U R                  -  -
  -  -  nX#-   nU R                  U5      $ )zJRecusively convert tabs to spaces in a single line.

Called from _detab().	rf   r   )r   r:   r   _detab_line)r   rA  chunk1chunk2outputs        r+   rH  Markdown._detab_lineA  s`     tKD!,3$..3v;+GGHI''r-   c                     SU;  a  U$ / nUR                  5        H#  nUR                  U R                  U5      5        M%     SR                  U5      $ )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'
rG  r   )r5  r   rH  join)r   rK   rK  rA  s       r+   r   Markdown._detabL  sM     tKOO%DMM$**401 &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                 F   [        U[        5      (       a  UnS nO#UR                  S5      n UR                  S5      nU(       d-  [        R
                  " SU5      nUc   eUR                  S5      nU(       a$  U R                  (       a  U R                  U5      nGOSU R                  ;   GaK  SU;   GaD  UR                  SS5      S   nU R                  R                  U5      nU(       Ga  UR                  S5      n[        [        S [        R                  " SU-  US   5      5      5      USS  -   nUS S	 [        [        S [        R                  " S
U-  US	   5      5      5      -   nUS   nSR                  USS	 5      nUS	   n	US UR                  5        XeR!                  5       S  -   n[#        U5      n
X`R$                  U
'   [#        U	5      nXR$                  U'   SR                  SU
SUSUS/5      $ OvU R                  R'                  S0 5      R'                  S5      (       aF  U R(                  R                  U5      (       a&  U R(                  R+                  U R,                  U5      n[#        U5      nX0R$                  U'   SU-   S-   $ ! [         a    S n GNaf = f)Nrf   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   r;   _sanitize_htmlr<   r   _html_markdown_attr_rer   r  filterrN  r   r&  r,   r~   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_subMarkdown._hash_html_block_sub  so   
 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@Z>>%%doot<D $|f$$M  s   J J J c                 j  ^ ^ SU;  a  U$ [        T R                  US9mT R                  UT R                  T5      nT R                  R                  TU5      nT R                  UT R                  UU 4S j5      nSU;   a'  [        T R                  5      nUR                  TU5      nSU;   Ga,  Sn  UR                  SU5      n UR                  SU5      S-   nUnU(       a_  [        T R                  S	-
  5       H  nXS	-
     S
:w  a    OUS	-  nUS:X  d  M    O   US:X  a  OUS	:X  a  US   S:X  a  SnOXS-
  U S:X  a  OOU[        U5      :  a  X   S;  a  OUS	-  nU[        U5      :  a  M  XUS-    S;  a  M  XU nU(       a"  T R                  (       a  T R                  U5      n[        U5      n	UT R                   U	'   USU S-   U	-   S-   XS -   nGM)  ST R"                  ;   a'  [%        T R                  5      n
U
R                  TU5      nU$ ! [         a     MF  f = f! [         a     MW  f = f)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   > T" TR                  U 5      5      $ N)_run_span_gamut)thash_html_block_subr   s    r+   <lambda>,Markdown._hash_html_blocks.<locals>.<lambda>  s    )$*>*>q*ABr-   <hrz<!--r   -->r  rf   r   r   r   r    	)r   r   r   Nxml)_curryr`  _strict_tag_block_sub_block_tags_a_liberal_tag_block_rer   
_span_tags_hr_tag_re_from_tab_widthr:   indexr   ranger   r;   rS  r,   r~   r<   _xml_oneliner_re_from_tab_width)r   rK   r   
_hr_tag_rer   	start_idxend_idxr@  rX  r   _xml_oneliner_rerh  s   `          @r+   r   Markdown._hash_html_blocks  sx    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	$>! 7 !A~"aDGtO$%	k)4> D	)}E1qLG D	)
 	*2DD g.4>>..t4D &(,  %JY'&036?$x.Pe h DKK  ?t~~N#''(;TBDw "  " s$   2H H$ 
H! H!$
H21H2html_tags_recallbackallow_indentc                    SnUnSnSnUR                  S5       H  n	[        R                  " SR                  U(       a  SOSU5      U	5      n
Xy-  nU
(       am  U	R	                  SU
R                  S5      -  5      (       a  US-  nO?U R                  U
R                  S5      U	5      (       a  S	n
OUS-  nU
R                  S5      nUS:X  d  M  U
(       a  U" UR                  S
5      5      nUnX-  nSnM     X-  nU$ )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</rf   r  Nr   )r5  r   r   r!  r  r   _tag_is_closedr8  )r   rK   r}  r~  r  	tag_countcurrent_tagblockresultchunk	is_markups              r+   rp  Markdown._strict_tag_block_sub6  s    " 	"__T*ECJJQ]2cfhstv{I NE##FY__Q-?$?@@NI **9??1+=uEE$(	!Q	&/ooa&8A~$U\\$%78E*/ +2 	r-   tag_namec                     [        [        R                  " SU-  U5      5      UR                  SU-  5      :w  a  gUR	                  SU 35      nUR	                  SU 35      nUS:g  =(       a    US:g  =(       a    XC:  $ )Nz<%s(?:.*?)>z</%s>F</rc  r.  )r   r   r	  countfind)r   r  rK   close_index
open_indexs        r+   r  Markdown._tag_is_closedi  sx    rzz-(2D9:djjS[I[>\\ ii"XJ0YY8*~.
RRK2$5R*:RRr-   c                     U R                   S-
  n[        R                  " SU-  [        R                  [        R                  -  [        R
                  -  5      nUR                  U R                  U5      $ )Nrf   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)
            )r:   r   r   Xr   Ur   _extract_link_def_sub)r   rK   less_than_tab_link_def_res       r+   r    Markdown._strip_link_definitionss  sf     * zz #"  ## " "$rtt!3#5$  : :DAAr-   c                     UR                  5       u  p#nUR                  5       nU R                  U5      U R                  U'   U(       a  X@R                  U'   gNr   )groupsr3  _encode_amps_and_anglesr|   r}   )r   r   idurltitler   s         r+   r  Markdown._extract_link_def_sub  sF    hhj55c:		#$KKr-   c                     UR                  5       u  p#[        X3R                  S5      (       + S9R                  5       n[        R
                  " SSU5      nUS-   U R                  U'   g)Nr   )skip_first_line\Wr  r   r   )r  r  r  r  r   r   r   )r   r   r  rK   r   s        r+   _extract_footnote_def_sub"Markdown._extract_footnote_def_sub  sW    <<>t1F-FGMMOFF5#r*	 %)6My!r-   c                     U R                   S-
  n[        R                  " SX R                   U R                   4-  [        R                  [        R                  -  5      nUR                  U R                  U5      $ )aP  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.
rf   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)
            )r:   r   r   r  r   r   r  )r   rK   r  footnote_def_res       r+   r   $Markdown._strip_footnote_definitions  si     *** & !..$..A&B DD244K ""4#A#A4HHr-   z)^[ ]{0,3}([-_*])[ ]{0,2}(\1[ ]{0,2}){2,}$c                 8   U R                  U5      nSU R                  -   S-   n[        R                  " U R                  X!5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU$ )Nz
<hrr   )
_do_headersr   r   r   _hr_re	_do_lists_do_code_blocks_do_block_quotesr   _form_paragraphs)r   rK   hrs      r+   r   Markdown._run_block_gamut  s    
 % T...t3vvdkk2,~~d###D)$$T* %%d+$$T*r-   c                    U R                  U5      nU R                  U5      nU R                  U5      nU R                  U5      nU R	                  U5      nU R                  U5      n[        R                  " SSU R                  -  U5      nU$ )Nz  {2,}\n(?!\<(?:\/?(ul|ol|li))\>)<br%s
)	_do_code_spans_escape_special_chars	_do_links_do_auto_linksr  _do_italics_and_boldr   r   r   r   s     r+   rf  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
            )
        )
        z^((?:\\\\)*(?!\\))c           	      ~   / nSnU R                   R                  U5       GH	  nU(       a  U R                  R                  U5      (       a  U R                  R                  U5      SS  =(       d    SU4u  pTUR	                  UR                  SU R                  S   5      UR                  SU R                  S   5      R                  SU R                  S   5      -   5        O@UR	                  U R                  UR                  SS	5      R                  S
S5      5      5        U(       + nGM     SR                  U5      $ )NFrf   r   z\\r/  *_\<&lt;z\>&gt;)	_sorta_html_tokenize_rer   _is_unescaped_rer   r   r   r   _encode_backslash_escapesrN  )r   rK   escapedis_html_markuptoken
escape_seqs         r+   r  Markdown._escape_special_chars  s    1177=E $"7"7"="=e"D"D %)$9$9$?$?$Fqr$J$YrSXk!
&&vt/A/A$/GHmmC););C)@A#GC););C)@AB 22eV4<<UFK
 "0/N- >. wwwr-   c                     SU;   a!  U R                   R                  U5      (       a  gSU;   a!  U R                  R                  U5      (       a  gg)Nr  T@F)_auto_link_rer   _auto_email_link_rer   s     r+   _is_auto_linkMarkdown._is_auto_link=  sE    $;4--33D99D[T55;;DAAr-   c           	        ^ ^^ U4S jnU 4S jn0 mT R                   R                  UU 4S jU5      n/ nT R                  R                  U5      mSnU[	        T5      :  Ga  US-  S:g  nTU   nU" XW5      nU(       GaG  T R                  U5      (       Gd0  U(       Gd(  U" U5      n	U	(       a  UR                  T R                  T R                  U	R                  S5      5      5      5        UR                  T R                  U	R                  S5      5      5        UR                  T R                  T R                  U	R                  S5      5      5      5        OT R                  R                  U5      c!  UR                  T R                  U5      5        O|UR                  T R                  T R                  U5      5      5        OLU(       a%  U(       a  UR                  TXUS-    5        US-  nGM  UR                  T R                  U5      5        US-  nU[	        T5      :  a  GM  SR                  U5      nTR!                  5        H  u  pUR#                  X5      nM     U$ )	Nc                    >  US:X  a  TX S-    nOUS:X  a  TU S-
  U S-    nOg[        R                  " SSR                  U5      5      $ ! [          a     gf = f)	N<code>r  </code>r   rf   Fz <code>md5-[A-Fa-f0-9]{32}</code>r   )rR  r   r   rN  )ru  r  peek_tokenssplit_tokenss      r+   _is_code_span0Markdown._hash_html_spans.<locals>._is_code_spanH  sn    H$".uai"@Ki'".uqy%!)"DK  88?AUVV  s   A
 A
 

AAc                 T   > TR                   S:X  a  g [        R                  " SU 5      $ )Nr   z(<!--)(.*)(-->))r;   r   r   )r  r   s    r+   _is_comment.Markdown._hash_html_spans.<locals>._is_commentU  s$    ~~*88.66r-   c                 z   > TR                  U R                  U R                  5       U R                  5        T5      $ re  )
_hash_spanr#  r   r&  )rZ  code_hashesr   s    r+   ri  +Markdown._hash_html_spans.<locals>.<lambda>_  s'    dooahhqwwy!%%'&BKPr-   r   r   rf   r  r   )_code_span_rer   r  r   r   r  r   r  rS  r   r  r   r  extend_encode_incomplete_tagsrN  r   r   )r   rK   r  r  tokensru  r  r  is_code
is_commentr   coder  r  s   `           @@r+   r   Markdown._hash_html_spansD  s   	W	7 !!%%P

 3399$?c,''"QY!^N 'E#E1Gd&8&8&?&?(/
MM$//$2E2EjFVFVWXFY2Z"[\MM$"5"5j6F6Fq6I"JKMM$//$2E2EjFVFVWXFY2Z"[\**007?MM$"<"<U"CDMM$//$2E2Ee2L"MNGl5!)<=
d::5ABQJE1 c,''4 wwv$**,IC<<*D -r-   c                 6   SnX:w  a  U(       a=  [        U R                  R                  5       5       H  u  pVUR                  XV5      nM     U(       a=  [        U R                  R                  5       5       H  u  p5UR                  XS5      nM     UnX:w  a  M  U$ )zz
Recursively unhash a block of text

Args:
    spans: unhash anything from `self.html_spans`
    code: unhash code blocks
r   )r  r   r   r   r   )r   rK   spansr  origr   	sanitizeds          r+   r   Markdown._unhash_html_spans  s     l&*4??+@+@+B&CNC<<7D 'D!%d&6&6&<&<&>!?ID<<2D "@D l r-   r#   c                     U R                   S:X  a  U R                  $ U R                   S:X  a"  / SQnU H  u  p4UR                  X45      nM     U$ [        SU R                   -  5      e)Nr   r   )&&amp;)rc  r  )r   r  zAinvalid value for 'safe_mode': %r (must be 'escape' or 'replace'))r;   r   r   r/   )r   r#   replacementsbeforeafters        r+   rS  Markdown._sanitize_html  so    >>Y&)))^^x'L
 ".IIf, ".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                 |    U R                   R                  X5      nU(       a  UR                  5       $ [        U5      $ )z\Returns the index of the first non-whitespace character in text
after (and including) start
)_whitespacer   r&  r   )r   rK   r   r   s       r+   _find_non_whitespaceMarkdown._find_non_whitespace  s1       &&t3#uyy{2T2r-   open_cclose_cc                     Un[        U5      nSnUS:  a2  XV:  a-  X   U:X  a  US-  nOX   U:X  a  US-  nUS-  nUS:  a  XV:  a  M-  U$ )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.
rf   r   r   )r   rK   r   r  r  r@  lr  s           r+   _find_balancedMarkdown._find_balanced  se    
 IaiAEw& 
G#
FA aiAE r-   z
        data:
        # in format type/subtype;parameter=optional
        (?P<mime>\w+/[\w+\.-]+(?:;\w+=[\w+\.-]+)?)?
        # optional base64 token
        (?P<token>;base64)?
        ,(?P<data>.*)
    r  c                 @   U(       d  U$ U R                   R                  U5      nSnUbG  UR                  S5      =(       d    SnUR                  S5      (       a  UR                  S5      S:X  a  Sn[	        XR
                  US9n[        U5      nXPR                  U'   U$ )	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)r;   charset)_data_url_rer   r   r  _html_escape_urlr;   r,   r   )r   r  data_urlr   r  r   s         r+   _protect_urlMarkdown._protect_url  s      J$$**3/>>&)/RDx((X^^G-D	-Q snngNo"%3
r-   z#(?:https?|ftp):\/\/|(?:mailto|tel):c                     SnSnSR                  X5      nSX-   -  n[        R                  " SR                  U R                  X4U5      [        R                  5      $ )a*  
_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_hrefMarkdown._safe_href  sj     ;	IPPQU\t/0zzBII$J^J^`frz{}  ~B  ~B  C  	Cr-   c                 l    [        U S5      nUR                  U5      (       a  UR                  U5      nU$ )aa  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)LinkProcessorrl   rm   )r   rK   link_processors      r+   r  Markdown._do_links
  s6     'tT2t$$!%%d+Dr-   r   nc                     [        U5      nU(       a  [        U[        5      (       a  US-   U-   nU R                  U==   S-  ss'   S[	        U5      :X  d  U R                  U   S:  a  USU R                  U   -  -  nU$ )ap  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  rf   r   z-%s)_slugifyr   r   r   r   )r   rK   r   r  	header_ids        r+   header_id_from_textMarkdown.header_id_from_text  s~    & TN	j--y0I""9-2-I$"<"<Y"G!"K!;!;I!FFFIr-   c                     [        U5      nU R                  S   R                  S5      nU(       a  [        U[        5      (       a  US-   U-   nX R
                  ;   =(       d    U[        S U R                  5      ;   $ )Nr   r   r  c                     U S   $ r   r1   )xs    r+   ri  ,Markdown._header_id_exists.<locals>.<lambda>;  s    UVWXUYr-   )r  r<   r   r   r   r   mapr   )r   rK   r  r   s       r+   _header_id_existsMarkdown._header_id_exists6  sh    TN	\*..x8j--y0I666e)s>[_[d[dGe:eer-   levelr  rj   c                     XR                   :  a  g U R                  c  / U l        U R                  R                  XU R                  U5      45        g re  )r   r   r   r   )r   r   r  rj   s       r+   _toc_add_entryMarkdown._toc_add_entry=  sB    ??"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                    UR                  S5      b&  UR                  S5      S:X  a  UR                  S5      $ UR                  S5      b,  SSS.UR                  S5      S      nUR                  S5      nO+[        UR                  S5      5      nUR                  S5      nU R                  R                  S	5      nU(       a  [	        X$-   S5      nS
nSU R                  ;   a;  U R                  UU R                  S   R                  S5      U5      nU(       a  SU-  nU R                  U5      nSU R                  ;   a  W(       a  U R                  X&U5        SX%Xr4-  $ )z#Handles processing markdown headersrf   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   r<   r   minr  rf  r"  )r   r   r  header_groupdemote_headersheader_id_attrr  rX  s           r+   _h_subMarkdown._h_subT  s1   ;;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d3$4'CCCr-   z\
        ^<h([1-6])(.*)>  # \1 tag num, \2 attrs
        (.*)  # \3 text
        </h\1>
    c                    UR                   UR                  5       UR                  5        n[        UR	                  S5      5      n[
        R                  " SUR	                  S5      =(       d    S5      =(       d    SnU(       a  UR	                  S5      =(       d    SnUR                  S5      nUR	                  S5      nU(       a  U R                  U5      (       a  U$ U=(       d.    U R                  XPR                  S   R                  S5      U5      nS	U R                  ;   a  U R                  X6U5        U(       a  U(       d  US
S SU-  -   USS
 -   $ U$ )zIDifferent to `_h_sub` in that this function handles existing HTML headersrf   z.*?id="(\S+)?".*r   r   z'" r  r   r   r   Nr&  )r#  r   r&  r   r   r   r   r  r  r  r<   r   r"  )r   r   rK   h_levelid_attrh_textr  s          r+   rW  Markdown._h_tag_subu  s   ||EKKM599;7ekk!n%88/Q1E2FL"mmA&,"G--'Q t--g66K qt77L@Y@]@]^f@gipq	DKKF;W8j944tABx??r-   c                     SU R                   ;   a&  U R                  R                  U R                  U5      $ U R                  R                  U R                  U5      $ )Nztag-friendly)r<   _h_re_tag_friendlyr   r+  _h_rer   s     r+   r  Markdown._do_headers  sF      T[[(**..t{{DAAzz~~dkk400r-   z*+-z(?:[%s]|\d+\.)z(?:[%s])z	(?:\d+\.)c                    UR                  S5      nUR                  S5      U R                  ;   =(       a    S=(       d    SnUS:X  a-  UR                  S5      S:w  a  SUR                  S5      S S -  nOSnX@R                  U5      -   nU R                  U5      nU R                  (       a  S	R                  X4XS5      $ S
R                  X4XS5      $ )Nrf   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_optsr  s         r+   	_list_subMarkdown._list_sub  s    kk!n;;q>T%:%::CtKttA$ 6$u{{1~cr'::HH;;HEE))#.??&--h&SS(//FUUr-   c                 R   Sn / nU R                   U R                  4 GH#  nU R                  S-
  nX@R                  :X  a  U R                   OU R                  nSXTXF4-  nU R                  (       aK  [        R
                  " SU-   [        R                  [        R                  -  [        R                  -  5      nOJ[        R
                  " SU-   [        R                  [        R                  -  [        R                  -  5      nUR                  X5      n	U	(       d  GM  UR                  U	R                  5       U	45        GM&     U(       d   U$ UR                  5         US   S   n	U	R                  5       u  pU R                  U	5      nUS U
 U-   XS  -   nU
[        U5      -   nGM  )Nr   rf   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_olr:   r   r   r   r  r   Sr   r   r   r   r"  r?  r   )r   rK   poshits
marker_patr  other_marker_pat
whole_listlist_rer   r   r&  r\  s                r+   r  Markdown._do_lists  sg   
  D#@
 $ 26@OO6S4??Y]YhYh 4 %*O5P
6 ?? jjZrtt9KLG jj)?
)J)+rtt);=Gt15KK 67K AL   IIKGAJEJE^^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                     UR                  S5      nUR                  S5      nUS;   a  U R                  SU4-  $ US:X  a  U R                  SU4-  $ g)Nrf   r   )z[x]z[X]zchecked z[ ]r   )r   _task_list_warpper_str)r   r   marker	item_texts       r+   _task_list_item_subMarkdown._task_list_item_sub  s[    QKKN	]"..*i1HHHu_.."i@@ r-   c                 8   UR                  S5      nUR                  S5      nU(       d  SU;   d  U R                  (       a0  U R                  USU R                  S9S   nU R	                  U5      nONU R                  U R                  USS9S   5      nUR                  S5      (       a  US S nU R                  U5      n[        UR                  S	5      5      S
:H  U l        SU R                  ;   a&  U R                  R                  U R                  U5      nSU-  $ )Nr!   rf   r   r   )min_outdentmax_outdent)rT  r   r.  r   r   	task_listz<li>%s</li>
)r   _last_li_endswith_two_eols_uniform_outdentr   r   r  r7  rf  r   r<   _task_list_item_rer   rQ  )r   r   r  leading_lines       r+   _list_item_sub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                     U =R                   S-  sl         SU l        UR                  S5      S-   nU R                  R	                  U R
                  U5      nU =R                   S-  sl         U$ )Nrf   Fr   )r   rW  r8  _list_item_rer   r[  )r   r]  s     r+   r;  Markdown._process_list_items%  s^    0 	1*/'??4(4/%%))$*=*=xH1r-   
lexer_namec                      SSK JnJn   UR	                  U5      $ ! [         a     gf = f! UR
                   a     gf = f)zY
Returns:
    `pygments.Lexer` or None if a lexer matching `lexer_name` is
    not found
r   )lexersutilN)pygmentsrc  rd  ImportErrorget_lexer_by_nameClassNotFound)r   ra  rc  rd  s       r+   _get_pygments_lexerMarkdown._get_pygments_lexerD  sM    	-	++J77  		 !! 		s    , 
))??	codeblockc                     SSK nSSKn " S SUR                  R                  5      nUR	                  SS5        U" S0 UD6nUR                  XU5      $ )z
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                   *    \ rS rSrS rS rSS jrSrg)8Markdown._color_with_pygments.<locals>.HtmlCodeFormatterie  c              3   4   #    Sv   U Sh  vN   Sv   g N	7f)zGA function for use in a Pygments Formatter which
wraps in <code> tags.
)r   r  N)r   r  r1   r   rt   s     r+   
_wrap_codeCMarkdown._color_with_pygments.<locals>.HtmlCodeFormatter._wrap_codef  s!      "!   "" !   

c              3   4   #    Sv   U S h  vN   Sv   g  N	7f)N)r   r   r1   rp  s     r+   _add_newlineEMarkdown._color_with_pygments.<locals>.HtmlCodeFormatter._add_newlinen  s         !rs  Nc           	          Uc/  U R                  U R                  U R                  U5      5      5      $ U R                  U R                  U R                  U R                  U5      5      5      5      $ )z,Return the source with a code, pre, and div.)ru  	_wrap_prerq  	_wrap_div)r   sourceoutfiles      r+   wrap=Markdown._color_with_pygments.<locals>.HtmlCodeFormatter.wrapt  sY    ?,,T^^DOOF<S-TUU  >>$*;*;DNN4??[aKb<c*deer-   r1   re  )r2   r3   r4   r5   rq  ru  r|  r6   r1   r-   r+   HtmlCodeFormatterrn  e  s    #fr-   r~  cssclass
codehiliter1   )re  pygments.formatters
formattersHtmlFormatterr   	highlight)r   rk  lexerformatter_optsre  r~  	formatters          r+   _color_with_pygmentsMarkdown._color_with_pygmentsS  sV     	"	f 3 3 A A 	f0 	!!*l;%77	!!)I>>r-   c                 4   UR                  S5      nU R                  U5      nU R                  U5      nUR                  S5      nUR	                  5       nU R                  S5      nU R                  S5      nU R                  U5      nSR                  X4U5      $ )Nrf   r   prer  z!
<pre{}><code{}>{}
</code></pre>
)r   _outdentr   r  r8  r:  _encode_coder!  )r   r   rk  pre_class_strcode_class_strs        r+   _code_block_subMarkdown._code_block_sub  s    KKN	MM),	KK	*	$$T*	$$&	55e<66v>%%i0	5<<96 	6r-   rY  c                     SU R                   ;  a  g U R                   S   n[        U[        5      (       a  X;   a  SX!   -  $ g! [         a     gf = f)z_Get the appropriate ' class="..."' string (note the leading
space), if any, for the given tag.
zhtml-classesr   z class="%s")r<   r   r   	TypeError)r   rY  html_classes_from_tags      r+   r:  !Markdown._html_class_str_from_tag  sd     ,	F$(KK$?! /66/(+@+EEE  		s   A 
AAc                     [         R                  " SU R                  U R                  4-  [         R                  [         R                  -  5      nUR                  U R                  U5      $ )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   r:   r   r  r   r  )r   rK   code_block_res      r+   r  Markdown._do_code_blocks  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                     UR                  S5      R                  S5      nU R                  U5      nSR                  U R	                  S5      U5      $ )Nr   rm  z<code{}>{}</code>r  )r   r  r  r!  r:  )r   r   cs      r+   _code_span_subMarkdown._code_span_sub  sI    KKN  'a "))$*G*G*OQRSSr-   c                 N    U R                   R                  U R                  U5      $ re  )r  r   r  r   s     r+   r  Markdown._do_code_spans  s#    0 !!%%d&9&94@@r-   c                 x    / SQnU H  u  p4UR                  X45      nM     [        U5      nXPR                  U'   U$ )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   rK   r  r  r  hasheds         r+   r  Markdown._encode_code  sB    

 *MF<<.D *D!!'r-   a   
        (?:_{1,}|\*{1,})?  # ignore any leading em chars because we want to wrap `<strong>` as tightly around the text as possible
                           # eg: `***abc***` -> `*<strong>abc</strong>*` instead of `<strong>*abc*</strong>`
                           # Makes subsequent <em> processing easier
        (\*\*|__)(?=\S)    # strong syntax - must be followed by a non whitespace char
        (.+?)              # the strong text itself
        (?<=\S)\1          # closing syntax - must be preceeded by non whitespace char
        z(\*|_)(?=\S)(.*?\S)\1c                     U R                   (       d  [        U S 5      U l         U R                   R                  U5      (       a  U R                   R                  U5      nU$ re  )_iab_processorGFMItalicAndBoldProcessorrl   rm   r   s     r+   r  Markdown._do_italics_and_bold  sL    """;D$"GD##D))&&**40D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                 P    [         R                  " SSUR                  S5      5      $ )Nz(?m)^  r   rf   )r   r   r   r   r   s     r+   _dedent_two_spaces_subMarkdown._dedent_two_spaces_sub  s    vvj"ekk!n55r-   c                    UR                  S5      nSU R                  ;   =(       a    U R                  R                  U5      nU(       a  U R                  R                  SU5      nOU R                  R                  SU5      nU R                  R                  SU5      nU R                  U5      n[        R
                  " SSU5      nU R                  R                  U R                  U5      nU(       a  SU-  $ SU-  $ )Nrf   spoilerr   z(?m)^  z/<blockquote class="spoiler">
%s
</blockquote>

z<blockquote>
%s
</blockquote>

)r   r<   _bq_all_lines_spoilersr   _bq_one_level_re_spoilerr   _bq_one_level_rer   r   r   _html_pre_block_rer  )r   r   bq
is_spoilers       r+   _block_quote_subMarkdown._block_quote_sub  s    [[^$++-W$2M2M2S2STV2W
..222r:B&&**2r2B""&&r2.""2&VVGT2&$$(()D)DbIH2MM82==r-   c                     SU;  a  U$ SU R                   ;   a&  U R                  R                  U R                  U5      $ U R                  R                  U R                  U5      $ )Nr   r  )r<   _block_quote_re_spoilerr   r  _block_quote_rer   s     r+   r  Markdown._do_block_quotes3  sX    d?K#//33D4I4I4PP''++D,A,A4HHr-   c                    UR                  S5      n/ n[        [        R                  " SU5      5       GH  u  p4X@R                  ;   a   UR                  U R                  U   5        M5  S nSU R                  ;   a  U R                  R                  US-   5      nU(       a  [        UR                  S5      5      S::  a  UR                  S5      (       a*  UR                  S5      S   UR                  S5      S   :X  d  UR                  S5      cX  UR                  5       nU R                  XGS  5      R                  S5      n[        R                  " S	U5      (       a  US U nOUnS nU R                  U5      nUR                  S
U R!                  S5      -  UR#                  S5      -   S-   5        U(       d  GM  UR                  U5        GM     SR%                  U5      $ )Nr   z\n{2,}zcuddled-listsr   r  next_markerrO  r.  z^<(?:ul|ol).*?>z<p%s>prm  </p>r   )r  r6  r   r   r~   r   r<   r_  r   r   r   r   r  r8  r   rf  r:  r  rN  )r   rK   grafsr@  grafcuddled_listlir   s           r+   r  Markdown._form_paragraphs<  s    zz$  )T!:;GA'''T--d34#"dkk1 ++224$;?B s288A;/14%'XXm%<%<(ASTVAW[][c[cdq[rsu[vAv$&HH]$;$C !#
'+~~d6l'C'J'J4'P88$6EE#'<D $0D+/L ++D1Wt'D'DS'IIDKKX]L^^aggh<LL.K <N {{5!!r-   c           	        ^  T R                   (       Ga  SST R                  -   S/nT R                  (       d  ST l        T R                  (       d  ST l        T R                  R                  U 4S jS9  [        T R                  5       H  u  p4US:w  a  UR                  S	5        UR                  S
U-  5        UR                  T R                  T R                  T R                   U   5      5      5         ST R                  -   S-   T R                  -   S-   XCS-   4-  nUS   R                  S5      (       a  US   S [        S5      *  S-   U-   S-   US'   OUR                  SU-  5        UR                  S5        M     UR                  S5        UR                  S5        US-   SR                  U5      -   $ U$ ! [         a!    [        R                  S5        SXCS-   4-  n Nf = f)Nz<div class="footnotes">rk  z<ol>z%Jump back to footnote %d in the text.z&#8617;c                 h   > [        TR                  R                  5       5      R                  U 5      $ re  )r  r   keysru  )ar   s    r+   ri  )Markdown._add_footnotes.<locals>.<lambda>|  s#    dnn6I6I6K1L1R1RST1Ur-   r   r   r   z<li id="fn-%s">z4<a href="#fnref-%s" class="footnoteBackLink" title=""></a>rf   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.  r  z&#160;z

<p>%s</p></li>z</ol>z</div>r   r   )r   r   r>   r?   r   r   r6  r   r   r   r  r1  r2  r7  r   rN  )r   rK   footerr@  r  backlinks   `     r+   r   Markdown._add_footnotesl  s   >>>)111F &&&M#...7+
 ""'U"V"4#4#456MM"%/"45,,--dnnR.@A3!&(,(;(;!<>B!C !77!8 #	!# (*Q3i	 0H ":&&v..!'Mc&k\!:""#%-".06"7F2J MM-(":;g&; 6< MM'"MM(#&=499V#444K% ! 3II H I!& *,qS	!2H3s   5)F::(G%$G%z<(?![a-z/?\$!])z(?<![a-z0-9?!/'"-])>c                     [         R                  SU5      n[        R                  SU5      nU R                  R                  SU5      nU R                  R                  SU5      nU$ )Nr  z&amp;\1r  r  )_AMPERSAND_REr   _ESCAPED_AMPERSAND_RE_naked_lt_re_naked_gt_rer   s     r+   r   Markdown._encode_amps_and_angles  sa       $/$((T:   $$VT2
   $$VT2r-   z*\\*<(!--|/?\w+?(?!\w)\s*?.+?(?:[\s/]+?|$))c                    ^  T R                   S;  a  U$ T R                  U5      (       a  U$ U 4S jnT R                  R                  X!5      nU$ )Nr   c                    > U R                  5       nTR                  R                  U5      (       d  UR                  SS5      nUR                  SS5      $ )Nr  r  rc  )r   r  r   r   )r   rK   r   s     r+   incomplete_tags_sub=Markdown._encode_incomplete_tags.<locals>.incomplete_tags_sub  sF    ;;=D((..t44||E62<<V,,r-   )r;   r  _incomplete_tags_rer   )r   rK   r  s   `  r+   r   Markdown._encode_incomplete_tags  sN    >>!66Kd##K	- ''++,?Fr-   c                     [        U R                  R                  5       5       H  u  p#UR                  SU-   U5      nM     U$ )Nr/  )r  r   r   r   )r   rK   chr   s       r+   r  "Markdown._encode_backslash_escapes  s;    t11779:JB<<R0D ;r-   z<((https?|ftp):[^\'">\s]+)>c                 f    UR                  S5      nSR                  U R                  U5      U5      $ )Nrf   <a href="{}">{}</a>)r   r!  r  )r   r   g1s      r+   _auto_link_subMarkdown._auto_link_sub  s-    [[^$++D,=,=b,A2FFr-   z
          <
           (?:mailto:)?
          (
              [-.\w]+
              \@
              [-\w]+(\.[-\w]+)*\.[a-z]+
          )
          >
        c                 `    U R                  U R                  UR                  S5      5      5      $ r   )_encode_email_addressr   r   r  s     r+   _auto_email_link_subMarkdown._auto_email_link_sub  s+    ))((Q8: 	:r-   c                     U R                   R                  U R                  U5      nU R                  R                  U R                  U5      nU$ re  )r  r   r  r  r  r   s     r+   r  Markdown._do_auto_links  sC    !!%%d&9&94@''++D,E,EtLr-   addrc                     SU-    Vs/ s H  n[        U5      PM     nnSSR                  U5      < SSR                  USS  5      < S3nU$ s  snf )Nzmailto:	<a href="r   r     r  ) _xml_encode_email_char_at_randomrN  )r   r  r  charss       r+   r  Markdown._encode_email_address  s_     %t+-+R 2"5+ 	 - ''%."''%)"46-s   Ac                 <   [        U R                  R                  5       5      [        U R                  R                  5       5      -   nU[        S U R                  R                  5        5       5      -  n UnU H  u  pEUR                  XT5      nM     X:X  a   U$ M(  )Nc              3   J   #    U  H  n[        [        U5      5      v   M     g 7fre  )tuplereversed).0r@  s     r+   	<genexpr>3Markdown._unescape_special_chars.<locals>.<genexpr>  s     N5Mx{++5Ms   !#)r  r   r   r   r~   r   )r   rK   hashmap	orig_textr  hashs         r+   r    Markdown._unescape_special_chars  s    **0023eD<L<L<R<R<T6UU5NT5E5E5K5K5MNNNI#||D- $  r-   c                 :    U R                   R                  SU5      $ r  )r   r   r   s     r+   r  Markdown._outdent	  s    ##B--r-   
hash_tablec                 J    [        U5      nUb  XU'   U$ XR                  U'   U$ )a'  
Wrapper around `_hash_text` that also adds the hash to `self.hash_spans`,
meaning it will be automatically unhashed during conversion.

Args:
    text: the text to hash
    hash_table: the dict to insert the hash into. If omitted will default to `self.html_spans`

Returns:
    The hashed text
)r,   r   )r   rK   r  r   s       r+   r  Markdown._hash_span		  s5     !"sO 
 $(OOC 
r-   rT  rU  c                    U R                  5        Vs/ s H&  nU(       a  [        R                  " SU5      S   OSPM(     nnU Vs/ s H	  oUc  M  UPM     nnU(       d  SU 4$ [        U5      nUb-  [        U Vs/ s H  oUU:  d  M
  UPM     sn=(       d    U/5      nUb  [        Xr5      n/ n[	        X@R                  S5      5       H|  u  pUR                  U5      (       a$  UR                  UR                  USS5      5        M?  U	b)  X:  a$  UR                  UR                  U	SS5      5        Mk  UR                  U5        M~     USR                  U5      4$ s  snf s  snf s  snf )a#  
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   Trf   )	r5  r   r	  r'  zipr  r   r   rN  )
rK   rT  rU  rA  
whitespacer@  whitespace_not_emptyoutdent	outdentedline_wss
             r+   rX  Markdown._uniform_outdent	  sY   $ ).
) 04BJJz4(+=) 	 .
 ,6G:a:G $t8O *+"&:O&:;>N1&:O`T_S`aG"'/G	 __T-BCMGw''  gr1!=>$):  gr1!=>  & D 	***;.
  H Ps   -EE E :	E%E%indentinclude_empty_linesindent_empty_linesc                    / nU R                  S5       H_  nUR                  5       (       d  U(       a  UR                  X-   5        M4  U(       a  UR                  U5        MN  UR                  S5        Ma     SR                  U5      $ )a  
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   )r5  r  r   rN  )rK   r  r  r  blocksrA  s         r+   _uniform_indentMarkdown._uniform_indentK	  sc      OOD)Dzz||1fm,$d#b! * wwvr-   substrc                    [         R                  " [         R                  " U5      U 5       HS  nUR                  5       u  pEXAR	                  5       s=::  a  U::  a     g  XAR                  5       s=::  a
  U::  d  MO     g  MU     g)zF
Checks if a regex match overlaps with a substring in the given text.
TF)r   finditerr   r"  r   r&  )rK   r   r  instancer   r&  s         r+   _match_overlaps_substrMarkdown._match_overlaps_substre	  sf    
 BIIf$5t<H!JE,, -		*s* +	 = r-   )r   r   r   r   r  r   rW  r   r   r   r   rM   r   rk   r<   r   r?   r>   r   r~   r   r=   r   r   r;   r   r:   r}   r|   r@   )F)TFre  NN)FF)r2   r3   r4   r5   _extras_dict__annotations__r   r   r   r   r   
_safe_moder  r  r   r   rP   floatr   r   r   r   DEFAULT_TAB_WIDTHbool_extras_param_link_patternsr   r   r   
IGNORECASEVERBOSEr   rI   r   rz   r`   r   rR   r   r!  	MULTILINEr  r
  r  r  r  r   UNICODEr   DOTALLr4  Matchr   r   rH  r   
_html5tagsrq  r  _strict_tag_block_re_block_tags_brs  rr  rT  r   r`  rS   r   r   rp  r  rT   r   r  r  r   r  rU   r   r[   rf  r  r  r]   r  r  r   r   rS  rE  _inline_link_title_tail_of_reference_link_rer  _strip_anglebracketsr  r  r  r  r  propertyr  r^   r  r  r  r"  
_h_re_baser4  r3  r+  rV  rW  rV   r  r9  _marker_anyrC  rD  r?  rW   r  r_  rY  rN  rQ  rW  r[  r;  ri  r  r  r:  rX   r  r  r  r\   r  r  
_strong_re_em_rer  r_   r  _block_quote_baser  r  r  r  r  r  r  r  rY   r  rZ   r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  staticmethodrX  r  r  r6   r1   r-   r+   rH   rH     s!    W%%
sCx.cNc3hS#X)s)$4c4
##
uS#s]#
$$ JL=L zz+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 ~$6 ~@] !!"   #   !s s  "&  % F')ABBLLSUS]S]D] 

V
 

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

BD(bhhsm ( (eC eDcN eN	( 	( 	(!3 !3 !0 hJ ZMZM:: 
' 
' 	rtt kMZM	M 
 JJ 
( 
( 	rtt  ZZ$&
 2%RXXc]C'(2% 2% 
	2%h  rc r r r !rr #11 1 C5#:&	1
 1 
1fSs S# S$ S  BC BC B !B6288C= S rxx}  I I IB ZZDbddKF!!"S S  #<   !C C  "4 !jj *. TT/6 zz"78$$%  #   #    &  D  ?S ?S ? !?Bs s &K K K   % TTBDD[ "$ - TTBDD[" **V$K::k23 3S 3S 33 s C # RU $ ::  
L  * =OC C" c c  "   C= 
	:fc fd fJC JS J J JJ JJzC'5EJ$4bddRTTkBDBHHSM Dc D6 

  
	I # 2 1 1 1 1& #&66K..JJVrxx} V V$ 9c 9c 9 9v JJ   F;,
rttbddM  % 
rtt	
 f	# 	3 	 "'&BHHSM &c &&C C >c ,?,?
 
,?\6RXXc] 6s 6C C   !!"=C =C = #=4 JJ   TTBDD[MTBHHSM Tc T
   !A3 A3 A "A2  &   	rtt	J ZZ0"$$7FN%%&   ' jj!2R!7EO jj):[)H"$$QSQUQU+Vzz"2BDD9!zz*BBDDIZZ(MrttT$:BDDA6BHHSM 6c 6>bhhsm > >* ""#IS IS I $I   !-"S -"S -" "-"^33 33 3j ::0"$$7L::9244@LC C  **%RSC C $c c 
 JJ=rttDMGBHHSM Gc G ** 	& TTBDD[244	!:"((3- :C :3 3 
# # (C C .S .S .s  # &  &*%),+,+c],+ c],+ 
sCx	,+ ,+\  %*#(	 " !	
 
 2 
S 
# 
 
PT 
 
r-   rH   c                        \ rS rSrSrSS/rSrg)MarkdownWithExtrasis	  ab  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-blocksr1   N)r2   r3   r4   r5   __doc__r<   r6   r1   r-   r+   r0  r0  s	  s    
 /0Fr-   r0  c                   "   \ rS rSr% 0 r\\\S    4   \S'   0 r	\\
\\\S       \\S       4   4   \S'   \\S'    \\\\
\S    4      \\\
\S    4      4   \S'    S\S\\   4S jr\S	 5       r\S
 5       r\S\S\4S j5       rS\S\4S jrSrg)rh   i	  r   ri   rj   rg   rn   optionsc                 2    Xl         Ub  X l        g0 U l        g)zh
Args:
    md: An instance of `Markdown`
    options: a dict of settings to alter the extra's behaviour
Nrn   r4  )r   rn   r4  s      r+   r   Extra.__init__	  s     ")"5w2r-   c                     U R                   U R                  ;   a  U R                  U R                   	 [        R                  R	                  5        H+  nU H"  nX;   d  M
  UR                  U 5        X;   a  M  M$     M-     g)zL
Removes the class from the extras registry and unsets its execution order.
N)rj   r   rh   ri   valuesremove)cls
exec_ordersections      r+   
deregisterExtra.deregister	  s_    
 88s}}$chh'++224J%nNN3' n & 5r-   c                 *   X R                   U R                  '   [        / U R                  S   QU R                  S   Q75       GHL  u  pU[	        U R                  S   5      :  n[        U[        5      (       dz  [        U[        5      (       ae  [        R                  R                  5        HA  nU H8  nX%;   d  M
  UR                  U5      nU(       d  US-  nUR                  X`5        M:     MC     M  [        R                  R                  U/ / 45        U [        R                  U   U(       a  SOS   ;   a  M  U(       a)  [        R                  U   S   R                  SU 5        GM'  [        R                  U   S   R                  U 5        GMO     g)zv
Registers the class for use with `Markdown` and calculates its execution order based on
the `order` class attribute.
r   rf   N)r   rj   r6  rg   r   r   rP   
issubclassrh   ri   r9  ru  insertr   r   )r;  ru  r  r  exec_ordersr=  to_indexs          r+   registerExtra.register	  s;    #&chh$%Csyy|%Cciil%CDKES1..FdE**z$/F/F#(#4#4#;#;#=K#.?'.}}T':H#) (A#NN89 $/ $> !!,,TB8<%++D1v!1EE%%d+A.55a=%%d+A.55c:+ Er-   rK   r$   c                     g)zd
Run the extra against the given text.

Returns:
    The new text after being modified by the extra
Nr1   r   s     r+   rm   	Extra.run	  s     	r-   c                     g)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+   rl   
Extra.test	  s     r-   r6  N)r2   r3   r4   r5   r   r   r   typer  ri   rP   r  r  r   r   rH   r   r   classmethodr>  rE  r	   rm   r  rl   r6   r1   r-   r+   rh   rh   	  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-   rh   c                   $  ^  \ rS rSrSrSr\R                  4\R                  44r\	R                  r\	R                  rS\	S\\   4U 4S jjrS\4S jr\S	\R*                  \   S
\4S j5       rS	\R*                  \   S
\4S jrS\4S jrSrU =r$ )ItalicAndBoldProcessori	  a}  
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-processorrn   r4  c                 2   > [         TU ]  X5        0 U l        g re  superr   r  r   rn   r4  	__class__s      r+   r   ItalicAndBoldProcessor.__init__	      %r-   rK   c                 z   U R                   R                  [        R                  :  aN  U R                  R                  U R
                  U5      nU R                  R                  U R
                  U5      nU$ SnX!:w  a=  UnU R                  R                  5        H  u  p4UR                  X45      nM     X!:w  a  M=  U$ r  )
rn   rg   rP   r_   	strong_rer   em_rer  r   r   )r   rK   r  r   r  s        r+   rm   ItalicAndBoldProcessor.run	  s    77==5000>>%%dhh5D::>>$((D1D  I# 	#'??#8#8#:KC<<4D $; # r-   r   r$   c                 X    UR                   UR                  5       UR                  5        $ re  )r#  r   r&  r  s     r+   r   ItalicAndBoldProcessor.sub
  s!     ||EKKM599;77r-   c                     UR                   UR                  5       UR                  5        nU R                  R	                  X R
                  5      $ re  )r#  r   r&  rn   r  r  )r   r   r  s      r+   sub_hashItalicAndBoldProcessor.sub_hash
  s7    ekkmUYY[9ww!!&//::r-   c                     U R                   R                  [        R                  :  a  SU;   =(       d    SU;   $ U R                  =(       a    [
        R                  " SU5      $ )Nr  r  md5-[0-9a-z]{32})rn   rg   rP   r_   r  r   r   r   s     r+   rl   ItalicAndBoldProcessor.test

  sF    77==5000$;-#+-G299-@$#GGr-   r  )r2   r3   r4   r5   r2  rj   rP   r_   rg   rH   r+  rW  r,  rX  r   r   r   r   rm   r	   r   r!  r   r]  rl   r6   __classcell__rS  s   @r+   rN  rN  	  s     'D""$u'<'<&>>E##IOOE8 htn   8# 83 8 8;bhhsm ; ;H H Hr-   rN  c                      \ rS rSrSrSr\R                  4\" 5       4r	S\
4S jr   S#S\R                  \
   S\R                  \
   S	\\R                  \
      S
\\
   S\\
   S\\\
   \\   4   4S jjrS\R                  \
   S\R                  \
   S\\R                  \
      S\\R                  \
   \4   S\\R                  \
      S\\\R                  \
   \\R                  \
      4   \S   4   4S jr S$S\R                  \
   S\R                  \
   S\\R                  \
   \4   S\\\R                  \
   \\R                  \
      \\R                  \
      4      4S jjrS\R                  \
   4S jr\R4                  " SS9S\
S\
4S j5       rS\R                  \
   S\R                  \
   4S jr\R4                  " SS9S\
4S j5       rS\\R                  \
      4S  jrS\
4S! jr S"r!g)%r  i
  z
An upgraded version of the `ItalicAndBoldProcessor` that covers far more edge cases and gets close
to Github Flavoured Markdown compliance.
zgfm-italic-and-bold-processorrK   c                 t   SnSnU(       Ga  U[        U5      :w  Ga  [        U5      nSn/ / S.n 0 0 S.n / / S.n / n Sn [        R                  " SU5      n	U R                  U	5      n
U
(       Ga  U
u  pnU R                  U	5      n
UR	                  S5      nUS   nU(       a	  XO   (       d  U(       a  XO   R                  U5        M`  XO   (       aV  U R                  XO   S   U5      (       a:  XO   R                  S5        XO   (       a  U R                  XO   S   U5      (       a  M:  XO   (       d  U(       a  XO   R                  U5        M  XO   R                  S5      nUR                  5       U:  a  SnGM  X_   R                  US5      nUR	                  S5      US  nS nUU:w  a  U R                  UXU   X_   Xo   5      nUSLa<  US   nUS   U:w  a-  US   nX_   R                  US5      nUR	                  S5      US  nOmU R                  UXU   U
5      (       dR  UX_   U'   XO   R                  U5        U(       a  SX_   U'   XO   R                  U5        OXo   R                  U5        GM	  UR                  UR                  UUR                  5       U-    5        U R                  UUUUUS	9u  nnUR                  U5        Uc  [        U5      nOwU[        U5      :  a  UX_   U'   XO   R                  U5        OMU[        U5      :  a>  XO   (       a5  XO   S   nUR	                  S5      n[        U5      [        U5      U-
  :  a  SnUR                  5       U-   nU
(       a  GM  U[        U5      :  a  UR                  XS  5        SR                  U5      nU(       a  U[        U5      :w  a  GM  U$ )
NTr   F)r  r  r   z(\*+|_+)rf   r.  )open_syntaxclose_syntax)r,   r   r  	_next_runr   r   body_crosses_span_borderspopr   
has_middle(should_process_imbalanced_delimiter_runsr#  process_spanr  r   rN  )r   rK   nestingr  opensunused_opensunused_closesr  ru  delim_runs_iternext_delim_run	delim_runleftrightsyntaxem_typerE   open_offsetrg  r\  rl  r"  close_syntax_used_chars	prev_openprev_open_syntaxs                            r+   rm   GFMItalicAndBoldProcessor.run
  s   	)z$'77"4(IG2&EN!#"-L #%2.M F\EJ kk+t<O!^^O<N )7&	!%!@"+ ) EN--i8 n)G)GWYHZ\e)f)fN&&r* n)G)GWYHZ\e)f)f~--i8~))"-::<%' #G
 +377a@"jjmKL9 &(!%iw$-}/E"J
 ".!+A%a=D0#-a=D*6*?*C*CD!*LK*.**Q-*EK!JJig)>  7B-d3--d3?@L1)<!N11)<)299)D  i..udjjl[6PQR040A0A)V +& 1B 1-- d#*2.1&k+,s6{:7NL))4N)))4,s;/??EN !&r 2I'0q'9$+,[1AD[1[\"& "),CCw !.z s4y d6l+776?Dw )z$'77z r-   NrE   rG   r\  rg  rh  r$   c                 >   U=(       d    [        [        UR                  S5      5      nU(       a  UR                  S5      OSnU=(       d    [        [        UR                  S5      5      n[        [	        XE5      5      nU(       a  [        [	        [        XE5      U5      5      OSnUSXx-   *  SUS-  -  SUS-  -  /n	U(       a  [        U5      S:X  a  SOS	n
XE:  a  U	R                  S
U
 S35        U	R                  UR                  UR                  5       UR                  5        5        XE:  a  U	R                  SU
 S35        OU	R                  S
U
 S35        U	R                  UR                  UR                  5       UR                  5        5        XE:  a  U	R                  SU
 S35        O:U	R                  UR                  UR                  5       UR                  5        5        U	R                  SUS-  -  SUS-  -  -   5        UnU(       a	  XE:  a  X-  nX4$ )a  
Args:
    open: the match against the opening delimiter run
    close: the match against the closing delimiter run
    middle: an optional delimiter run in the middle of the span
    open_syntax: the string of the opening delimiter run. If omitted `open.group(1)` will be used.
        Useful if there are characters in the delimiter run that need to be skipped
    close_syntax: the string of the opening delimiter run. If omitted `close.group(1)` will be used.
        Useful if there are characters in the delimiter run that need to be skipped

Returns:
    A list of processed tokens, and then the number of chars from the closing syntax that were
    consumed. If the latter item is None, then assume all chars were consumed
rf   r   r   N<em>r   z<strong>strongemrc  r   r  z	</strong></em>)
r   r   r   r   r'  maxr   r#  r&  r   )r   rE   rG   r\  rg  rh  middle_syntaxouter_syntax_lengthinner_syntax_lengthr  	inner_tagclose_delim_chars_useds               r+   rn  &GFMItalicAndBoldProcessor.process_span
  s   ( "=T#tzz!}%=+1Qr#@tCQ'@ "#k"@AY_c#c+&Dm"TUef
 E.DEF)A-.-23
  %($6!$;I))A./MM%,,txxz6<<>BC)9+Q/0)A./MM%,,vzz|U[[]CD)9+Q/0 MM%,,txxz5;;=AB 	/145-124	
 "5k0"9"--r-   rp  rq  rr  Fc                   ^^ UR                  TS5      nTR                  S5      US nTR                  S5      nXx:  af  U(       a_  U R                  US   T5      (       a  gTn	UR                  S5      mUR                  TS5      nTR                  S5      US nXx:X  a  Sn	TU	4$ Xx:  a"  U(       a  [	        UU4S jU 5       S5      n	TU	4$ g)a!  
Check if an emphasis span has a middle delimiter run, which may change the outer tags

Args:
    open: the current opening delimiter run
    close: the closing delimiter run
    opens: a list of all opening delimiter runs in the text
    unused_opens: a mapping of unused opens within the text to their offset values
    unused_closes: a list of unused closes within the text

Returns:
    False if there is no middle run. Otherwise, a tuple of the new opening run and the optional
    middle span. The middle span may be None if it is invalid
r   rf   Nr.  Fc              3      >#    U  HD  nTR                  5       UR                  5       s=:  a  TR                  5       :  d  M<  O  M@  Uv   MF     g 7fre  )r&  r   )r  r@  rG   rE   s     r+   r  7GFMItalicAndBoldProcessor.has_middle.<locals>.<genexpr>  s8     ^mtxxzAGGI7]PUP[P[P]7]17]1ms   ;AA	A)r   r   rj  rk  next)
r   rE   rG   rp  rq  rr  rz  rg  rx  r\  s
    ``       r+   rl  $GFMItalicAndBoldProcessor.has_middle
  s    $ #&&tQ/jjmKL1QE --eBi>>F99R=D&**43K**Q-5K$  V| !m ^m^`deF V| r-   rt  c                    Uc  gUR                  US5      nUR                  S5      US nUR                  S5      nXg:  a  [        U5      S:  a  gUS   nUS   R                  S5      n	U	S   U:w  a  gU R                  U5      u  pXg:  a$  U
(       a  US   (       a  XU-   :  a  US   (       d  gXg:  a  U(       a  US   (       d  US   (       d  gg)a;  
Check if an imbalanced delimiter run should be consumed now, or left for a later pass

Args:
    open: the opening delimiter run
    close: the closing delimiter run
    unused_opens: a mapping of unused opens within the text to their offset values
    next_delim_run: the next delimiter run after the closing run
NTr   rf   r  r   F)r   r   r   delimiter_left_or_right)r   rE   rG   rq  rt  rz  rg  rx  ry  next_delim_run_syntaxrv  rw  s               r+   rm  BGFMItalicAndBoldProcessor.should_process_imbalanced_delimiter_runs  s     !"&&tQ/jjmKL1QCK1$4 ) .q 1 7 7 : #w.2259"1%(+?? #1%>!,"1% r-   ru  c                     UR                   [        SUR                  5       S-
  5      UR                  5       S-    nU R	                  X!R                  S5      5      $ )z
Determine if a delimiter run is left or right flanking

Returns:
    Tuple of bools that mean left and right flanking respectively
r   rf   )r#  r  r   r&  _delimiter_left_or_rightr   )r   ru  rm   s      r+   r  1GFMItalicAndBoldProcessor.delimiter_left_or_rightO  sO     s1ioo&7!&;<immoPQ>QR,,S//!2DEEr-   i   )maxsizerm   rx  c                    UR                  SS5      n[        R                  " SU-  U[        R                  5      =(       aj    [        R                  " SU-  U[        R                  5      =(       d:    [        R                  " SU-  U[        R                  [        R                  -  5      n[        R                  " SU-  U[        R                  5      =(       aj    [        R                  " SU-  U[        R                  5      =(       d:    [        R                  " SU-  U[        R                  [        R                  -  5      nXE4$ )	z
Cached version of `delimiter_left_or_right` that massively speeds things up when dealing
with many repetetive delimiter runs - eg: in a ReDoS scenario
r  z\*z.*%s\Sz
.*%s[\s\w]z(^|[\s\W])%s([^\s\w]|$)z\S%s.*z
[\s\w]%s.*z[^\s\w]%s(\s|[^\s\w]|$))r   r   r   rE  r   )r   rm   rx  	syntax_rerv  rw  s         r+   r  2GFMItalicAndBoldProcessor._delimiter_left_or_rightZ  s     NN3.	 HHY*C6  2C> V886BCPRPTPTU 	 HHY*C6  2C> V886BCPRPTPTU 	 {r-   c                     UR                   UR                  5       UR                  5        n[        U5      S:  a  gU R	                  U5      $ )z
Checks if the body of an emphasis crosses a span border

Args:
    open: the opening delimiter run
    close: the closing delimiter run

Returns:
    True if the emphasis crosses a span border (invalid). False if not
r  F)r#  r&  r   r   _body_crosses_span_borders)r   rE   rG   rK   s       r+   rj  3GFMItalicAndBoldProcessor.body_crosses_span_bordersz  s?     {{488:u{{}5t9q=..t44r-   @   c                     [        [        R                  " SU R                  R                   S3U5      5       H%  nU R                  R                  X!5      (       a  M%    g   g)z-Cached version of `body_crosses_span_borders`z</?()TF)setr   r	  rn   rs  r  )r   rK   rY  s      r+   r  4GFMItalicAndBoldProcessor._body_crosses_span_borders  sP     rzzT$''*<*<)=Q"?FGC77))#44 H r-   rs  c                       [        U5      nU R                  U5      u  p4U(       d  U(       a  X#U4$ M2  ! [         a     gf = f)z
Gets the next delimiter run from an iterator of delimiter runs

Returns:
    A tuple containing the run, and matches dictating whether it is left or right flanking
    respectively. Returns nothing if no valid runs left
N)r  r  StopIteration)r   rs  ru  rv  rw  s        r+   ri  #GFMItalicAndBoldProcessor._next_run  sO    	 1	"::9E5%U33	 
  		s   05 5 
AAc                 `    UR                  S5      S:  =(       d    UR                  S5      S:  $ )Nr  rf   r  )r  r   s     r+   rl   GFMItalicAndBoldProcessor.test  s'    zz#"9djjo&99r-   r1   NNNre  )"r2   r3   r4   r5   r2  rj   rP   r_   r  rg   r   rm   r   r!  r   r   r   r   rn  r   r   r   rl  rm  r  rv   	lru_cacher  rj  r  r   ri  rl   r6   r1   r-   r+   r  r  
  s    +D""$eg-E@ @H /3)-*.	H.H..0hhsmH.RXXc]+H. "#H. #3-	H.
 49hsm+,H.T/HHSM/*,((3-/@DRXXc]@S/288C=#-./?CBHHSM?R/ 
uRXXc]HRXXc]$;;<genL	M/h lp8HHSM8*,((3-8288C=#-.8 !rxx}hrxx}6MxXZX`X`adXeOf'f!gh8t	F# 	F %C   &>5bhhsm 5BHHSM 5" $s  %"((3-)@ ": :r-   r  c                   B    \ rS rSr% Sr\\   \S'    \\S'    \\S'   Sr	g)_LinkProcessorExtraOptsi  z%Options for the `LinkProcessor` extratagsinlinerefr1   N)
r2   r3   r4   r5   r2  r   r   r  r  r6   r1   r-   r+   r  r    s!    /
s)ONL8	I;r-   r  )totalc                     ^  \ rS rSr% Sr\R                  4\R                  44r\	\
S'   S\S\\   4U 4S jjrS\S\S\S	\\\\\\   \4      4S
 jrS\S\S\S	\\\R(                  \      \4   4S jrS\S\S\S	\\\\\   \\   \4      4S jrS\S\S\S	\\\4   4S jrS\S\S\S	\\\4   4S jrS\4S jrS\4S jrSrU =r$ )r  i  zlink-processorr4  rn   c                 :   > U=(       d    0 n[         TU ]  X5        g re  rQ  r   rR  s      r+   r   LinkProcessor.__init__  s    -R%r-   rK   
_link_textry  r$   c                    U R                   R                  XS-   5      nU[        U5      :X  a  gUnX   S:H  nU(       a   U R                   R                  XS-   SS5      nU R                   R                  XSS5      nU R                   R                  R                  XU5      nU(       d  gXUR                  5        UR                  S5      pU(       a&  U R                   R                  R                  SU5      nXX4$ )	a  
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
rf   Nrc  r   (r  r  z\1)
rn   r  r   r  r%  r   r   r   r'  r   )
r   rK   r  ry  idxrz  has_anglebracketsr   r  r  s
             r+   parse_inline_anchor_or_image*LinkProcessor.parse_inline_anchor_or_image  s    $ gg**4Q?#d) I,gg,,T19c3GG''((SA**11$WEekkm,ekk'.BU''..225#>C%((r-   	link_textc                    SnU(       a  [         R                  " SXS 5      (       a  U R                  R                  R                  USU  SXS  3U5      nU(       a_  UR	                  S5      R                  5       =(       d    UR                  5       U R                  R                  ;   a  USU  SXS  3nXA4$ SnXA4$ )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[]r  )r   r   rn   r&  r   r3  r|   )r   rK   r  ry  r   s        r+   process_link_shortrefs$LinkProcessor.process_link_shortrefs  s     ":D<LMMGG66<<Zi@P?QQSTXYcTdSe=fhqrE
 KK%++-B1Btww||S":I./r$z2B1CDD { !E{r-   c                    SnSU R                   R                  ;   a  U R                  XU5      u  pAU=(       d%    U R                   R                  R	                  X5      nU(       d  gUR                  S5      R                  5       =(       d    UR                  5       nU R                   R                  R                  U5      nU R                   R                  R                  U5      nUR                  5       nXXx4$ )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-shortrefsr  )rn   r<   r  r&  r   r   r3  r|   r   r}   r&  )	r   rK   r  ry  r   link_idr  r  url_end_idxs	            r+   parse_ref_anchor_or_ref_image+LinkProcessor.parse_ref_anchor_or_ref_image  s    $ tww~~-55dyQKER;;AA$R++d#))+@y/@ggllw'""7+iik%,,r-   r  
title_attrc                    U R                   R                  S5      nSU R                   R                  U5       SU R                   R                  [	        U5      5       SU U U R                   R
                   3nU[        U5      4$ )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   )rn   r:  r  r  _xml_escape_attrr   r   )r   r  r  r  img_class_strr  s         r+   process_imageLinkProcessor.process_image!  s      88?--c23 4WW''(8(CDEQl=/$''*F*F)GI 	
 s6{""r-   c                    U R                   R                  (       a1  U R                   R                  R                  U5      (       d  SU S3nO"SU R                   R	                  U5       SU S3nU U S3[        U5      4$ )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   r  )rn   r;   r  r   r  r   )r   r  r  r  result_heads        r+   process_anchorLinkProcessor.process_anchor9  sx      77TWW%7%7%=%=c%B%B'
|15K%dgg&:&:3&?%@*QOKyk.K0@@@r-   c           	      :   SnSnSn  UR                  SU5      nSn[        US-   [        XR-   [	        U5      5      5       H)  nX   nUS:X  a  US-  nUS:  a    OM  US:X  d  M$  US-  nM+     US-   nMn  XS-   U n	U R
                  R                  (       a6  U R
                  R                  U	5      n	U R
                  R                  U	5      n	SU R
                  R                  ;   a  U	R                  S5      (       ap  [        R                  " S	S
U	SS  5      n
XR
                  R                  ;   a4  SU
 SU
 SU R
                  R                   S
U
 S3	nUS U U-   XS-   S  -   nOUS-   nGMf  US-  nXUS-    S:X  aj  U R                  R!                  SS5      (       d  US-   nGM  U R#                  XU5      nU(       d  US-   nGM  Uu  ppU R
                  R                  USS9nOWU R                  R!                  SS5      (       d  US-   nGM	  U R%                  XU5      nU(       d  US-   nGM*  Uu  ppUc  UnGM7  UR'                  SU R
                  R(                  S   5      R'                  SU R
                  R(                  S   5      nU(       a`  [+        U5      R'                  SU R
                  R(                  S   5      R'                  SU R
                  R(                  S   5      nSU S3nOSnUS:  =(       a
    XS-
     S:H  nU(       aE  SU R                  R!                  SS/5      ;  a  US-   nGM6  US-  nU R-                  UUU	5      u  nnOMXS:  a@  SU R                  R!                  SS/5      ;  a  US-   nGM  U R/                  UUU	5      u  nnOUS-   nGM  SU R
                  R                  ;   a)  UR'                  SU R
                  R(                  S   5      nUU-   nU[	        U5      -   nUS U U-   XS  -   nGM  ! [         a     U$ f = f)Ni  r   T[rf   ]r   rB  r  r  z$<sup class="footnote-ref" id="fnref-z"><a href="#fn-r  z
</a></sup>r  r  )r  r  r  r  z title="r   r   !r  r  r  r   )ru  r   rv  r'  r   rn   r;   r   r   r<   r  r   r   r   r   r4  r   r  r  r   r   r  r  r  )r   rK   MAX_LINK_TEXT_SENTINELanchor_allowed_poscurr_posry  bracket_depthr  r  r  r   r  parsedr  r  r  	title_stris_imgskips                      r+   rm   LinkProcessor.runP  s[   !%
   JJsH5	 MAI6D	B W9!Q&M$q( )3Y!Q&M %q=]A.I ww   GG44Y?	 GG66yA	 dggnn,1E1Ec1J1JFF5#y}=	 1 11>yk J((1{"TWW5M5M4NaPY{Zdf 
  
+f4taCDzAD  !1uH FA
 a!e}#||''$77(1}H::4AN(1}H06-5gg0040@ ||''t44(1}H;;DQO(1}H06-5;  !H
 dgg33C89dgg33C89 
 $U+WS$''"7"7"<=WS$''"7"7"<= 
 'ugQ/		 ]?taK'8C'?F 0 0% AA(1}HQ	#11#y)L0dll..vu==(1}H#223	9M %q=/TWW-B-B3-GH
 !4'H!*S[!8
#f,tL/AADk $  H Ks   P 
PPc                 $    SU;   =(       d    SU;   $ )Nr  r  r1   r   s     r+   rl   LinkProcessor.test  s    d{)cTk)r-   r1   )r2   r3   r4   r5   rj   rP   r_   r]   rg   r  r  rH   r   r   r   r   r   r   r  r   r!  r  r  r  r  rm   rl   r6   rc  rd  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 SXYabdbjbjknboYpruYuSv @!-# !-# !-RU !-Zbchilnvwzn{  ~F  GJ  ~K  MP  jP  dQ  [R !-F# ## ## #%PSUXPX/ #0A# A3 A3 A5QTVYQY? A.a aF* * *r-   r  c                      \ rS rSrSrSr\R                  \R                  4S4r	Sr
\R                  " S\
-  \R                  \R                  -  \R                  -  5      rS\4S jrS	\R&                  \   S
\4S jrS\4S jrSrg)Admonitionsi  z#
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
        rK   c                 <    U R                   R                  U5      S L$ re  )admonitions_rer   r   s     r+   rl   Admonitions.test  s    ""))$/t;;r-   r   r$   c                    UR                  5       u  p#pESU-  nUR                  5       S:X  a  SnOSUR                  5       -  nU(       a  SU-  nU R                  R                  SU R                  R	                  U5      S   -  5      nU R                  R                  SR                  XdU5      U R                  R                  S5      nS	R                  Xx5      nU R                  R                  XS5      $ )
Nz<strong>%s</strong>
admonitionzadmonition %sz<em>%s</em>z
%s
rf   z
{}
{}

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


 6<<=MZ
ww&&zFFr-   c                 N    U R                   R                  U R                  U5      $ re  )r  r   r   s     r+   rm   Admonitions.run-  s    ""&&txx66r-   N)r2   r3   r4   r5   r2  rj   rP   rU   rT   rg   r  r   r   r  r  r  r  r   rl   r!  r   rm   r6   r1   r-   r+   r  r    s     D0"4E^KZZ !
 ! 	$rzz1N< <G# G3 G87 7r-   r  c                       \ rS rSrSrSrS\R                  44r\	R                  " S\	R                  5      rS\4S jrS\	R                  \   S	\4S
 jrS\4S jrSrg)Alertsi1  z
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>
    rK   c                     SU;   $ )Nz<blockquote>r1   r   s     r+   rl   Alerts.testD  s    %%r-   r   r$   c                     US   R                  5       nSUS   R                  5        S3nUS   R                  5       nUS   (       a  SU SU SU S	3$ SU SU S
U S	3$ )NrK  r  r  contentsclosing_tagz<div class="alert z">
r   
</div>z
<p>)r3  r  r  )r   r   typheadingr  s        r+   r   
Alerts.subG  s    Fm!!#v,,./u5$**,'uD	H:XNN'uD	xjQQr-   c                 N    U R                   R                  U R                  U5      $ re  )alert_rer   r   s     r+   rm   
Alerts.runP  s    }}  400r-   N)r2   r3   r4   r5   r2  rj   rP   rY   rg   r   r   r  r  r   rl   r!  r   rm   r6   r1   r-   r+   r  r  1  ss    
 D##&&Ezz  
H& &R# R3 R1 1r-   r  c                   0    \ rS rSr% Sr\\S'    \\S'   Srg)_BreaksExtraOptsiT  zOptions for the `Breaks` extraon_backslashr   r1   Nr2   r3   r4   r5   r2  r  r  r6   r1   r-   r+   r  r  T  s    (<@r-   r  c                   P    \ rS rSr% SrS\R                  44r\\	S'   S\
4S jrSrg)Breaksi\  r   r1   r4  rK   c                 *   U R                   R                  SS5      nU R                   R                  SS5      nU(       a
  U(       a  SnOU(       a  SnOU(       a  SnOSnSU R                  R                  -  n[        R
                  " US	-   XQ5      nU$ )
Nr  Fr   z *\\?z(?: *\\| {2,})z *z {2,}r  z\n(?!\<(?:\/?(ul|ol|li))\>))r4  r   rn   r   r   r   )r   rK   r  r   pattern	break_tags         r+   rm   
Breaks.runa  s|    ||''>\\%%lE:
JG'GGG < <<	vvg >>	Pr-   N)r2   r3   r4   r5   rj   rP   r_   rg   r  r  r   rm   r6   r1   r-   r+   r  r  \  s,    D&&((E r-   r  c                   &  ^  \ rS rSrSrSr\R                  4\R                  44rU 4S jr	S\
4U 4S jjr  SS\R                  \
   S\R                  \
   S	\\R                  \
      S
\\
   S\\
   4
U 4S jjjrS\
4S jrS\
4U 4S jjrSrU =r$ )CodeFriendlyit  z%
Disable _ and __ for em and strong.
zcode-friendlyc                 2   > [         TU ]  X5        0 U l        g re  rP  rR  s      r+   r   CodeFriendly.__init__{  rU  r-   rK   c                   > U R                   R                  [        R                  :  a  [        TU ]  U5      nU$ SnX!:w  a=  UnU R                  R                  5        H  u  p4UR                  X45      nM     X!:w  a  M=  U$ r  )	rn   rg   rP   r_   rQ  rm   r  r   r   )r   rK   r  r   r  rS  s        r+   rm   CodeFriendly.run  sv    77==50007;t$D  I# 	#'??#8#8#:KC<<4D $; # r-   rE   rG   r\  rg  rh  c                 0  >^  UR                   UR                  5       UR                  5        nU=(       d    [        [        UR                  S5      5      nU=(       d    [        [        UR                  S5      5      nSU;   a!  [        R                  " SU 4S jU5      nU/S 4$ SU;   a\  U[        U5      [        U5      *  R                  ST R                  S5      5      R                  ST R                  S5      5      nXFU/S 4$ [        TT ]1  XX4U5      $ )Nrf   r  z_+c                 D   > TR                  U R                  S5      5      $ r   )r,   r   )rZ  r   s    r+   ri  +CodeFriendly.process_span.<locals>.<lambda>  s    4??1771:+Fr-   __)r#  r   r&  r   r   r   r   r   r   r   r,   rQ  rn  )r   rE   rG   r\  rg  rh  rK   rS  s   `      r+   rn  CodeFriendly.process_span  s     {{4::<5!=T#tzz!}%=#@tCQ'@+66%!FMD64<D[ S%L(9'9:tt45dooc23 
  |4d::w#DlSSr-   c                 8   XR                   R                  5       ;   aV  [        U R                   R                  5       5      [        U R                   R                  5       5      R	                  U5         $ [        U R                  U-   5      nXR                   U'   U$ )zK
Wrapper around `_hash_text` that updates the entries in `self.hash_table`
)r  r9  r  r  ru  r,   rj   )r   rK   r  s      r+   r,   CodeFriendly._hash_text  sx    
 ??))++--/0t7M7M7O1P1V1VW[1\]] DII,-"&r-   c                    > [         TU ]  U5      =(       d*    U R                  =(       a    [        R                  " SU5      $ Nr`  rQ  rl   r  r   r   r   rK   rS  s     r+   rl   CodeFriendly.test  1    w|D! 
OOD		*=t D	
r-   rb  r  )r2   r3   r4   r5   r2  rj   rP   r_   rg   r   r   rm   r   r!  r   rn  r,   rl   r6   rc  rd  s   @r+   r  r  t  s     D""$u'<'<&>>E	 	 \`IMTHHSMT*,((3-TAI"((SV-AXTc]T9A#T T.s 
 
 
r-   r  c                   N   \ rS rSrSrSr\R                  \R                  4\R                  44r
\R                  " S\R                  \R                  -  \R                  -  5      rS\4S jrS\S\S	\4S
 jrS\S	\\\4   4S jrS\R,                  \   S	\4S jrS\4S jrSrg)FencedCodeBlocksi  z
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.
r1  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
        rK   c                 n   SU;  a  gU R                   R                  [        R                  :X  a  U R                   R                  (       d  gU R                   R                  [        R
                  :X  a  U R                   R                  (       a  gU R                   R                  [        R                  :H  $ )Nz```FT)rn   rb   rP   rR   r;   rT   rU   r   s     r+   rl   FencedCodeBlocks.test  sn    77==E,,,TWW5F5F77==EOO+0A0Aww}} 1 111r-   rk  leading_indentr$   c                   ^  T R                   R                  S   =(       d    0 nU 4S jnT R                   R                  XS9u  paU" U5      nT R                   R                  " X40 UD6nT R                   R	                  XrS5      $ )z
Args:
    codeblock: the codeblock to format
    leading_indent: the indentation to prefix the block with
    lexer (pygments.Lexer): the lexer to use
r1  c                    > [        TR                  R                  R                  5       5       H  u  pU R	                  X5      n M     / SQnU H  u  pEU R	                  XE5      n M     U $ )N))r  r  )r  rc  )r  r   )r  rn   r   r   r   )rk  r   r  r  oldnewr   s         r+   unhash_code@FencedCodeBlocks._code_block_with_lexer_sub.<locals>.unhash_code  sc    "&tww'9'9'?'?'A"B%--c=	 #CL
 )%--c7	 )r-   rU  T)rn   r<   rX  r  r  )r   rk  r  r  r  r#  r  coloreds   `       r+   _code_block_with_lexer_sub+FencedCodeBlocks._code_block_with_lexer_sub  s     (<=C
	 ww//	/V	*	''..y A1?A ww&&wEEr-   ra  c                     U R                   R                  S5      nSU R                   R                  ;   a  U(       a  SR                  X5      nOU R                   R                  S5      nSR                  X#5      S4$ )a  
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>)rn   r:  r<   r!  )r   ra  	pre_class
code_classs       r+   r  FencedCodeBlocks.tags  sd     GG44U;	/J299*QJ99&AJ!((?QQr-   r   c                    UR                  S5      nUR                  S5      nUS S nUR                  UR                  5       UR                  S   S    n[        R
                  " SUR                  5       5      R                  5       nU(       a  SU R                  R                  ;  a  U R                  R                  U5      nU(       a^  S[        UR                  S5      5      [        UR                  S5      R                  5       5      -
  -  nUU R                  X7U5      -   U-   $ S[        UR                  S5      5      [        UR                  S5      R                  5       5      -
  -  nU(       a  U R                  R                  X7S	9u  psU R                  R                  U5      nU R                  U5      nU U US    U S
U US    U 3$ )Nr   r  r.  rf   r   z\n*$r*  r   r%  r   )r   r#  r   regsr   r   rn   r<   ri  r   r  r'  rX  r  r  )	r   r   ra  rk  leading_newlinestrailing_newlinesr  r  r  s	            r+   r   FencedCodeBlocks.sub  s   [[^
KKN	crN	 !<<uzz!}Q7GHIIgu{{}=CCE ,DGGNNBGG//
;E!$EKKN(;c%++a.BWBWBY>Z(Z![$55iQVWX'( EKKN 3c%++a.:O:O:Q6R RS(,(@(@(@(g%NGG((3	yy$   tAwik a	 !	#	
r-   c                 N    U R                   R                  U R                  U5      $ re  )fenced_code_block_rer   r   s     r+   rm   FencedCodeBlocks.run,  s    ((,,TXXt<<r-   r1   N)r2   r3   r4   r5   r2  rj   rP   rT   rU   rR   rg   r   r   r   r  rE  r4  r   rl   r'  r  r  r!  r   rm   r6   r1   r-   r+   r  r    s      D__e//053C3C2EEE:: '
 TTBDD[244!	2 	2!F!F !F
 
!FFRs RuS#X R$$
# $
3 $
L= =r-   r  c                   Z   \ rS rSrSrSr\R                  \4S4r	\
R                  " S5      r\
R                  " S\
R                  5      r\
R                  " S\
R                  5      r\
R                  " S\
R                  5      r\
R                  " S	5      rS
r0 rS rS rS rS\4S jrSrg
)Latexi0  zH
Convert $ and $$ to <math> and </math> tags for inline and block math.
latexr1   z(?<!\$)\$(?!\$)(.*?)\$z\$\$(.*?)\$\$z<pre>(.*?)</pre>z```(.*?)```z(?<!`)(`)(.*?)(?<!`)\1(?!`)Nc                 V    U R                   R                  UR                  S5      5      $ r   )	converterrI   r   r  s     r+   _convert_single_matchLatex._convert_single_matchB  s    ~~%%ekk!n55r-   c                 t    U R                   R                  UR                  S5      R                  SS5      SS9$ )Nrf   z\nr   r  )display)r:  rI   r   r   r  s     r+   _convert_double_matchLatex._convert_double_matchE  s2    ~~%%ekk!n&<&<UB&GQX%YYr-   c                 t    S[        U R                  5       S3nUR                  S5      U R                  U'   U$ )Nz<!--CODE_BLOCK_rl  r   )r   code_blocksr   )r   r   placeholders      r+   code_placeholderLatex.code_placeholderH  s:    'D,<,<(='>cB(-A%r-   rK   c                 H    SS K nUR                  U l        U R                  R	                  U R
                  U5      nU R                  R	                  U R
                  U5      nU R                  R	                  U R
                  U5      nU R                  R	                  U R                  U5      nU R                  R	                  U R                  U5      nU R                  R                  5        H  u  p4UR                  X45      nM     U$ ! [         a    [        S5      ef = f)Nr   zFThe "latex" extra requires the "latex2mathml" package to be installed.)latex2mathml.converterr:  rf  _pre_code_block_rer   rD  
_single_re
_triple_re_single_dollar_rer;  _double_dollar_rer?  rB  r   r   )r   rK   latex2mathmlrC  
code_blocks        r+   rm   	Latex.runM  s    	h))33DN
 &&**4+@+@$G""4#8#8$?""4#8#8$?%%))$*D*DdK%%))$*D*DdK (,'7'7'='='?#K<<8D (@   	hfgg	hs   D D!)r:  )r2   r3   r4   r5   r2  rj   rP   rX   r  rg   r   r   rK  r   rL  rH  rJ  rI  r:  rB  r;  r?  rD  r   rm   r6   r1   r-   r+   r7  r7  0  s     D 0125E

#<=

#3RYY? $7CNBII6J:;JIK6Z
 r-   r7  c                       \ rS rSr% SrSr\R                  4S4r\	\
S'   \R                  " S5      rS\4S jrS\4S	 jrSrg
)LinkPatternsic  zb
Auto-link given regex patterns in text (e.g. bug number
references, revision number references).
r   r1   r4  z!?\[.*?\]\(.*?\)rK   c                   ^ ^^^^ 0 nT R                    GH  u  p4/ nUR                  T5       Hl  m[        UU U4S jU 5       5      (       a  M!  [        U5      (       a	  U" T5      nOTR	                  U5      nUR                  TR                  5       U45        Mn     [        U5       GH  u  u  mmnTTS-
  T S:X  a  TTTS-    S:X  a  M$  TTS-
  T S:X  d  TTTS-    S:X  a  M>  TTS-
  T S	:X  a%  TTTS-    S	:X  a  TS TS-
   TTT -   TTS-   S  -   mMo  S
nT R                  R                  T R                  4 HF  nUR                  T5       H,  m[        UU4S jTR                   5       5      (       d  M*  Sn  O   MF    O   U(       a  M  UR                  SS5      R                  ST R                  R                  S   5      R                  ST R                  R                  S   5      n	SR                  U	TTT 5      n
T R                  R                  X5      nTS T U-   TTS  -   mGM     GM      [!        UR#                  5       5       H  u  pTR                  X5      mM     T$ )Nc              3   ^   >#    U  H"  nTR                   R                  TTU5      v   M$     g 7fre  )rn   r  )r  hr   r   rK   s     r+   r  #LinkPatterns.run.<locals>.<genexpr>s  s'     ^~!tww55dE1EE~s   *-rf   r  r  r   z](z")r  z"""Fc              3   P   >#    U  H  oS    T:*  =(       a    TUS   :*  v   M     g7f)r   rf   Nr1   )r  rC   r&  r   s     r+   r  rU    s'     S
1! =#1+ =
s   #&Tr   &quot;r  r  r  )r4  r  anycallableexpandr   r"  r  rn   r  _basic_link_rer/  r   r   r!  r  r  r   )r   rK   link_from_hashregexreplr  hrefis_inside_linklink_reescaped_hreflinkr  r&  r   r   s   ``          @@@r+   rm   LinkPatterns.runn  so   <<KEL-^~^^^D>>;D <<-D##UZZ\4$89 . '/|&<"d 	%(C/DS1W4E4L 	%(D0DS1W4E4M 	%(E1d3sQw6G56P
+d5o=S1WXND "' $ 5 5t7J7JKG!(!1!1$!7S

SSS .2N! "8 !  L " LLh/ dgg&;&;C&@A dgg&;&;C&@A	 
 -33L$uS/Rww))$?FU|d*T#$Z7M '= (d ~3356JD<<+D 7r-   c                     gNTr1   r   s     r+   rl   LinkPatterns.test      r-   N)r2   r3   r4   r5   r2  rj   rP   r^   rg   r  r  r   r   r[  r   rm   rl   r6   r1   r-   r+   rQ  rQ  c  sL     D[[NBEZZ 34N6 6p r-   rQ  c                   V    \ rS rSrSrSrS\R                  44rS\	4S jr
S\	4S jrSrg)	MarkdownInHTMLi  z
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.
rQ  r1   rK   c                    ^  S[         4U 4S jjnT R                  R                  UT R                  R                  US5      $ )Nr  c                    > TR                   R                  U 5      u  pTR                   R                  U 5      n TR                   R                  XSSS9n U $ )NTF)r  r  )rn   rX  r`  r  )r  r  r   s     r+   r~  $MarkdownInHTML.run.<locals>.callback  sN     GG44U;MFGG007EGG++Ethm+nELr-   T)r   rn   rp  rq  )r   rK   r~  s   `  r+   rm   MarkdownInHTML.run  s7    	C 	 ww,,T4773H3H(TXYYr-   c                     grf  r1   r   s     r+   rl   MarkdownInHTML.test  rh  r-   N)r2   r3   r4   r5   r2  rj   rP   rS   rg   r   rm   rl   r6   r1   r-   r+   rj  rj    s9     D""EZ Z r-   rj  c                   $    \ rS rSr% Sr\\S'   Srg)_MarkdownFileLinksExtraOptsi  z)Options for the `MarkdownFileLinks` extra	link_defsr1   Nr   r1   r-   r+   rr  rr    s    3ODr-   rr  c                      ^  \ rS rSr% SrSr\R                  4\R                  44r	\
\S'   S\S\\   4U 4S jjrS\S\S	\4U 4S
 jjrS\4U 4S jjrS\4U 4S jjrSrU =r$ )MarkdownFileLinksi  z1
Replace links to `.md` files with `.html` links
zmarkdown-file-linksr4  rn   c                 F   > S/SS.U=(       d    0 En[         TU ]  X5        g )Nr  F)r  r  r  rR  s      r+   r   MarkdownFileLinks.__init__  s%    5B7=bB%r-   rK   r  ry  c                    > [         TU ]  XU5      nU(       a#  US   (       a  US   R                  S5      (       d  g US   R                  S5      S-   nUS   U/USS  Q7$ )Nrf   .md.htmlr   r   )rQ  r  r7  removesuffix)r   rK   r  ry  r  r  rS  s         r+   r  .MarkdownFileLinks.parse_inline_anchor_or_image  si    5d	RVAYfQi.@.@.G.G Qi$$U+g5ay#*qr
**r-   c                   > [         R                  U R                  R                  s=:  a  [         R                  :  a  O  OU R
                  R                  SS5      (       ap  U R                  R                  R                  5        HH  u  p#UR                  S5      (       d  M  UR                  S5      S-   U R                  R                  U'   MJ     [        TU ]1  U5      $ )Nrs  Try  rz  )rP   r^   rn   rg   rT   r4  r   r|   r   r7  r{  rQ  rm   )r   rK   r   r  rS  s       r+   rm   MarkdownFileLinks.run  s    ;;88T\\=M=Mk[_=`=` GGLL..0<<&&(+(8(8(?'(IDGGLL% 1 w{4  r-   c                 :   > [         TU ]  U5      =(       a    SU;   $ )Nry  )rQ  rl   r  s     r+   rl   MarkdownFileLinks.test  s    w|D!3etm3r-   r1   )r2   r3   r4   r5   r2  rj   rP   r^   rT   rg   rr  r  rH   r   r   r   r   r   r  rm   rl   r6   rc  rd  s   @r+   ru  ru    s{     !D[[NU__..E((&8 &htn &
+ +# +RU +! !4 4 4r-   ru  c                   >   ^  \ rS rSrSr\4S4rS\4U 4S jjrSr	U =r
$ )Mermaidi  mermaidr1   ra  c                 0   > US:X  a  g[         TU ]  U5      $ )Nr  )z.<pre class="mermaid-pre"><div class="mermaid">z</div></pre>)rQ  r  )r   ra  rS  s     r+   r  Mermaid.tags  s    "Uw|J''r-   )r2   r3   r4   r5   rj   r  rg   r   r  r6   rc  rd  s   @r+   r  r    s&    D#E(s ( (r-   r  c                      ^  \ rS rSrSrSr\4\R                  44r	S\
S\\\S4   4U 4S jjrS\4S	 jrS
\R$                  \   4U 4S jjrS\4U 4S jjrSrU =r$ )MiddleWordEmi  z
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-emrn   r4  Nc                   > [        U[        5      (       a  SU0nOU=(       d    0 nUR                  SS5        [        TU ]  X5        SR                  UR                  R                  5       5      n[        R                  " SU< SU< S3[        R                  [        R                  -  5      U l        [        U R                  S-   5      [        U R                  S-   5      S	.U l        g
)a9  
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.
allowedT|z
            (?<!^)         # To be middle of a word, it cannot be at the start of the input
            (?<![*_\W])    # cannot be preceeded by em char or non word char (must be in middle of word)
            (?<!a$  )        # cannot be preceeded by a hashed escape char either
            ([*_])         # em char
            (?=\S)         # must be followed by non-whitespace char
            (?!
                [*_]|$|\W  # cannot be followed by another em char, EOF or a non-word char
                |za        # Also cannot be followed by any of the escaped non-word chars
            )
            r  r  )r  r  N)r   r  r   rQ  r   rN  r   r9  r   r   r  r   middle_word_em_rer,   rj   r  )r   rn   r4  escaped_hashesrS  s       r+   r   MiddleWordEm.__init__  s     gt$$ '*GmG9d+%""2"2"9"9";<!# ">
3 DD244K"
" DIIO,DIIO,
r-   rK   c                    U R                   S   (       a  U$ U R                  R                  U R                  R                  :  a&  U R                  R                  U R
                  U5      nU R                  R                  U R                  R                  :  a>  UR                  U R                  S   S5      nUR                  U R                  S   S5      nU$ )Nr  r  r  )r4  rn   rg   rb   r  r   r   r  r   s     r+   rm   MiddleWordEm.run%  s    <<	"K 77==477==())--dhh=D 77==477==(<< 4c:D<< 4c:Dr-   r   c                    > UR                   U R                  :w  a  [        TU ]  U5      $ UR	                  S5      nU R
                  U   $ r   )r   r  rQ  r   r   r  )r   r   rx  rS  s      r+   r   MiddleWordEm.sub5  s@    88t---7;u%%Qv&&r-   c                    > [         TU ]  U5      =(       d*    U R                  =(       a    [        R                  " SU5      $ r  r  r  s     r+   rl   MiddleWordEm.test<  r  r-   )r  r  )r2   r3   r4   r5   r2  rj   r  rP   r_   rg   rH   r   r   r  r   r   rm   r   r!  r   rl   r6   rc  rd  s   @r+   r  r    su    
 DOe3355E%
8 %
eD$4D.E %
N  '# '
 
 
r-   r  c                   H    \ rS rSrSrSr\R                  4S4rS\	4S jr
Srg)	NumberingiB  z
Support of generic counters.  Non standard extension to
allow sequential numbering of figures, tables, equations, exhibits etc.
	numberingr1   rK   c                    [         R                  " S[         R                  5      n[         R                  " S5      n0 n0 n/ nSnSnUR                  U5       H  n	[	        U	R                  5       5      S:w  a  M"  U	R                  S5      n
U	R                  S5      R                  5       nU	R                  S5      nU	R                  S5      nUR                  U
S5      nX4X\'   UR                  U	R                  S	5      UR                  U
UUUU5      U	R                  S	5      45        US-   XJ'   M     [        U5       H  nUS US	    US   -   XS   S  -   nM     [        [        UR                  U5      5      5       H  n	UR                  U	R                  S5      S
5      u  pUb#  UR                  U
U	R                  S5      U5      nO7UR                  U	R                  S5      SSU	R                  S5      -   S-   5      nSU R                  R                   ;   a)  UR#                  SU R                  R$                  S   5      nUS U	R                  5        U-   XR                  5       S  -   nM     U$ )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!   rf   r   r  r   r  countererror?r   r   )r   r   r  r  r   r  r   r  r   r   r   r!  r&  r  r  rn   r<   r   r   )r   rK   regex_defns
regex_subscounters
referencesr  definition_htmlreference_htmlr   countertext_beforeref_id
text_afternumberr^  s                   r+   rm   Numbering.runK  sK   jj "
  ZZ 01

ZF ))$/E5<<>"a'kk!nG++a...0K[[^FQJ\\'1-F"(!2JQ!0!7!78>8C8>8B	"D
 "'1!/ 0 !'
H# 0$ \*Da>DG+d78n<D + d:#6#6t#<=>E(nnU[[^\JOF!%,,W-2[[^-35 &,,U[[^-;-05;;q>-AC-GI /||C)>)>s)CD'$.iikl1CCD ? r-   N)r2   r3   r4   r5   r2  rj   rP   rT   rg   r   rm   r6   r1   r-   r+   r  r  B  s+    
 D__"E5 5r-   r  c                       \ rS rSrSrSrS\R                  44rS\	4S jr
S\R                  \	   S\	4S	 jrS\	4S
 jrSrg)PyShelli  zG
Treats unindented Python interactive shell sessions as <code>
blocks.
pyshellr1   rK   c                     SU;   $ )Nz>>>r1   r   s     r+   rl   PyShell.test  s    }r-   r   r$   c                    SU R                   R                  ;   aH  [        UR                  S5      5      nU R                   R                  S   R                  SU-   S-   5      $ UR                  S5      R                  S5      n[        U5        SU R                   R                  -  nSU-   SU-   R                  U5      -   S-   nU$ )Nr1  r   z	```pycon
z```
r   r   )
rn   r<   r  r   rk   rm   r5  _dedentlinesr:   rN  )r   r   dedentedr?  r  r#   s         r+   r   PyShell.sub  s    477>>1u{{1~.H77(()=>BB<RZCZ]dCdeeA))!,Utww(((f**512 r-   c                     U R                   R                  S-
  n[        R                  " SU-  [        R                  [        R
                  -  5      nUR                  U R                  U5      $ )Nrf   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
            rn   r:   r   r   r   r  r   )r   rK   r  _pyshell_block_res       r+   rm   PyShell.run  s^    ))A-JJ (  	(  "$	. !$$TXXt44r-   N)r2   r3   r4   r5   r2  rj   rP   rW   rg   r   rl   r   r!  r   rm   r6   r1   r-   r+   r  r    sQ    
 DE # 3 5 5r-   r  c                   $   \ rS rSrSrSrS\R                  44r\	R                  " S5      r\	R                  " S5      r\	R                  " S5      r\	R                  " S5      r\	R                  " S	5      r/ S
QrS\S\4S jrS\4S jrS\4S jrSrg)SmartyPantsi  z
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suprK   r$   c                     U R                   R                  SU5      nU R                   HO  nUR                  SU-  SU-  5      nUR                  SUR	                  5       -  SUR	                  5       -  5      nMQ     U$ )Nz	&#8217;\1z'%sz	&#8217;%s)_apostrophe_year_rer   _contractionsr   
capitalize)r   rK   r  s      r+   contractionsSmartyPants.contractions  sr    ''++L$?##A<<	;?;D<< 6alln,.D $ r-   c                 8   SU;   aI  U R                  U5      nU R                  R                  SU5      nU R                  R                  SU5      nSU;   a8  U R                  R                  SU5      nU R
                  R                  SU5      nUR                  SS5      nUR                  S	S
5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nSU R                  R                  ;   a  SU;   a  UR                  SS5      nU$ )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   rn   r<   r   s     r+   rm   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                 .   ^ [        U4S jS 5       5      $ )Nc              3   ,   >#    U  H	  oT;   v   M     g 7fre  r1   )r  r@  rK   s     r+   r  #SmartyPants.test.<locals>.<genexpr>  s       '
9 '
s   )r   r   r  r  r  )rX  r   s    `r+   rl   SmartyPants.test  s      '
   	r-   N)r2   r3   r4   r5   r2  rj   rP   r[   rg   r   r   r  r  r  r  r  r  r   r  rm   rl   r6   r1   r-   r+   r  r    s    
 D!!##E!zz*;<!zz*;<!zz+6!zz*KL
 **%EF:M   B r-   r  c                       \ rS rSrSrSr\R                  4S4r\	R                  " S\	R                  5      rS\4S jrS\4S jrSrg	)
Strikei  z2
Text inside of double tilde is ~~strikethrough~~
striker1   z~~(?=\S)(.+?)(?<=\S)~~rK   c                 :    U R                   R                  SU5      $ )Nz	<s>\1</s>)
_strike_rer   r   s     r+   rm   
Strike.run  s    ""<66r-   c                     SU;   $ )Nz~~r1   r   s     r+   rl   Strike.test      t|r-   N)r2   r3   r4   r5   r2  rj   rP   r_   rg   r   r   rE  r  r   rm   rl   r6   r1   r-   r+   r  r    sN     D""$b(E5rtt<J7 7 r-   r  c                   t    \ rS rSrSrSrS\R                  44rS\	4S jr
S\R                  \	   S\	4S	 jrSrg
)Tablesi   z
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   rK   c                     U R                   R                  S-
  n[        R                  " SX"U4-  [        R                  [        R
                  -  5      nUR                  U R                  U5      $ )zCopying PHP-Markdown and GFM table syntax. Some regex borrowed from
https://github.com/michelf/php-markdown/blob/lib/Michelf/Markdown.php#L2538
rf   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   rK   r  table_res       r+   rm   
Tables.run	  sf     ))A-:: * !?+@* BD+N, ||DHHd++r-   r   r$   c                 "   SnSnSnSnUR                  5       u  pgn[        R                  " U[        R                  " US[        R                  " USU5      5      5       V	s/ s H)  n	[        R                  " USU	R	                  5       5      PM+     n
n	0 n[        U
5       H;  u  pUS   S:X  a  US	   S:X  a  S
X'   M  US   S:X  a  SX'   M,  US	   S:X  d  M7  SX'   M=     SU R                  R                  S5      -  SU R                  R                  S5      -  S/n[        R                  " U[        R                  " US[        R                  " USU5      5      5       V	s/ s H)  n	[        R                  " USU	R	                  5       5      PM+     n
n	[        U
5       HO  u  pUR                  SR                  UR                  US5      U R                  R                  U5      5      5        MQ     UR                  S5        UR                  S5        UR	                  S5      nU(       Ga1  UR                  S5        UR                  S5       H  nUR                  S5        [        R                  " U[        R                  " US[        R                  " USU5      5      5       V	s/ s H)  n	[        R                  " USU	R	                  5       5      PM+     n
n	[        U
5       HO  u  pUR                  SR                  UR                  US5      U R                  R                  U5      5      5        MQ     UR                  S5        M     UR                  S5        UR                  S5        SR                  U5      S-   $ s  sn	f s  sn	f s  sn	f )Nz	^\s+|\s+$z^\||\|$z^\||(?<![\`\\])\|z\\\|r   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>)r  r   r   r   r  r6  rn   r:  r   r!  r   rf  rN  )r   r   trim_space_retrim_bar_resplit_bar_reescape_bar_rer:  	underliner  cellcolsalign_from_col_idxcol_idxcolhlinesrA  s                   r+   r   
Tables.sub&  s   $ + % FHXXl\^\b\bcnprtvtztz  |I  KM  OX  uY  ]Z  F[  \  F[T}c4::<8  F[  \%dOLG1v}RC.K"+Q3.I"+RC.J"+ ,  @ @ 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  FVT}c4::<8  FV  W%dOLGMM+22"&&w3'',  ,
 	gj! zz$MM)$

4(f%MOXXVbdfdjdjkvxz|~  }C  }C  DQ  SU  W[  }\  e]  N^  _  N^T}c4::<@  N^  _$-dOLGMM"3":":*..w;//4#  %4
 g& ) MM*%j!yy 4''K \ W _s   !0N!0N'0NN)r2   r3   r4   r5   r2  rj   rP   rW   rg   r   rm   r   r!  r   r6   r1   r-   r+   r  r     sE    
 DE, ,:.(# .(3 .(r-   r  c                       \ rS rSrSrS\R                  44r\R                  " S\R                  5      rS\4S jrS\4S jrSrg)	TelegramSpoileriW  z
tg-spoilerr1   z\|\|\s?(.+?)\s?\|\|rK   c                 :    U R                   R                  SU5      $ )Nz<tg-spoiler>\1</tg-spoiler>)_tg_spoiler_rer   r   s     r+   rm   TelegramSpoiler.run]  s    ""&&'EtLLr-   c                     SU;   $ Nz||r1   r   s     r+   rl   TelegramSpoiler.test`  r  r-   N)r2   r3   r4   r5   rj   rP   r_   rg   r   r   rE  r  r   rm   rl   r6   r1   r-   r+   r  r  W  sI    D&&((EZZ 6=NM M r-   r  c                       \ rS rSrSrSr\R                  4S4r\	R                  " S\	R                  5      rS\4S jrS\4S jrSrg	)
	Underlineid  z/
Text inside of double dash is --underlined--.
r  r1   z.(?<!<!)--(?!>)(?=\S)(.+?)(?<=\S)(?<!<!)--(?!>)rK   c                 :    U R                   R                  SU5      $ )Nz	<u>\1</u>)_underline_rer   r   s     r+   rm   Underline.runm  s    !!%%lD99r-   c                     SU;   $ )Nr  r1   r   s     r+   rl   Underline.testp  r  r-   N)r2   r3   r4   r5   r2  rj   rP   r_   rg   r   r   rE  r  r   rm   rl   r6   r1   r-   r+   r  r  d  sQ     D""$b(EJJPRTRVRVWM: : r-   r  c                   $    \ rS rSr% Sr\\S'   Srg)_WavedromExtraOptsit  z Options for the `Wavedrom` extraprefer_embed_svgr1   Nr   r1   r-   r+   r	  r	  t  s    *r-   r	  c                       \ rS rSr% SrSr\R                  \4S4r	\
\S'   S\4S jrS\R                  \   S	\4S
 jrS\4S jrSrg)Wavedromi  z9
Support for generating Wavedrom digital timing diagrams
wavedromr1   r4  rK   c                 ~    [         R                  R                  U5      nUS L =(       d    UR                  S5      S:H  $ )Nr   r  )r  r4  r   r   )r   rK   r   s      r+   rl   Wavedrom.test  s4     55<<TB}<A* <<r-   r   r$   c                    U R                   R                  UR                  S5      5      u  p#Su  pEU R                  R	                  SS5      nU(       a(   SS KnUR                  U5      R                  5       nSu  pE[        U5      U R                   R                  U'   U R                   R                  SR                  X@R                   R                  U   U5      USS9$ ! [         a     Npf = f)	Nr  )z<script type="WaveDrom">
z	</script>r
  Tr   )z<div>r  z
{}{}{}
)r  )rn   rX  r   r4  r   r  rendertostringrf  r,   r   r  r!  )r   r   r  wavesopen_tag	close_tag	embed_svgr  s           r+   r   Wavedrom.sub  s    !WW55ekk!nEG LL$$%7>	 .779&9#
 (2%'8e$ww&&''*?*?*F	RT ' 
 	
  s   'C   
C-,C-c                 V    [         R                  R                  U R                  U5      $ re  )r  r4  r   r   s     r+   rm   Wavedrom.run  s    44884HHr-   N)r2   r3   r4   r5   r2  rj   rP   rX   r  rg   r	  r  r   rl   r   r!  r   rm   r6   r1   r-   r+   r  r    s_     D 0125E= =
# 
3 
2I Ir-   r  c                   f    \ rS rSrSrSr\4S4rS\4S jr	S\
R                  \   S\4S	 jrS
 rSrg)
WikiTablesi  z_
Google Code Wiki-style tables. See
<http://code.google.com/p/support/wiki/WikiSyntax#Tables>.
zwiki-tablesr1   rK   c                     U R                   R                  S-
  n[        R                  " SU-  [        R                  [        R
                  -  5      nUR                  U R                  U5      $ )Nrf   z
            (?:(?<=\n\n)|\A\n?)            # leading blank line
            ^([ ]{0,%d})\|\|.+?\|\|[ ]*\n  # first line
            (^\1\|\|.+?\|\|\n)*        # any number of subsequent lines
            r  )r   rK   r  wiki_table_res       r+   rm   WikiTables.run  s]    ))A-

 $  	$  "$	.
   400r-   r   r$   c                   ^ ^	^
 UR                  S5      R                  5       n/ nUR                  S5       Hi  nUR                  5       SS R                  5       n[        R                  " SU5       Vs/ s H  oUR                  5       PM     nnUR                  U5        Mk     / m
SU
U 4S jjnU	U 4S jnU" ST R                  R                  S5      -  5        U(       a  US   (       a  [        R                  " S	US   S   5      (       ad  U" S
T R                  R                  S5      -  S5        U" SS5        US    H  m	U" SU" T	5       S3S5        M     U" SS5        U" SS5        USS  nU(       aI  U" SS5        U H1  nU" SS5        U H  m	U" SU" T	5       S3S5        M     U" SS5        M3     U" SS5        U" S5        SR                  T
5      S-   $ s  snf )Nr   r   z(?<!\\)\|\|c                 \   > TR                  TR                  R                  U-  U -   5        g re  )r   rn   r   )rA  indentsr  r   s     r+   	add_hline!WikiTables.sub.<locals>.add_hline  s!    MM477;;0D89r-   c                    > TR                   R                  [        R                  " SST5      R	                  S5      5      $ )N^\s*~r   r   )rn   rf  r   r   r  )rK   r  r   s    r+   format_cell#WikiTables.sub.<locals>.format_cell  s0    77**266(B+E+K+KC+PQQr-   r  r  r&  r  r  rf   r  z<th>z</th>r  r  r  r  z<td>z</td>r  r  r   )r   )
r   r  r5  r   r   r   rn   r:  r   rN  )r   r   ttextrowsrA  r  rowr#  r'  r  r  s   `        @@r+   r   WikiTables.sub  s   A$$&$$Q'D::<"%++-D&(hh~t&DE&D779&DC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#&!$D[%6$7u=qA  '1%	 
 j!$*yy 4''A Fs   3Gc                     SU;   $ r  r1   r   s     r+   rl   WikiTables.test  r  r-   N)r2   r3   r4   r5   r2  rj   r  rg   r   rm   r   r!  r   rl   r6   r1   r-   r+   r  r    sF     DIrME1 1%(# %(3 %(Nr-   r  r   c                   ^ U c  gU4S jn/ nS/mU  H  u  p4nUTS   :  a+  UR                  SU" 5       -  5        TR                  U5        OzUTS   :X  a  US==   S-  ss'   OcUTS   :  aZ  TR                  5         US   R                  S5      (       d  US==   S-  ss'   UR                  SU" 5       -  5        UTS   :  a  MZ  UR                  SR                  U" 5       XE5      5        M     [	        T5      S	:  a`  TR                  5         US   R                  S5      (       d  US==   S-  ss'   UR                  S
U" 5       -  5        [	        T5      S	:  a  M`  SR                  U5      S-   $ )zkReturn the HTML for the current TOC.

This expects the `_toc` attribute to have been set on this instance.
Nc                  &   > S[        T 5      S-
  -  $ )Nr  rf   r  )h_stacks   r+   r  "calculate_toc_html.<locals>.indent	  s    s7|a'((r-   r   r.  z%s<ul>r  z%s</ul></li>z{}<li><a href="#{}">{}</a>rf   z%s</ul>r   )r   rk  r7  r!  r   rN  )r   r  r?  r   r  rj   r1  s         @r+   r   r     s^   
 {)EcG472;LLFH,-NN5!gbk!"I I'"+%Ry))'22"I(I^fh67	 '"+%
 	188Hb  	!  g,
Ry!!'**"I IY)*	 g,

 99Ud""r-   c                   L    \ rS rSr% SrSr\\\\4      \	S'   Sr
\\   \	S'   Srg)rA   i#  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   r1   )r2   r3   r4   r5   r2  r   r   r   r   r  r   r6   r1   r-   r+   rA   rA   #  s.     *.HhtCH~&-"Hhsm"r-   z[^\w\s-]z[-\s]+r  c                     SSK nUR                  SU 5      R                  SS5      R                  5       n [        R                  SU 5      R                  5       R                  5       n [        R                  SU 5      $ )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  r3  _slugify_hyphenate_re)r  r7  s     r+   r  r  .  sf     !!&%077JQQSE!!"e,224::<E $$S%00r-   functionc                    ^ ^^ UU U4S jnU$ )Nc                  \   > TR                  5       nUR                  U5        T" TU -   0 UD6$ re  )r   r   )restkwrestcombinedro   r<  rp   s      r+   r  _curry.<locals>.result>  s.    ;;=111r-   r1   )r<  ro   rp   r  s   ``` r+   ro  ro  =  s    2 Mr-   c                 r   U R                  S5      (       a  U R                  S5      S:w  a  U R                  S5      nU SU XS-   S p2[        R                  [        R                  [        R
                  [        R                  [        R                  S.nSnU H  n XTU   -  nM     [        R                  " U SU U5      $ [        R                  " [        R                  " U 5      5      $ ! [         a?    [        SU< SU < SS	R                  [        UR                  5       5      5      < S
35      ef = f)zk'foo'    -> re.compile(re.escape('foo'))
'/foo/'  -> re.compile('foo')
'/foo/i' -> re.compile('foo', re.I)
/r   rf   N)r@  r  r#   rZ  uzunsupported regex flag: 'z' in 'z' (must be one of 'r   z'))r  rfindr   r  LOCALEr   r  r  KeyErrorr   rN  r  r  r   r   )r#   r  r  	flags_strflag_from_charflagschars          r+   _regex_from_encoded_patternrM  F  s   
 	||CQWWS\Q.ggcl3xq569
 DT--  zz!Ac(E**zz"))A,''  T $(!RWWT.:M:M:O5P-Q"S T TTs   C--A	D6r?  tabsizer  c           	      <   SnU(       a  [        SX4-  5        Sn[        U 5       Ho  u  pVUS:X  a	  U(       a  M  SnU H)  nUS:X  a  US-  nM  US:X  a  XqXq-  -
  -  nM!  US;   a  M)    O   MG  U(       a  [        S	Xv4-  5        Uc  UnMd  [        XG5      nMq     U(       a  [        S
U-  5        Ub  US:  a  [        U 5       H  u  pVUS:X  a	  U(       a  M  Sn	[        U5       H  u  pUS:X  a  U	S-  n	OGUS:X  a
  XX-  -
  -  n	O7US;   a!  U(       a  [        SU-  5        X   U
S X'     Mi  [        SXU4-  5      eU(       a  [        SXhX4-  5        X:X  a  X   U
S-   S X'     M  X:  d  M  SX-
  -  X   U
S-   S -   X'     M     U	(       d  M  X   U	S X'   M     U $ )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   rf   rG  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)printr6  r'  r   )r?  rN  r  DEBUGmarginr@  rA  r  r  removedjs              r+   r  r  d  s    EC*+ 	,FU#6oBSy!tV%566v  )VN:;>F(F) $* !F*+fqj 'GAAv/G"49qLG4Z'*;<<G6\BTIJ$x|EH$ &N(*&'9&: ; ; ;!w78 9$$x!~EH%"GN3ehqstnDEH- )0 7$x1EH; (< Lr-   c                 Z    U R                  S5      n[        X1US9  SR                  U5      $ )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)rN  r  r   )r5  r  rN  )rK   rN  r  r?  s       r+   r  r    s*     OOD!EI775>r-   c                   *    \ rS rSrSrS rS rS rSrg)	_memoizedi  zDecorator 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                     Xl         0 U l        g re  )rs   cache)r   rs   s     r+   r   _memoized.__init__  s    	
r-   c                      U R                   U   $ ! [         a#    U R                  " U6 =U R                   U'   nUs $ [         a    U R                  " U6 s $ f = fre  )rY  rH  rs   r  )r   ro   r  s      r+   __call___memoized.__call__  s_    	$::d## 	'+yy$'77DJJtuL 	$ 99d##	$s    *AAAc                 .    U R                   R                  $ )z Return the function's docstring.)rs   r2  r   s    r+   __repr___memoized.__repr__  s    yy   r-   )rY  rs   N)	r2   r3   r4   r5   r2  r   r\  r_  r6   r1   r-   r+   rW  rW    s    	$!r-   rW  c                 X    [         R                  " SU S-
  -  [         R                  5      $ )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
        )
        rf   r   r   r  r:   s    r+   rw  rw    s/    ::   1}!   "tt!% %r-   c                 X    [         R                  " SU S-
  -  [         R                  5      $ )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
        )
        rf   rb  rc  s    r+   rt  rt    s/    ::  1}  "tt% %r-   attrskip_single_quotec                     [         R                  SU 5      nU R                  SS5      R                  SS5      R                  SS5      nU(       d  UR                  SS	5      nU$ )
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   rW  rc  r  r   r  r   &#39;)r  r   r   )re  rf  r  s      r+   r  r    s\     .G	h		f		f	  //#w/Nr-   r  c                     [        5       nUS:  a  U S;  a  U $ US:  a  S[        [        U 5      5      SS  -  $ S[        U 5      -  $ )Ng?z@_g?z&#%s;rf   )r   hexord)r  rC   s     r+   r  r    sM    A 	3w2T>		
TSWab)))R  r-   r   c                     U R                  SS5      R                  SS5      R                  SS5      nU(       a  UR                  SS5      nU$ )	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   rW  rc  r  r   r  r   rh  )r   )re  r;   r   r  s       r+   r  r  #  sJ     	h		f		f	  //#w/Nr-   c                       \ rS rSrSrS rSrg)_NoReflowFormatteri:  z;An argparse formatter that does NOT reflow the description.c                     U=(       d    S$ r  r1   )r   descriptions     r+   format_description%_NoReflowFormatter.format_description<  s     b r-   r1   N)r2   r3   r4   r5   r2  rq  r6   r1   r-   r+   rn  rn  :  s
    E!r-   rn  c                  ,    SS K n U R                  5         g r   )doctesttestmod)rt  s    r+   _testrv  @  s    OOr-   c                    U c  [         R                  n [        R                  R                  (       d  [        R
                  " 5         [        R                  " S[        S[        S9nUR                  SSS[         3S9  UR                  SS	S
S9  UR                  SSSS[        R                  SS9  UR                  SSS9  UR                  SSSSS9  UR                  SSSSSS9  UR                  S S!S"S#S$9  UR                  S%S&S9  UR                  S'S(S9  UR                  S)SS*S$9  UR                  S+SS,S$9  UR                  S-[        S.S/9  UR                  [        R                  SS0S SS19  UR!                  5       nUR"                  n[$        R'                  UR(                  5        UR*                  (       a
  [-        5       $ UR.                  (       ar  0 nUR.                   H_  n[0        R2                  " S25      nUR5                  U5       H1  nS3U;   a!  UR5                  S3S45      u  p [7        U	5      n	OUS pXU'   M3     Ma     OS nUR:                  (       a  / n
[=        UR:                  5      n [?        URA                  5       5       H  u  pURC                  5       (       d  M  URE                  5       RG                  S55      (       a  MB   URI                  5       RK                  S S45      u  pU
RO                  [Q        U5      U45        M     URS                  5         OS n
S7S8K*J+nJ,nJ-nJ.n  U" U" U" U" [^        5      5      5      S9S:5      nU(       d  S;/nU GH  nUS;:X  a  [         R`                  Rc                  5       nOB[d        R<                  " US<URf                  5      nURc                  5       nURS                  5         URh                  (       a  S7S=K5J6nJ7n  [q        S>5        U" S?U-  S@UUS@SA9nUR`                  Rs                  URu                  S05      5        UR`                  RS                  5         URv                  Rc                  5       Ry                  S05      n[         Rv                  Rs                  U5        [q        SB5        [{        UUR|                  UR~                  XJUR                  S@SC9nUR                  (       a1  [=        UR                  SD5       nURs                  U5        S S S 5        O[         Rv                  Rs                  U5        U(       ab  SEU;   a\  [$        R                  SF[        UR                  Ru                  [         Rv                  Rf                  =(       d    S0SG5      5      -   5        URh                  (       d  GM=  U" U" U" U" [^        5      5      5      S95      nU" U" USH5      5      (       a7  [         R                  R                  S7U5        S7SIKFJGn  U" U5      nU" W5      n OUnWn [q        SJU U:H  -  5        GM     g ! [8         a     GNf = f! [8         a    [M        S6UR:                  US4-   U4-  5      ef = f! URS                  5         f = f! , (       d  f       GNc= f)KN	markdown2z%(prog)s [PATHS...])progrp  usageformatter_classz	--versionversionz	%(prog)s )actionr|  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)destr}  constr  z
--encodingz specify encoding of text content)r  z--html4tags
store_trueFz'use HTML 4 style for empty element tags)r}  defaultr  z-sz--safeMODEr;   zgsanitize literal HTML: 'escape' escapes HTML meta chars, 'replace' replaces with an [HTML_REMOVED] note)metavarr  r  z-xz--extrasr   zPTurn on specific extra features (not part of the core Markdown spec). See above.)r}  r  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)rK  r  r&   )r  comparer8   r;   r@   z[,;: ]+r   rf   #z$%s:%d: invalid link pattern line: %rr   )abspathdirnameexistsrN  rl   zMarkdown.plr  rC   )PIPEPopenz==== Markdown.pl ====zperl %sT)shellstdinstdout	close_fdsz==== markdown2.py ====)r9   r;   r<   r=   r@   rM   wr   z
toc_html: xmlcharrefreplaceztest_markdown2.py)norm_html_from_htmlz==== match? %r ====)HsysargvloggingroothandlersbasicConfigargparseArgumentParser
cmdln_descrn  add_argument__version__rQ  r   set_defaultsINFO
parse_argsr~  r1  setLevelr  	self_testrv  r<   r   r   r   r   r   link_patterns_filerE   r6  	readlinesr  r  r  r8  rsplitr/   r   rM  rG   os.pathr  r  r  rN  __file__r  rF   rD   r8   r  
subprocessr  r  rP  writer)   r  r9  r    r9   r;   r@   rK  r2  r   r7   rB  test_markdown2r  )!r  parseroptsr~  r<   r#   r   r   r   r   r=   fr@  rA  patr_  r  r  r  rN  markdown_plr7   rK   rJ   r  r  r  	perl_htmlrX  test_dirr  	norm_htmlnorm_perl_htmls!                                    r+   mainr  E  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/KE"4y #$T4 $u '  (()	$Q[[]3zz||;;=++C00P $ 4 4T1 =IC $$05t<> 4 GGI66wwwx'89:F$&K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 E & & " P'(N+/+B+BAaC*N)O P PP GGI@ ('sC   .X 5AY "X13 Y $Y2 
X.-X.1)YY Y/2
Z	__main__)   F)T)FNre  )}r2  r  __version_info__rN  r  r   r  
__author__r  rD   r  r   r  collectionsr   r   abcr   r	   rv   collections.abcr
   r   hashlibr   r   typingr   r   r   r   r   r   r   r   r   r   r   r   enumr   r   osr   r  r   r  r  r  r  Patternr!  r  rQ  	getLoggerr1  r  r(   r,   r   _AMPERSAND_BODY_REr   r  r  	Exceptionr/   r  r   rL   r    rP   rz   rH   r0  rh   rN  r  r  r  r  r  r  r  r  r  r7  rQ  rj  rr  ru  r  r  r  r  r  r  r  r  r  r	  r  r  rE  r   rA   r:  r;  r  ro  rM  r  r  rW  rw  rt  r  r  r  RawDescriptionHelpFormatterrn  rv  r  r2   exitr  )r  s   0r+   <module>r     sg  >D
V  hhs3 012
    	 
 0 #  .   d d d d &   ()
CH~d3i-.%

3sHbhhsm_VYEY<Z7Z1[ [\] 	
#  bkM# M# M
 "#! jn$!#
 5 

:(::;

#69K#KL 	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_! _!DC1 1,UC Up,HU ,H^V: V:r<iu <A*E A*P
37% 37l 1U  1FAy AU 0=
, =
@y=u y=x0E 0fD5 DNU .E"9 E!4 !4H( (J
, J
Z> >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 # JJ{+ 

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