
    g                         S r SSKJr  SSKJrJrJr  SSKJrJ	r	  SSK
Jr  SSKJr  \(       a  SSKJr   " S S	5      r\r\" S0 \D6 " S
 S5      5       r " S S5      rg)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)CallableIterableMutableMapping)	dataclassfield)TYPE_CHECKING)DATACLASS_KWARGS)
MarkdownItc                  f    \ rS rSr% S\S'   S	S jr\S
S j5       r\R                  SS j5       rSr	g)	StateBase   ztuple[int, ...]srcCharCodec                (    Xl         X0l        X l        g N)srcenvmd)selfr   r   r   s       1lib/python3.13/site-packages/markdown_it/ruler.py__init__StateBase.__init__!   s        c                    U R                   $ r   )_srcr   s    r   r   StateBase.src&   s    yyr   c                R    Xl         [        S U R                   5       5      U l        g )Nc              3  6   #    U H  n[        U5      v   M     g 7fr   )ord).0cs     r   	<genexpr> StateBase.src.<locals>.<genexpr>-   s      :AQs   )r   tupler   r   )r   values     r   r   r   *   s    	  : ::r   )r   r   r   r   r   N)r   strr   r   r   r   )returnr'   )r&   r'   r(   None)
__name__
__module____qualname____firstlineno____annotations__r   propertyr   setter__static_attributes__ r   r   r   r      s9      
   	ZZ; ;r   r   c                  J    \ rS rSr% S\S'   S\S'   \" SS9rS\S	'   S
\S'   Srg)Rule7   r'   nameboolenabledF)reprRuleFuncfn	list[str]altr2   N)r*   r+   r,   r-   r.   r   r;   r1   r2   r   r   r4   r4   7   s     
IMe$B$	Nr   r4   c                      \ rS rSrS rSS jrSS jrSSS jjrSSS jjrSSS jjr	SSS	 jjr
SSS
 jjrSSS jjrSSS jjrSS jrSS jrSS jrSrg)Ruler?   c                     / U l         S U l        g r   )	__rules__	__cache__r   s    r   r   Ruler.__init__@   s    %' <@r   c                h    [        U R                  5       H  u  p#UR                  U:X  d  M  Us  $    g)zFind rule index by name)	enumeraterB   r6   )r   r6   irules       r   __find__Ruler.__find__H   s-     0GAyyD  1 r   c                   S1nU R                    H:  nUR                  (       d  M  UR                   H  nUR                  U5        M     M<     0 U l        U Hx  n/ U R                  U'   U R                    HV  nUR                  (       d  M  U(       a  XBR                  ;  a  M.  U R                  U   R                  UR                  5        MX     Mz     g)zBuild rules lookup cache N)rB   r8   r=   addrC   appendr;   )r   chainsrI   r6   chains        r   __compile__Ruler.__compile__O   s    NND<<

4  ! #
 E$&DNN5!||e883u%,,TWW5 ' r   Nc                    U R                  U5      nU=(       d    0 nUS:X  a  [        SU 35      eX R                  U   l        UR	                  S/ 5      U R                  U   l        SU l        g)zReplace 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
rF   Parser rule not found: r=   N)rJ   KeyErrorrB   r;   getr=   rC   )r   ruleNamer;   optionsindexs        r   atRuler.atb   sg     h'-RB;4XJ?@@#%u $+KKr$:u!r   c                    U R                  U5      nU=(       d    0 nUS:X  a  [        SU 35      eU R                  R                  U[	        USX4R                  S/ 5      5      5        SU l        g)a  Add 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
rF   rU   Tr=   NrJ   rV   rB   insertr4   rW   rC   )r   
beforeNamerX   r;   rY   rZ   s         r   beforeRuler.beforer   se     j)-RB;4ZLABBeT(D"kk%QS>T%UVr   c                    U R                  U5      nU=(       d    0 nUS:X  a  [        SU 35      eU R                  R                  US-   [	        USX4R                  S/ 5      5      5        SU l        g)a  Add 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
rF   rU      Tr=   Nr^   )r   	afterNamerX   r;   rY   rZ   s         r   afterRuler.after   sm     i(-RB;4YK@AAAItHdBE20FG	
 r   c                    U R                   R                  [        USX#=(       d    0 R                  S/ 5      5      5        SU l        g)zPush 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)rB   rO   r4   rW   rC   )r   rX   r;   rY   s       r   push
Ruler.push   s8     	d8T227J7J5RT7UVWr   c                   [        U[        5      (       a  U/n/ nU Hc  nU R                  U5      nUS:  a	  U(       a  M#  US:  a  U(       d  [        SU 35      eSU R                  U   l        UR                  U5        Me     SU l        U$ )zEnable 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
isinstancer'   rJ   rV   rB   r8   rO   rC   r   namesignoreInvalidresultr6   idxs         r   enableRuler.enable   s     eS!!GED--%Ca]a!B4&IJJ*.DNN3'MM$  r   c                    [        U[        5      (       a  U/nU R                   H
  nSUl        M     U R	                  X5        g)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
FN)rn   r'   rB   r8   rt   )r   rp   rq   rI   s       r   
enableOnlyRuler.enableOnly   s9     eS!!GENND DL #E)r   c                   [        U[        5      (       a  U/n/ nU Hc  nU R                  U5      nUS:  a	  U(       a  M#  US:  a  U(       d  [        SU 35      eSU R                  U   l        UR                  U5        Me     SU l        U$ )zDisable 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   rl   FNrm   ro   s         r   disableRuler.disable   s     eS!!GED--%Ca]a!B4&IJJ*/DNN3'MM$  r   c                    U R                   c  U R                  5         U R                   c   eU R                   R                  U/ 5      =(       d    / $ )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.

)rC   rR   rW   )r   	chainNames     r   getRulesRuler.getRules   sF     >>!>>---~~!!)R06B6r   c                V    U R                    Vs/ sH  oR                  PM     sn$ s  snf )z Return all available rule names.)rB   r6   r   rs     r   get_all_rulesRuler.get_all_rules   s      $/1///s   &c                |    U R                    Vs/ sH!  oR                  (       d  M  UR                  PM#     sn$ s  snf )zReturn the active rule names.)rB   r8   r6   r   s     r   get_active_rulesRuler.get_active_rules   s(     $<1))<<<s   99)rC   rB   )r6   r'   r(   int)r(   r)   r   )rX   r'   r;   r:   )r`   r'   rX   r'   r;   r:   )re   r'   rX   r'   r;   r:   )F)rp   zstr | Iterable[str]rq   r7   )r}   r'   r(   zlist[RuleFunc])r(   r<   )r*   r+   r,   r-   r   rJ   rR   r[   ra   rf   ri   rt   rw   rz   r~   r   r   r1   r2   r   r   r?   r?   ?   sD    @6&  $	,*,70=r   r?   Nr2   )__doc__
__future__r   collections.abcr   r   r   dataclassesr   r   typingr	   markdown_it._compatr
   markdown_itr   r   r:   r4   r?   r2   r   r   <module>r      sc   " # > > (   0&; ;,    n= n=r   