� K�g�#��8�dZddlmZddlmZddlmZmZddlm Z m Z m Z m Z ddl Z ddlmZdd lmZe rdd lmZGd �d ��ZGd �de d���Ze d��Z edie��Gd�de e����ZGd�de e��ZdS)a� class Ruler Helper class, used by [[MarkdownIt#core]], [[MarkdownIt#block]] and [[MarkdownIt#inline]] to manage sequences of functions (rules): - keep rules in defined order - assign the name to each rule - enable/disable rules - add/replace rules - allow assign rules to additional named chains (in the same) - caching lists of active rules You will not need use this class directly until write plugins. For simple rules control use [[MarkdownIt.disable]], [[MarkdownIt.enable]] and [[MarkdownIt.use]]. �)� annotations)�Iterable)� dataclass�field)� TYPE_CHECKING�Generic� TypedDict�TypeVarN)�DATACLASS_KWARGS�)�EnvType)� MarkdownItc�h�eZdZdd�Zedd ���Zejdd ���Zedd���ZdS)� StateBase�src�str�mdr�envr c�0�||_||_||_dS�N)rrr)�selfrrrs �a/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/markdown_it/ruler.py�__init__zStateBase.__init__"s��������������returnc��|jSr)�_src�rs rrz StateBase.src's ���y�r�value�Nonec�"�||_d|_dSr)r� _srcCharCode)rrs rrz StateBase.src+s���� �48����r�tuple[int, ...]c��tjdtd���|j�#t d�|jD����|_|jS)Nz?StateBase.srcCharCode is deprecated. Use StateBase.src instead.�)� stacklevelc3�4K�|]}t|��V��dSr)�ord)�.0�cs r� <genexpr>z(StateBase.srcCharCode.<locals>.<genexpr>8s(����%@�%@��c�!�f�f�%@�%@�%@�%@�%@�%@r)�warnings�warn�DeprecationWarningr"�tuplerrs r� srcCharCodezStateBase.srcCharCode0sY��� � M� �� � � � � � � $� %�%@�%@�d�i�%@�%@�%@� @� @�D� �� � rN)rrrrrr )rr)rrrr )rr#)�__name__� __module__� __qualname__r�propertyr�setterr0�rrrr!s����������� �����X�� �Z�9�9�9��Z�9��!�!�!��X�!�!�!rrc��eZdZUded<dS)�RuleOptionsType� list[str]�altN)r1r2r3�__annotations__r6rrr8r8<s��������N�N�N�N�Nrr8F)�total� RuleFuncTvc�P�eZdZUded<ded<ed���Zded<d ed <d S) �Ruler�name�bool�enabledF)�reprr=�fnr9r:N)r1r2r3r;rrDr6rrr?r?DsI������� �I�I�I��M�M�M��U��&�&�&�B�&�&�&�&��N�N�N�N�Nrr?c��eZdZd$d�Zd%d�Zd$d�Z d&d'd�Z d&d(d�Z d&d)d�Z d&d'd�Z d*d+d�Z d*d+d�Z d*d+d�Z d,d-d!�Z d.d"�Zd.d#�Zd S)/�Rulerrr c�"�g|_d|_dSr)� __rules__� __cache__rs rrzRuler.__init__Ms��13���>B����rr@r�intc�X�t|j��D]\}}|j|kr|cS�dS)zFind rule index by name�����)� enumeraterHr@)rr@�i�rules r�__find__zRuler.__find__Us?�� ���0�0� � �G�A�t��y�D� � �����!��rrc� �dh}|jD])}|js� |jD]}|�|����*i|_|D]O}g|j|<|jD];}|js� |r ||jvr�|j|�|j���<�PdS)zBuild rules lookup cache�N)rHrBr:�addrI�appendrD)r�chainsrOr@�chains r� __compile__zRuler.__compile__\s�������N� !� !�D��<� ���� !� !��� � �4� � � � � !����� 6� 6�E�$&�D�N�5� !��� 6� 6���|�����e�4�8�3�3����u�%�,�,�T�W�5�5�5�5�  6� 6� 6rN�ruleNamerDr=�options�RuleOptionsType | Nonec���|�|��}|pi}|dkrtd|�����||j|_|�dg��|j|_d|_dS)z�Replace rule by name with new function & options. :param ruleName: rule name to replace. :param fn: new rule function. :param options: new rule options (not mandatory). :raises: KeyError if name not found rL�Parser rule not found: r:N)rP�KeyErrorrHrD�getr:rI)rrXrDrY�indexs r�atzRuler.atosu��� � �h�'�'���-�R�� �B�;�;��?�X�?�?�@�@� @�#%���u�� �$+�K�K��r�$:�$:���u��!�����r� beforeNamec � �|�|��}|pi}|dkrtd|�����|j�|t t |d||�dg������d|_dS)aKAdd new rule to chain before one with given name. :param beforeName: new rule will be added before this one. :param ruleName: new rule will be added before this one. :param fn: new rule function. :param options: new rule options (not mandatory). :raises: KeyError if name not found rLr\Tr:N�rPr]rH�insertr?r=r^rI)rrarXrDrYr_s r�beforez Ruler.before�s���� � �j�)�)���-�R�� �B�;�;��A�Z�A�A�B�B� B� ���� �4� �#�H�d�B�� � �E�2�8N�8N�O�O� � � �����r� afterNamec ��|�|��}|pi}|dkrtd|�����|j�|dzt t |d||�dg������d|_dS)aGAdd new rule to chain after one with given name. :param afterName: new rule will be added after this one. :param ruleName: new rule will be added after this one. :param fn: new rule function. :param options: new rule options (not mandatory). :raises: KeyError if name not found rLr\r Tr:Nrc)rrfrXrDrYr_s r�afterz Ruler.after�s���� � �i�(�(���-�R�� �B�;�;��@�Y�@�@�A�A� A� ���� �A�I�t�J�'��$��G�K�K��r�<R�<R�S�S� � � �����rc ��|j�tt|d||pi�dg������d|_dS)z�Push new rule to the end of chain. :param ruleName: new rule will be added to the end of chain. :param fn: new rule function. :param options: new rule options (not mandatory). Tr:N)rHrTr?r=r^rI)rrXrDrYs r�pushz Ruler.push�sU�� ���� �� �X�t�R�'�-�R�1D�1D�U�B�1O�1O� P� P� � � �����rF�names�str | Iterable[str]� ignoreInvalidrAr9c��t|t��r|g}g}|D]a}|�|��}|dkr|r� |dkr|std|�����d|j|_|�|���bd|_|S)aEnable rules with given names. :param names: name or list of rule names to enable. :param ignoreInvalid: ignore errors when rule not found :raises: KeyError if name not found and not ignoreInvalid :return: list of found rule names r�!Rules manager: invalid rule name TN�� isinstancerrPr]rHrBrTrI�rrkrm�resultr@�idxs r�enablez Ruler.enable�s��� �e�S� !� !� ��G�E���� � �D��-�-��%�%�C��a���]����a������I�4�I�I�J�J�J�*.�D�N�3� � '� �M�M�$� � � � ����� rc��t|t��r|g}|jD] }d|_� |�||��S)a-Enable rules with given names, and disable everything else. :param names: name or list of rule names to enable. :param ignoreInvalid: ignore errors when rule not found :raises: KeyError if name not found and not ignoreInvalid :return: list of found rule names F)rqrrHrBru)rrkrmrOs r� enableOnlyzRuler.enableOnly�sK�� �e�S� !� !� ��G�E��N� !� !�D� �D�L�L��{�{�5�-�0�0�0rc��t|t��r|g}g}|D]a}|�|��}|dkr|r� |dkr|std|�����d|j|_|�|���bd|_|S)aDisable rules with given names. :param names: name or list of rule names to enable. :param ignoreInvalid: ignore errors when rule not found :raises: KeyError if name not found and not ignoreInvalid :return: list of found rule names rroFNrprrs r�disablez Ruler.disable�s��� �e�S� !� !� ��G�E���� � �D��-�-��%�%�C��a���]����a������I�4�I�I�J�J�J�*/�D�N�3� � '� �M�M�$� � � � ����� rrR� chainName�list[RuleFuncTv]c��|j�|���|j�J�|j�|g��pgS)a=Return array of active functions (rules) for given chain name. It analyzes rules configuration, compiles caches if not exists and returns result. Default chain name is `''` (empty string). It can't be skipped. That's done intentionally, to keep signature monomorphic for high speed. )rIrWr^)rrzs r�getRuleszRuler.getRulessI�� �>� !� � � � � � ��>�-�-�-��~�!�!�)�R�0�0�6�B�6rc�$�d�|jD��S)z Return all available rule names.c��g|] }|j�� Sr6)r@�r)�rs r� <listcomp>z'Ruler.get_all_rules.<locals>.<listcomp>s��/�/�/�1���/�/�/r�rHrs r� get_all_ruleszRuler.get_all_ruless��/�/���/�/�/�/rc�$�d�|jD��S)zReturn the active rule names.c�*�g|]}|j� |j��Sr6)rBr@r�s rr�z*Ruler.get_active_rules.<locals>.<listcomp>s!��<�<�<�1�!�)�<���<�<�<rr�rs r�get_active_ruleszRuler.get_active_ruless��<�<���<�<�<�<r)rr )r@rrrJr)rXrrDr=rYrZrr ) rarrXrrDr=rYrZrr ) rfrrXrrDr=rYrZrr )F)rkrlrmrArr9)rR)rzrrr{)rr9)r1r2r3rrPrWr`rerhrjrurwryr}r�r�r6rrrFrFLsq������B�B�B�B�����6�6�6�6�(PT������.+/� �����:+/� �����2PT� � � � � � AF������2AF�1�1�1�1�1�"AF������0 7� 7� 7� 7� 7�0�0�0�0�=�=�=�=�=�=rrFr6)�__doc__� __future__r�collections.abcr� dataclassesrr�typingrrr r r,�markdown_it._compatr �utilsr � markdown_itrrr8r=r?rFr6rr�<module>r�s�����"#�"�"�"�"�"�$�$�$�$�$�$�(�(�(�(�(�(�(�(�=�=�=�=�=�=�=�=�=�=�=�=�����0�0�0�0�0�0��������'�&�&�&�&�&�&�!�!�!�!�!�!�!�!�6�����i�u������W�\� "� "� �F� ���� ��������7�:� ������H=�H=�H=�H=�H=�G�J� �H=�H=�H=�H=�H=r
Memory