� K�gp����dZddlmZddlmZddlmZmZmZm Z ddl Z ddl m cm Z ddlmZerddlmZdXd�ZdZ dZ dZ dZ dZ dZ dZ dZ dZ dZ dZ dZ dZ edzZ dZ! e Z" e!Z# dZ$ d Z% d!Z& d"Z' d#Z( d$Z) dYd'�Z*Gd(�d)e ��Z+Gd*�d+��Z,Gd,�d-e,��Z-Gd.�d/e,��Z.Gd0�d1e-��Z/Gd2�d3e-��Z0Gd4�d5e,��Z1Gd6�d7e-��Z2Gd8�d9e1��Z3Gd:�d;e2��Z4Gd<�d=e-��Z5Gd>�d?e1��Z6Gd@�dAe2��Z7GdB�dCe-��Z8GdD�dEe-��Z9GdF�dGe9��Z:GdH�dIe-��Z;GdJ�dKe;��Z<GdL�dMe;��Z=GdN�dOe=��Z>GdP�dQe=��Z?GdR�dSe?��Z@GdT�dUe-��ZAGdV�dWe-��ZBdS)ZaB In version 3.0, a new, more flexible inline processor was added, [`markdown.inlinepatterns.InlineProcessor`][]. The original inline patterns, which inherit from [`markdown.inlinepatterns.Pattern`][] or one of its children are still supported, though users are encouraged to migrate. The new `InlineProcessor` provides two major enhancements to `Patterns`: 1. Inline Processors no longer need to match the entire block, so regular expressions no longer need to start with `r'^(.*?)'` and end with `r'(.*?)%'`. This runs faster. The returned [`Match`][re.Match] object will only contain what is explicitly matched in the pattern, and extension pattern groups now start with `m.group(1)`. 2. The `handleMatch` method now takes an additional input called `data`, which is the entire block under analysis, not just what is matched with the specified pattern. The method now returns the element *and* the indexes relative to `data` that the return element is replacing (usually `m.start(0)` and `m.end(0)`). If the boundaries are returned as `None`, it is assumed that the match did not take place, and nothing will be altered in `data`. This allows handling of more complex constructs than regular expressions can handle, e.g., matching nested brackets, and explicit control of the span "consumed" by the processor. �)� annotations�)�util)� TYPE_CHECKING�Any� Collection� NamedTupleN)�entities)�Markdown�mdr �kwargsr�return�util.Registry[InlineProcessor]c �P�tj��}|�tt��dd��|�t t |��dd��|�tt|��dd��|�tt|��dd��|�tt|��d d ��|�tt|��d d ��|�tt|��d d��|�t!t|��dd��|�t#t$|��dd��|�t't(|��dd��|�t+t,d��dd��|�t/t0|��dd��|�t/t2|��dd��|�t5t6��dd��|�t9d��dd ��|�t;d!��d"d#��|S)$a Build the default set of inline patterns for Markdown. The order in which processors and/or patterns are applied is very important - e.g. if we first replace `http://.../` links with `<a>` tags and _then_ try to replace inline HTML, we would end up with a mess. So, we apply the expressions in the following order: * backticks and escaped characters have to be handled before everything else so that we can preempt any markdown patterns by escaping them; * then we handle the various types of links (auto-links must be handled before inline HTML); * then we handle inline HTML. At this point we will simply replace all inline HTML strings with a placeholder and add the actual HTML to a stash; * finally we apply strong, emphasis, etc. �backtick��escape�� reference��link�� image_link��image_reference��short_reference��short_image_ref�}�autolink�x�automail�n�br� linebreak�d�html�Z�entity�P� not_strong�Fz\*� em_strong�<�_� em_strong2�2)r�Registry�register�BacktickInlineProcessor� BACKTICK_RE�EscapeInlineProcessor� ESCAPE_RE�ReferenceInlineProcessor� REFERENCE_RE�LinkInlineProcessor�LINK_RE�ImageInlineProcessor� IMAGE_LINK_RE�ImageReferenceInlineProcessor�IMAGE_REFERENCE_RE�ShortReferenceInlineProcessor�"ShortImageReferenceInlineProcessor�AutolinkInlineProcessor� AUTOLINK_RE�AutomailInlineProcessor� AUTOMAIL_RE�SubstituteTagInlineProcessor� LINE_BREAK_RE�HtmlInlineProcessor�HTML_RE� ENTITY_RE�SimpleTextInlineProcessor� NOT_STRONG_RE�AsteriskProcessor�UnderscoreProcessor)r r �inlinePatternss �g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/markdown/inlinepatterns.py�build_inlinepatternsrR5sb��&�]�_�_�N����3�K�@�@�*�c�R�R�R����1�)�R�@�@�(�C�P�P�P����4�\�2�F�F� �UX�Y�Y�Y����/���<�<�f�c�J�J�J����0���C�C�\�SV�W�W�W����%�&8�"�=�=�?P�RU�������%�l�B�7�7�9J�C�������*�+=�r�B�B�DU�WZ�������3�K��D�D�j�RU�V�V�V����3�K��D�D�j�RU�V�V�V����8���M�M�{�\_�`�`�`����/���<�<�f�b�I�I�I����/� �2�>�>��"�M�M�M����5�m�D�D�l�TV�W�W�W����-�e�4�4�k�2�F�F�F����/��5�5�|�R�H�H�H� ��z(?<!\!)z;(?:(?<!\\)((?:\\{2})+)(?=`+)|(?<!\\)(`+)(.+?)(?<!`)\2(?!`))z\\(.)z(\*)([^\*]+)\1z(\*{2})(.+?)\1z%(?<!\w)(_{2})(?!_)(.+?)(?<!_)\1(?!\w)z"(?<!\w)(_)(?!_)(.+?)(?<!_)\1(?!\w)z7(?<!\w)(\_)\1(?!\1)(.+?)(?<!\w)\1(?!\1)(.+?)\1{3}(?!\w)z(\*)\1{2}(.+?)\1(.*?)\1{2}z(_)\1{2}(.+?)\1(.*?)\1{2}z(\*)\1{2}(.+?)\1{2}(.*?)\1z(_)\1{2}(.+?)\1{2}(.*?)\1z&(\*)\1(?!\1)([^*]+?)\1(?!\1)(.+?)\1{3}z\[z\!\[z%((^|(?<=\s))(\*{1,3}|_{1,3})(?=\s|$))z+<((?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^<>]*)>z<([^<> !]+@[^@<> ]+)>z;(<(\/?[a-zA-Z][^<>@ ]*( [^<>]*)?|!--(?:(?!<!--|-->).)*--)>)z-(&(?:\#[0-9]+|\#x[0-9a-fA-F]+|[a-zA-Z0-9]+);)z \n�string�strc���|�d��r|�d��s*|�d��r|�d��r |dd�S|S)z#Remove quotes from around a string.�"�'r�����)� startswith�endswith)rTs rQ�dequoter\�sh�� � � �3� � ��F�O�O�C�$8�$8�����#����#)�?�?�3�#7�#7���a��d�|��� rSc�2�eZdZUdZded<ded<ded<dS)� EmStrongItemzEmphasis/strong pattern item.�re.Pattern[str]�patternrU�builder�tagsN)�__name__� __module__� __qualname__�__doc__�__annotations__�rSrQr^r^�s4�������'�'������L�L�L� �I�I�I�I�IrSr^c�r�eZdZUdZe��Zded< ded<ded<ddd �Zdd�Zdd�Z dd�Z dd�Z dS)�Patterna� Base class that inline patterns subclass. Inline patterns are handled by means of `Pattern` subclasses, one per regular expression. Each pattern object uses a single regular expression and must support the following methods: [`getCompiledRegExp`][markdown.inlinepatterns.Pattern.getCompiledRegExp] and [`handleMatch`][markdown.inlinepatterns.Pattern.handleMatch]. All the regular expressions used by `Pattern` subclasses must capture the whole block. For this reason, they all start with `^(.*)` and end with `(.*)!`. When passing a regular expression on class initialization, the `^(.*)` and `(.*)!` are added automatically and the regular expression is pre-compiled. It is strongly suggested that the newer style [`markdown.inlinepatterns.InlineProcessor`][] that use a more efficient and flexible search approach be used instead. However, the older style `Pattern` remains for backward compatibility with many existing third-party extensions. zCollection[str]�ANCESTOR_EXCLUDESr_� compiled_re�Markdown | Noner Nr`rUc��||_tjd|ztjtjz��|_||_dS)a! Create an instant of an inline pattern. Arguments: pattern: A regular expression that matches a pattern. md: An optional pointer to the instance of `markdown.Markdown` and is available as `self.md` on the class instance. z ^(.*?)%s(.*)$N)r`�re�compile�DOTALL�UNICODErlr ��selfr`r s rQ�__init__zPattern.__init__�s@���� ��:�&6��&@�&(�i�"�*�&<�>�>�������rSr� re.Patternc��|jS)z' Return a compiled regular expression. )rl�rts rQ�getCompiledRegExpzPattern.getCompiledRegExp�s ����rS�m� re.Match[str]�etree.Element | strc��dS)z�Return a ElementTree element from the given match. Subclasses should override this method. Arguments: m: A match object containing a match of the pattern. Returns: An ElementTree Element object. Nrh�rtrzs rQ� handleMatchzPattern.handleMatch�s �� �rSc��|jjS)z+ Return class name, to define pattern type )� __class__rcrxs rQ�typez Pattern.type�s ���~�&�&rS�textc��� |jjdj�n#t$r|cYSwxYw�fd�}tj�||��S)�> Return unescaped text given text with an inline placeholder. �inlinec����|�d��}|�vrS��|��}t|t��r|Sd�|�����SdS)Nr�)�group�get� isinstancerU�join�itertext)rz�id�value�stashs �rQ� get_stashz#Pattern.unescape.<locals>.get_stash sf���������B��U�{�{�� � �"� � ���e�S�)�)�5� �L��7�7�5�>�>�#3�#3�4�4�4� �{rS�r �treeprocessors� stashed_nodes�KeyErrorr�INLINE_PLACEHOLDER_RE�sub�rtr�r�r�s @rQ�unescapezPattern.unescapest��� ��G�*�8�4�B�E�E��� � � ��K�K�K� ���� 5� 5� 5� 5� 5��)�-�-�i��>�>�>s �� *�*�N�r`rUr rm)rrv)rzr{rr|)rrU�r�rUrrU) rcrdrerf�tuplerkrgruryrr�r�rhrSrQrjrj�s����������&*/�����0�0�0�0�� !� � � ����������" � � � �  �  �  �  �'�'�'�'�?�?�?�?�?�?rSrjc�$�eZdZdZddd�Zdd �ZdS)�InlineProcessorz� Base class that inline processors subclass. This is the newer style inline processor that uses a more efficient and flexible search approach. Nr`rUr rmc��||_tj|tjtjz��|_d|_||_dS)a" Create an instant of an inline processor. Arguments: pattern: A regular expression that matches a pattern. md: An optional pointer to the instance of `markdown.Markdown` and is available as `self.md` on the class instance. FN)r`rorprqrrrl� safe_moder rss rQruzInlineProcessor.__init__s<���� ��:�g�r�y�2�:�/E�F�F����������rSrzr{�datar�9tuple[etree.Element | str | None, int | None, int | None]c��dS)a�Return a ElementTree element from the given match and the start and end index of the matched text. If `start` and/or `end` are returned as `None`, it will be assumed that the processor did not find a valid region of text. Subclasses should override this method. Arguments: m: A re match object containing a match of the pattern. data: The buffer currently under analysis. Returns: el: The ElementTree element, text or None. start: The start of the region that has been matched or None. end: The end of the region that has been matched or None. Nrh�rtrzr�s rQrzInlineProcessor.handleMatch/s ��& �rSr�r�)rzr{r�rUrr��rcrdrerfrurrhrSrQr�r�sK�������������" � � � � � rSr�c��eZdZdZdd�ZdS) �SimpleTextPatternz2 Return a simple text of `group(2)` of a Pattern. rzr{rrUc�,�|�d��S)z< Return string content of `group(2)` of a matching pattern. �)r�r~s rQrzSimpleTextPattern.handleMatchGs���w�w�q�z�z�rSN�rzr{rrU�rcrdrerfrrhrSrQr�r�Es.������<�<������rSr�c��eZdZdZd d�Zd S) rLz2 Return a simple text of `group(1)` of a Pattern. rzr{r�rUr�tuple[str, int, int]c�~�|�d��|�d��|�d��fS)z< Return string content of `group(1)` of a matching pattern. rr)r��start�endr�s rQrz%SimpleTextInlineProcessor.handleMatchNs-���w�w�q�z�z�1�7�7�1�:�:�q�u�u�Q�x�x�/�/rSN�rzr{r�rUrr�r�rhrSrQrLrLLs.������<�<�0�0�0�0�0�0rSrLc��eZdZdZd d�Zd S) r7z Return an escaped character. rzr{r�rUr�tuple[str | None, int, int]c�`�|�d��}||jjvrad�tjt |��tj��|�d��|� d��fSd|�d��|� d��fS)a� If the character matched by `group(1)` of a pattern is in [`ESCAPED_CHARS`][markdown.Markdown.ESCAPED_CHARS] then return the integer representing the character's Unicode code point (as returned by [`ord`][]) wrapped in [`util.STX`][markdown.util.STX] and [`util.ETX`][markdown.util.ETX]. If the matched character is not in [`ESCAPED_CHARS`][markdown.Markdown.ESCAPED_CHARS], then return `None`. r�{}{}{}rN) r�r � ESCAPED_CHARS�formatr�STX�ord�ETXr�r�)rtrzr��chars rQrz!EscapeInlineProcessor.handleMatchVs����w�w�q�z�z�� �4�7�(� (� (��?�?�4�8�S��Y�Y���A�A�1�7�7�1�:�:�q�u�u�UV�x�x�W� W��������Q�U�U�1�X�X�-� -rSN)rzr{r�rUrr�r�rhrSrQr7r7Ss.������(�(� .� .� .� .� .� .rSr7c�"�eZdZdZd d�Zd d �Zd S)�SimpleTagPatternz] Return element of type `tag` with a text attribute of `group(3)` of a Pattern. r`rU�tagc�J�t�||��||_dS)z� Create an instant of an simple tag pattern. Arguments: pattern: A regular expression that matches a pattern. tag: Tag of element. N)rjrur��rtr`r�s rQruzSimpleTagPattern.__init__ls'�� ����w�'�'�'����0�0rSrzr{r� etree.Elementc�l�tj|j��}|�d��|_|S)z� Return [`Element`][xml.etree.ElementTree.Element] of type `tag` with the string in `group(3)` of a matching pattern as the Element's text. �)�etree�Elementr�r�r�)rtrz�els rQrzSimpleTagPattern.handleMatchys+�� �]�4�8� $� $���'�'�!�*�*���� rSN�r`rUr�rU�rzr{rr�r�rhrSrQr�r�fsF�������� 1� 1� 1� 1������rSr�c�"�eZdZdZd d�Zdd �Zd S)�SimpleTagInlineProcessorz] Return element of type `tag` with a text attribute of `group(2)` of a Pattern. r`rUr�c�J�t�||��||_dS)z� Create an instant of an simple tag processor. Arguments: pattern: A regular expression that matches a pattern. tag: Tag of element. N)r�rur�r�s rQruz!SimpleTagInlineProcessor.__init__�s'�� � � ��w�/�/�/����0�0rSrzr{r�r�tuple[etree.Element, int, int]c��tj|j��}|�d��|_||�d��|�d��fS)z� Return [`Element`][xml.etree.ElementTree.Element] of type `tag` with the string in `group(2)` of a matching pattern as the Element's text. r�r)r�r�r�r�r�r�r��rtrzr�r�s rQrz$SimpleTagInlineProcessor.handleMatch�sG�� �]�4�8� $� $���'�'�!�*�*����1�7�7�1�:�:�q�u�u�Q�x�x�'�'rSNr��rzr{r�rUrr�r�rhrSrQr�r��sF�������� 1� 1� 1� 1�(�(�(�(�(�(rSr�c��eZdZdZdd�ZdS) �SubstituteTagPattern�3 Return an element of type `tag` with no children. rzr{rr�c�4�tj|j��S)�H Return empty [`Element`][xml.etree.ElementTree.Element] of type `tag`. )r�r�r�r~s rQrz SubstituteTagPattern.handleMatch�s���}�T�X�&�&�&rSNr�r�rhrSrQr�r��s.������=�=�'�'�'�'�'�'rSr�c��eZdZdZd d�Zd S) rGr�rzr{r�rUrr�c��tj|j��|�d��|�d��fS)r�r)r�r�r�r�r�r�s rQrz(SubstituteTagInlineProcessor.handleMatch�s/���}�T�X�&�&����� � �A�E�E�!�H�H�<�<rSNr�r�rhrSrQrGrG�s.������=�=�=�=�=�=�=�=rSrGc�"�eZdZdZd d�Zd d �Zd S)r5zA Return a `<code>` element containing the escaped matching text. r`rUc���t�||��d�tjt d��tj��|_d|_dS)Nr��\�code) r�rur�rr�r�r��ESCAPED_BSLASHr�)rtr`s rQruz BacktickInlineProcessor.__init__�sG��� � ��w�/�/�/�&�o�o�d�h��D� � �4�8�L�L������0�0rSrzr{r�r�$tuple[etree.Element | str, int, int]c��|�d��r�tj|j��}t jt j|�d���������|_||� d��|� d��fS|�d��� d|j ��|� d��|� d��fS)a� If the match contains `group(3)` of a pattern, then return a `code` [`Element`][xml.etree.ElementTree.Element] which contains HTML escaped text (with [`code_escape`][markdown.util.code_escape]) as an [`AtomicString`][markdown.util.AtomicString]. If the match does not contain `group(3)` then return the text of `group(1)` backslash escaped. r�rrz\\) r�r�r�r�r� AtomicString� code_escape�stripr�r�r��replacer�r�s rQrz#BacktickInlineProcessor.handleMatch�s��� �7�7�1�:�:� Y���t�x�(�(�B��'��(8�������9I�9I�9K�9K�(L�(L�M�M�B�G��q�w�w�q�z�z�1�5�5��8�8�+� +��7�7�1�:�:�%�%�f�d�.A�B�B�A�G�G�A�J�J�PQ�PU�PU�VW�PX�PX�X� XrSN)r`rU)rzr{r�rUrr�r�rhrSrQr5r5�sH������K�K�1�1�1�1� Y�Y�Y�Y�Y�YrSr5c��eZdZdZdd�ZdS) �DoubleTagPattern�fReturn a ElementTree element nested in tag2 nested in tag1. Useful for strong emphasis etc. rzr{rr�c�D�|j�d��\}}tj|��}tj||��}|�d��|_t|�����dkr|�d��|_ |S)z� Return [`Element`][xml.etree.ElementTree.Element] in following format: `<tag1><tag2>group(3)</tag2>group(4)</tag2>` where `group(4)` is optional. �,r���) r��splitr�r�� SubElementr�r��len�groups�tail)rtrz�tag1�tag2�el1�el2s rQrzDoubleTagPattern.handleMatch�s|�� �X�^�^�C�(�(� ��d��m�D�!�!����s�D�)�)���7�7�1�:�:��� �q�x�x�z�z�?�?�a� � ��w�w�q�z�z�C�H�� rSNr�r�rhrSrQr�r��s2�������� � � � � � rSr�c��eZdZdZd d�Zd S) �DoubleTagInlineProcessorr�rzr{r�rUrr�c��|j�d��\}}tj|��}tj||��}|�d��|_t|�����dkr|�d��|_ ||� d��|� d��fS)z� Return [`Element`][xml.etree.ElementTree.Element] in following format: `<tag1><tag2>group(2)</tag2>group(3)</tag2>` where `group(3)` is optional. r�r�r�r) r�r�r�r�r�r�r�r�r�r�r�r�)rtrzr�r�r�r�r�s rQrz$DoubleTagInlineProcessor.handleMatch�s��� �X�^�^�C�(�(� ��d��m�D�!�!����s�D�)�)���7�7�1�:�:��� �q�x�x�z�z�?�?�a� � ��w�w�q�z�z�C�H��A�G�G�A�J�J����a���(�(rSNr�r�rhrSrQr�r��s2�������� )� )� )� )� )� )rSr�c�*�eZdZdZd d�Zdd �Zdd �Zd S)rIz1 Store raw inline html and return a placeholder. rzr{r�rUrr�c� �|�|�|�d������}|jj�|��}||�d��|�d��fS)zL Store the text of `group(1)` of a pattern and return a placeholder string. rr)�backslash_unescaper�r�r � htmlStash�storer�r�)rtrzr��rawhtml� place_holders rQrzHtmlInlineProcessor.handleMatch�sd���)�)�$�-�-����� � �*C�*C�D�D���w�(�.�.�w�7�7� ��Q�W�W�Q�Z�Z����q���1�1rSr�c���� �jjdj�n#t$r|cYSwxYwd��fd� }tj�||��S)r�r�rzr{rrUc����|�d��}��|��}|�0 �j�|��S#t$rd|zcYSwxYwdS)Nrz\%s)r�r�r � serializer� Exception)rzr�r�rtr�s ��rQr�z/HtmlInlineProcessor.unescape.<locals>.get_stashsu���������B��I�I�b�M�M�E�� �*��7�-�-�e�4�4�4�� �*�*�*�!�E�>�)�)�)�*����!� s�A � A�Ar�r�r�s` @rQr�zHtmlInlineProcessor.unescape�s���� ��G�*�8�4�B�E�E��� � � ��K�K�K� ���� *� *� *� *� *� *� *��)�-�-�i��>�>�>s �� +�+c�� |jjdj}n#t$r|cYSwxYwdd�}|�||��S)zG Return text with backslash escapes undone (backslashes are restored). r�rzr{rrUc�`�tt|�d������S)Nr)�chr�intr�)rzs rQ� _unescapez9HtmlInlineProcessor.backslash_unescape.<locals>._unescapes ���s�1�7�7�1�:�:���'�'� 'rSr�)r r��REr�r�)rtr�rrs rQr�z&HtmlInlineProcessor.backslash_unescape si�� ���'� �3�6�B�B��� � � ��K�K�K� ���� (� (� (� (��v�v�i��&�&�&s �� )�)Nr�r�)rcrdrerfrr�r�rhrSrQrIrI�sV������;�;�2�2�2�2� ?�?�?�?�$ '� '� '� '� '� 'rSrIc ���eZdZdZeejeejej z��dd��eeje ejej z��dd��eeje ejej z��dd��eeje ejej z��dd��eeje ejej z��dd��gZ d!d�Zd"d�Zd"d�Zd#d�Zd$d�Zd%d�Zd S)&rNzGEmphasis processor for handling strong and em matches inside asterisks.�double� strong,em� em,strong�double2�single�strong�emrzr{r�rU�idxrrr�c��tj|��}|�d��}|�||d|��|S)zReturn single tag.r�N)r�r�r��parse_sub_patterns)rtrzr�rr�r�s rQ� build_singlezAsteriskProcessor.build_single$s?���m�C� � ���w�w�q�z�z�� ����c�4��5�5�5�� rSrbc��|�d��\}}tj|��}tj|��}|�d��}|�||d|��|�|��t |�����dkr-|�d��}|�||||��|S)zReturn double tag.r�r�Nr�)r�r�r�r�r�appendr�r�� rtrzrbrr�r�r�r�r�s rQ� build_doublezAsteriskProcessor.build_double+s����Z�Z��_�_� ��d��m�D�!�!���m�D�!�!���w�w�q�z�z�� ����c�4��5�5�5� � � �3���� �q�x�x�z�z�?�?�a� � ��7�7�1�:�:�D� � #� #�D�#�s�C� 8� 8� 8�� rSc�d�|�d��\}}tj|��}tj|��}|�d��}|�||d|��|�d��}|�|��|�||d|��|S)zFReturn double tags (variant 2): `<strong>text <em>text</em></strong>`.r�r�Nr�)r�r�r�r�rrrs rQ� build_double2zAsteriskProcessor.build_double29s����Z�Z��_�_� ��d��m�D�!�!���m�D�!�!���w�w�q�z�z�� ����c�4��5�5�5��w�w�q�z�z�� � � �3���� ����c�4��5�5�5�� rSr��parent�last�etree.Element | None�Nonec�X�d}d}t|��}||kr�|j�||��r�d}t|j��D]�\} } | |kr� | j�||��} | r�||| �d���} | r|�| |_n| |_|� | | j | j | ��} |� | ��| }| � d��x}}d}��|s|dz }n|dz }||k��||d�} | r|� | |_dS| |_dSdS)a/ Parses sub patterns. `data`: text to evaluate. `parent`: Parent to attach text and sub elements to. `last`: Last appended child to parent. Can also be None if parent has no children. `idx`: Current pattern index that was used to evaluate the parent. rFNTr)r�rl�match� enumerate�PATTERNSr`r�r�r�� build_elementrarbrr�)rtr�rrr�offset�pos�length�matched�index�itemrzr�r�s rQrz$AsteriskProcessor.parse_sub_patternsFsx�������T�����F�l�l���%�%�d�C�0�0� ���#,�T�]�#;�#;�'�'�K�E�4���|�|� �� �*�*�4��5�5�A��'� $�F�1�7�7�1�:�:�$5�6���3�#�/�,0�� � �.2�� �!�/�/��4�<���E�R�R��� � �b�)�)�)�!��'(�u�u�Q�x�x�/���"&������1�H�C���q���A�F�l�l�F�F�G�G�}�� � #��� �� � � �"�� � � �  #� #rSrar&c��|dkr|�|||��S|dkr|�|||��S|�|||��S)zElement builder.r r)rrr)rtrzrarbr&s rQr!zAsteriskProcessor.build_element�sb�� �i� � ��%�%�a��u�5�5� 5� �� � ��$�$�Q��e�4�4� 4��$�$�Q��e�4�4� 4rS�3tuple[etree.Element | None, int | None, int | None]c�H�d}d}d}t|j��D]�\}}|j�||�d����}|rN|�d��}|�d��}|�||j|j|��}n��|||fS)zParse patterns.Nr) rr r`rr�r�r!rarb) rtrzr�r�r�r�r&r'�m1s rQrzAsteriskProcessor.handleMatch�s���������$�T�]�3�3� � �K�E�4���#�#�D�!�'�'�!�*�*�5�5�B�� ����� � ���f�f�Q�i�i���'�'��D�L�$�)�U�K�K����  � �5�#�~�rSN)rzr{r�rUrrrr�)rzr{rbrUrrrr�) r�rUrr�rrrrrr) rzr{rarUrbrUr&rrr��rzr{r�rUrr))rcrdrerfr^rorp� EM_STRONG_RErqrr� STRONG_EM_RE� STRONG_EM3_RE� STRONG_RE� EMPHASIS_REr rrrrr!rrhrSrQrNrNsn������Q�Q� � �Z�R�Z� �b�i�"�*�.D�E�E�x�Q\�]�]�� �Z�R�Z� �b�i�"�*�.D�E�E�x�Q\�]�]�� �Z�R�Z� �r�y�2�:�/E�F�F� �S^�_�_�� �Z�R�Z� �2�9�r�z�+A�B�B�H�h�W�W�� �Z�R�Z� �R�Y���-C�D�D�h�PT�U�U� �H�P����� � � � � � � � �;#�;#�;#�;#�z5�5�5�5������rSrNc ��eZdZdZeejeejej z��dd��eeje ejej z��dd��eeje ejej z��dd��eeje ejej z��dd��eeje ejej z��dd��gZd S) rOzIEmphasis processor for handling strong and em matches inside underscores.rr r r r r rN)rcrdrerfr^rorp� EM_STRONG2_RErqrr� STRONG_EM2_RE�SMART_STRONG_EM_RE�SMART_STRONG_RE�SMART_EMPHASIS_REr rhrSrQrOrO�s�������S�S� � �Z�R�Z� �r�y�2�:�/E�F�F��R]�^�^�� �Z�R�Z� �r�y�2�:�/E�F�F��R]�^�^�� �Z�R�Z� 2�B�I�� �4J�K�K�Y�Xc�d�d�� �Z�R�Z����R�Z�1G�H�H�(�T\�]�]�� �Z�R�Z� 1�2�9�r�z�3I�J�J�H�VZ�[�[� �H�P�OrSrOc��eZdZdZejdejejz��Zejd��Z dd �Z dd�Z dd�Z dS)r;z- Return a link element from the given match. z2\(\s*(?:(<[^<>]*>)\s*(?:('[^']*'|"[^"]*")\s*)?\))?z\srzr{r�rUrr)c�d�|�||�d����\}}}|sdS|�||��\}}}}|sdStjd��}||_|�d|��|�|�d|��||�d��|fS)zS Return an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. r�NNN�a�hrefN�title)�getTextr��getLinkr�r�r��setr�) rtrzr�r�r&�handledr<r=r�s rQrzLinkInlineProcessor.handleMatch�s���#�|�|�D�!�%�%��(�(�;�;���e�W�� $�#�#�&*�l�l�4��&?�&?�#��e�U�G�� $�#�#� �]�3� � ����� ���v�t���� � � �F�F�7�E� "� "� "��1�7�7�1�:�:�u�$�$rSr&r�!tuple[str, str | None, int, bool]c ��d}d}d}|j�||���}|r�|�d��rz|�d��dd����}|�d��r|�d��dd�}|�d��}d }�n�|�r�d}d}|���} | }d} d} d} d} d}d}d}d}d}t |t |����D�]8}||}|d kr|s|dz }n�|dkr|dz}n}|d kr:| dkr| |ks |dkr ||krd}n\|s|dz}nT|dkr|dz}|dkr|dz} n=|d vr9| sd }|}d}|dz} |} n)|| kr |s|dz}|}n|| kr|dz} n |r ||kr|dz}|dz }|dkr�| dkr4| |kr.|| | dz �}d�|| | dz ���}nG|dkr4||kr.|| |dz �}d�|||dz ���}n || |dz �}n |d kr|}��:|dkr|dkr|| | dz �}| }d}|dk}|�M|j� d t|� |���������}|� |�����}||||fS)z?Parse data between `()` of `[Text]()` allowing recursive `()`. r�NF�r#rrYr�rT�(�))rXrW� ) �RE_LINKrr�r�r��ranger�r��RE_TITLE_CLEANr�r\r�)rtr�r&r<r=rArz� bracket_count�backtrack_count� start_index� last_bracket�quote� start_quote� exit_quote�ignore_matches� alt_quote�start_alt_quote�exit_alt_quoterr#�cs rQr?zLinkInlineProcessor.getLink�s����� ���� �L� � �t�� � /� /�� �c )�������c )��7�7�1�:�:�a��d�#�)�)�+�+�D��w�w�q�z�z� )����� � �1�R�4�(���E�E�!�H�H�E��G�G� �\ )��M��O��%�%�'�'�K��E��L�!%�E��K��J�"�N��I� �O��N��D��U�C��I�I�.�.�; �; ����I����8�8�*�-�%��*� � �(�1�,�,�'�1�,����#�X�X�$�r�)�)�e�t�m�m��SU�AU�AU�Zc�gk�Zk�Zk�()� � �+�5�%��*� � �(�1�,�,�'�1�,��*�a�/�/�+0�1�9�L���*�_�_� �3�*.��*7��()� �&+�a�i� � !����e���I��*/�!�)��$%� � ��e���%*�Q�Y� � �"�3�q�I�~�~�).������ ��!�A�%�%�!�Q���5�D�=�=�#�K� �a��$?�@�� "����[��a��-G�(H� I� I���'�1�,�,��d�1B�1B�#�K��!�0C�$C�D�� "����_�^�a�=O�-O�(P� Q� Q���#�K��� �$9�:���E���8�8��D�� ��!�!�o��&:�&:��K� �q�(8�8�9��$�� !� �#�q�(�G� � ��'�+�+�C�����u�{�{�}�}�9U�9U�1V�1V�W�W�E��}�}�T�"�"�(�(�*�*���U�E�7�*�*rS�tuple[str, int, bool]c��d}g}t|t|����D]C}||}|dkr|dz}n |dkr|dz }|dz }|dkrn|�|���Dd�|��||dkfS)zsParse the content between `[]` of the start of an image or link resolving nested square brackets. r�]�[rr�)rIr�rr�)rtr�r&rKr�r#rVs rQr>zLinkInlineProcessor.getText9s��� � ������D� � �*�*� � �C��S� �A��C�x�x���"� � ��c�����"� � �Q�J�E���!�!��� �K�K��N�N�N�N��w�w�t�}�}�e�]�a�%7�7�7rSNr,)r�rUr&rrrB)r�rUr&rrrW) rcrdrerfrorprqrrrHrJrr?r>rhrSrQr;r;�s�������7�7��b�j�R�TV�T]�`b�`j�Tj�k�k�G��R�Z��&�&�N�%�%�%�%�*r+�r+�r+�r+�h8�8�8�8�8�8rSr;c��eZdZdZd d�Zd S) r=z. Return a `img` element from the given match. rzr{r�rUrr)c��|�||�d����\}}}|sdS|�||��\}}}}|sdStjd��}|�d|��|�|�d|��|�d|�|����||�d��|fS)zU Return an `img` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. rr:�img�srcNr=�alt)r>r�r?r�r�r@r�r�) rtrzr�r�r&rAr^r=r�s rQrz ImageInlineProcessor.handleMatchPs���#�|�|�D�!�%�%��(�(�;�;���e�W�� $�#�#�%)�\�\�$��%>�%>�"��U�E�7�� $�#�#� �]�5� !� !�� ���u�c���� � � �F�F�7�E� "� "� "� ���u�d�m�m�D�)�)�*�*�*��1�7�7�1�:�:�u�$�$rSNr,r�rhrSrQr=r=Ms.������8�8�%�%�%�%�%�%rSr=c��eZdZdZejdej��Zejdejej z��Z dd �Z dd�Z dd�Z dS)r9z6 Match to a stored reference and return link element. z\s+z\s?\[([^\]]*)\]rzr{r�rUrr)c��|�||�d����\}}}|sdS|�|||��\}}}|sdS|j�d|��}||jjvrd|�d��|fS|jj|\}} |�|| |��|�d��|fS)zz Return [`Element`][xml.etree.ElementTree.Element] returned by `makeTag` method or `(None, None, None)`. rr:rGN) r>r��evalId�NEWLINE_CLEANUP_REr�r � referencesr��makeTag) rtrzr�r�r&rAr�r�r<r=s rQrz$ReferenceInlineProcessor.handleMatchks��� $�|�|�D�!�%�%��(�(�;�;���e�W�� $�#�#��;�;�t�U�D�9�9���C��� $�#�#�� $� (� (��b� 1� 1�� �T�W�'� '� '��������S�(� (��g�(��,� ��e��|�|�D�%��.�.����� � �C�?�?rSr&rr��tuple[str | None, int, bool]c���|j�||���}|sd|dfS|�d�����}|�d��}|s|���}||dfS)z\ Evaluate the id portion of `[ref][id]`. If `[ref][]` use `[ref]`. rDNFrrT)rHrr��lowerr�)rtr�r&r�rzr�r�s rQrbzReferenceInlineProcessor.evalId�s~�� �L� � �t�� � /� /��� "����%� %�������!�!�#�#�B��%�%��(�(�C�� "��Z�Z�\�\���3��}�rSr<r=r�c��tjd��}|�d|��|r|�d|��||_|S)z; Return an `a` [`Element`][xml.etree.ElementTree.Element]. r;r<r=)r�r�r@r��rtr<r=r�r�s rQrez ReferenceInlineProcessor.makeTag�sM�� �]�3� � �� ���v�t���� � #� �F�F�7�E� "� "� "����� rSNr,)r�rUr&rr�rUrrf�r<rUr=rUr�rUrr�)rcrdrerfrorp� MULTILINErcrqrrrHrrbrerhrSrQr9r9es�������@�@�#���F�B�L�9�9���b�j�+�R�Y���-C�D�D�G�@�@�@�@�,���� � � � � � rSr9c��eZdZdZd d �Zd S) rAz%Short form of reference: `[google]`. r�rUr&rr�rrWc�0�|���|dfS�zEvaluate the id of `[ref]`. T�rh�rtr�r&r�s rQrbz$ShortReferenceInlineProcessor.evalId�����z�z�|�|�U�D�(�(rSN�r�rUr&rr�rUrrW�rcrdrerfrbrhrSrQrArA�s.������/�/�)�)�)�)�)�)rSrAc��eZdZdZd d�Zd S) r?z7 Match to a stored reference and return `img` element. r<rUr=r�rr�c���tjd��}|�d|��|r|�d|��|�d|�|����|S)z= Return an `img` [`Element`][xml.etree.ElementTree.Element]. r]r^r=r_)r�r�r@r�rjs rQrez%ImageReferenceInlineProcessor.makeTag�sf�� �]�5� !� !�� ���u�d���� � #� �F�F�7�E� "� "� "� ���u�d�m�m�D�)�)�*�*�*�� rSNrk)rcrdrerfrerhrSrQr?r?�s.������A�A������rSr?c��eZdZdZd d �Zd S) rBz* Short form of image reference: `![ref]`. r�rUr&rr�rrWc�0�|���|dfSrorprqs rQrbz)ShortImageReferenceInlineProcessor.evalId�rrrSNrsrtrhrSrQrBrB�s.������4�4�)�)�)�)�)�)rSrBc��eZdZdZd d�Zd S) rCzD Return a link Element given an auto-link (`<http://example/com>`). rzr{r�rUrr�c�P�tjd��}|�d|�|�d������t j|�d����|_||�d��|� d��fS)zI Return an `a` [`Element`][xml.etree.ElementTree.Element] of `group(1)`. r;r<rr) r�r�r@r�r�rr�r�r�r�r�s rQrz#AutolinkInlineProcessor.handleMatch�sx�� �]�3� � �� ���v�t�}�}�Q�W�W�Q�Z�Z�0�0�1�1�1��#�A�G�G�A�J�J�/�/����1�7�7�1�:�:�q�u�u�Q�x�x�'�'rSNr�r�rhrSrQrCrC�s.������N�N�(�(�(�(�(�(rSrCc��eZdZdZd d�Zd S) rEzW Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`). rzr{r�rUrr�c���tjd��}|�|�d����}|�d��r|t d��d�}dd ���fd �|D��}t jd �|����|_ d|z}d �d �|D����}|� d |��||� d��|� d��fS)za Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link of `group(1)`. r;rzmailto:Nr�rrrUc��tj�|��}|r d�tj|��Sdtj|fzS)z=Return entity definition by code, or the code if not defined.z{}{};z%s#%d;)r �codepoint2namer�r�r�AMP_SUBSTITUTE)r�r*s rQr~z;AutomailInlineProcessor.handleMatch.<locals>.codepoint2name�sJ���,�0�0��6�6�F�� >��~�~�d�&9�6�B�B�B��4�#6��"=�=�=rSc�@��g|]}�t|������Srh)r�)�.0�letterr~s �rQ� <listcomp>z7AutomailInlineProcessor.handleMatch.<locals>.<listcomp>�s)���C�C�C�6�>�>�#�f�+�+�.�.�C�C�CrSr�c�L�g|]!}tjdt|��zz��"S)z#%d;)rrr�)r�r�s rQr�z7AutomailInlineProcessor.handleMatch.<locals>.<listcomp>�s@��<�<�<�*0��-���f�+�+�1&�&�<�<�<rSr<r)r�rrrU) r�r�r�r�rZr�rr�r�r�r@r�r�)rtrzr�r��email�letters�mailtor~s @rQrz#AutomailInlineProcessor.handleMatch�s��� �]�3� � ��� � �a�g�g�a�j�j�)�)�� � � �I� &� &� +��#�i�.�.�/�/�*�E� >� >� >� >�D�C�C�C�U�C�C�C���#�B�G�G�G�$4�$4�5�5����U�"�����<�<�4:�<�<�<�=�=�� ���v�v�����1�7�7�1�:�:�q�u�u�Q�x�x�'�'rSNr�r�rhrSrQrErE�s2��������(�(�(�(�(�(rSrE)r r r rrr)rTrUrrU)Crf� __future__rr�r�typingrrrr ro�xml.etree.ElementTreer�� ElementTreer(r �markdownr rR�NOIMGr6r8r1r0r6r7r5r-r3r.r4r/r<r>r:r@rMrDrFrJrKrHr\r^rjr�r�rLr7r�r�r�rGr5r�r�rIrNrOr;r=r9rAr?rBrCrErhrSrQ�<module>r�s���(��*#�"�"�"�"�"�������=�=�=�=�=�=�=�=�=�=�=�=� � � � �%�%�%�%�%�%�%�%�%��������"�!�!�!�!�!�!�*�*�*�*�` ��\�L� �M� � �=�� �7� � �5�:��b�9��c�O��B�,� �S�,� �V�,� �?�,� �B�9� �?� �%�-��`�� �S�� �5�"��:�8� �'�<� �=�&� �;� H��$� <� �V�� �(����������:����S?�S?�S?�S?�S?�S?�S?�S?�l- �- �- �- �- �g�- �- �- �`���������0�0�0�0�0��0�0�0�.�.�.�.�.�O�.�.�.�&�����w����:(�(�(�(�(��(�(�(�:'�'�'�'�'�+�'�'�'�=�=�=�=�=�#;�=�=�=�Y�Y�Y�Y�Y�o�Y�Y�Y�2�����'����*)�)�)�)�)�7�)�)�)�*$'�$'�$'�$'�$'�/�$'�$'�$'�NC�C�C�C�C��C�C�C�L P� P� P� P� P�+� P� P� P�_8�_8�_8�_8�_8�/�_8�_8�_8�D%�%�%�%�%�.�%�%�%�05�5�5�5�5�2�5�5�5�p)�)�)�)�)�$<�)�)�)� � � � � �$<� � � �)�)�)�)�)�)F�)�)�)�(�(�(�(�(�o�(�(�(�(�(�(�(�(�o�(�(�(�(�(rS
Memory