
    $gG                     F   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	c m
Z	 ddlmZ ddlmZ ddlZdZd	Z ej        d
          Z ej        d          Zd                    ej         ed          ej                  ZdZ G d de          Z G d de          Zd ZdS )a  
Keys.

pymdownx.keys
Markdown extension for keystroke (user keyboard input) formatting.

It wraps the syntax `++key+key+key++` (for individual keystrokes with modifiers)
or `++"string"++` (for continuous keyboard input) into HTML `<kbd>` elements.

If a key is found in the extension's database, its `<kbd>` element gets a matching class.
Common synonyms are included, e.g. `++pg-up++` will match as `++page-up++`.

## Config

If `strict` is `True`, the entire series of keystrokes is wrapped into an outer`<kbd>` element, and then,
each keystroke is wrapped into a separate inner `<kbd>` element, which matches the HTML5 spec.
If `strict` is `False`, an outer `<span>` is used, which matches the practice on Github or StackOverflow.

The resulting `<kbd>` elements are separated by `separator` (`+` by default, can be `''` or something else).

If `camel_case` is `True`, `++PageUp++` will match the same as `++page-up++`.

The database can be extended or modified with the `key_map` dict.

## Examples

### Input

```
Press ++Shift+Alt+PgUp++, type in ++"Hello"++ and press ++Enter++.
```

### Config 1

```
  pymdownx.keys:
    camel_case: true
    strict: false
    separator: '+'
```

### Output 1

```
<p>Press <span class="keys"><kbd class="key-shift">Shift</kbd><span>+</span><kbd
class="key-alt">Alt</kbd><span>+</span><kbd class="key-page-up">Page Up</kbd></span>, type in <span
class="keys"><kbd>Hello</kbd></span> and press <span class="keys"><kbd class="key-enter">Enter</kbd></span>.</p>
```

### Config 2

```
  pymdownx.keys:
    camel_case: true
    strict: true
    separator: ''
```

### Output 2

```
<p>Press <kbd class="keys"><kbd class="key-shift">Shift</kbd><kbd class="key-alt">Alt</kbd><kbd
class="key-page-up">Page Up</kbd></kbd>, type in <kbd class="keys"><kbd>Hello</kbd></kbd> and press <kbd
class="keys"><kbd class="key-enter">Enter</kbd></kbd>.</p>
```

Idea by Adam Twardoch and coded by Isaac Muse.

Copyright (c) 2017 Isaac Muse <isaacmuse@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    N)	Extension)InlineProcessor)util   )	keymap_dbz(?x)
(?:
    # Escape
    (?<!\\)(?P<escapes>(?:\\{2})+)(?=\+)|
    # Key
    (?<!\\)\+{2}
    (
        (?:(?:[\w\-]+|"(?:\\.|[^"])+"|\'(?:\\.|[^\'])+\')\+)*?
        (?:[\w\-]+|"(?:\\.|[^"])+"|\'(?:\\.|[^\'])+\')
    )
    \+{2}
)
z"\+{2}([\w\-]+(?:\+[\w\-]+)*?)\+{2}z(?<!\\)(?:\\\\)*\\(.)z(?<!\\)(?:\\\\)*(\+)z{}{}{}\z\\c                   <     e Zd ZdZd fd	Zd Zd Zd Zd Z xZ	S )	KeysPatternzReturn kbd tag.Fc                 `   |d         | _         |d         | _        |d                             d          | _        |                     t
          j        |d                   | _        t
          j        | _        |d         | _        || _	        t                                          ||           dS )Initialize.	separatorstrictclass key_map
camel_caseN)ksepr   splitclassesmergekeymapmapaliasescamelearlysuper__init__)selfpatternconfigmdr   	__class__s        M/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/keys.pyr   zKeysPattern.__init__w   s     ;'	X&g,,S11::fmVI->??~L)

"%%%%%    c                 X    |                                 }|                    |           |S )z,Given two dicts, merge them into a new dict.)copyupdate)r   xyzs       r#   r   zKeysPattern.merge   s%     FFHH	r$   c                 Z   | j         s|S g }d}|D ]}|                                rZ|r|dk    r(|                    |                                           n?|                    d|                                g           n|                    |           |}d                    |          S )zNormalize the value. -)r   isupperappendlowerextendjoin)r   keynorm_keylastcs        r#   	normalizezKeysPattern.normalize   s     z 	J 	 	Ayy{{ # 6ts{{OOAGGII....OOS!''))$45555"""DDwwx   r$   c           	      j   |                     d          rJdt          j        t                              d|dd                                                             f}nS|                     |          }| j                            ||          }| j	                            |d          }|r||fnd}|S )zProcess key."'Nz\1r   )

startswithhtmlunescape	ESCAPE_REsubstripr7   r   getr   )r   r3   valuer4   canonical_keynames         r#   process_keyzKeysPattern.process_key   s     >>*%% 	<4=uc!B$i)H)HIIOOQQREE~~c**H L,,Xx@@M8<<t44D-1;]D))tEr$   c                      j         r|                    d          r\|                    d                              t          t                    |                    d          |                    d          fS d}g }t                              |                    d                    D ]J}|dk    rB|	                    d          r|dz  }|
                                         |                     K|sdS n4 fd|                    d                              d          D             }d	|v rdS t          j         j        rd
nd j        rdd                     j                  ini           }d	}|D ]\  }}	g }
|r|

                    d|z              |: j        r3t          j        |d          }t'          j         j                  |_        i }|
rd                    |
          |d<   t          j        |d
|          }t'          j        |	          |_        |}||                    d          |                    d          fS )zHandle kbd pattern matches.r   escapesr      +r9   )NNNc                 :    g | ]}                     |          S  )rG   ).0r3   r   s     r#   
<listcomp>z+KeysPattern.handleMatch.<locals>.<listcomp>   s'    NNNt'',,NNNr$   Nkbdspanr   r   zkey-)r   groupreplaceDOUBLE_BSLASHESCAPED_BSLASHstartendUNESCAPED_PLUSr   r=   r/   rG   etreeElementr   r   r2   r   
SubElementmd_utilAtomicStringtext)r   mdataquotedcontentr3   elr5   
item_class	item_namer   rQ   attrrP   s   `             r#   handleMatchzKeysPattern.handleMatch   s]    : 	Owwqzz gwwy))11-PPRSRYRYZ[R\R\^_^c^cde^f^fffFG%++AGGAJJ77 : :#::~~j11 $!NN4#3#3C#8#8999 (''( ONNN

8H8H8M8MNNNG7??##]k-UUv26,Fgsxx--..B
 

 %, 	 	!J	G 4v
2333DI'F33#0;;	D 2 # 1 1W"2ud33C+I66CHDD1771::quuQxx''r$   )F)
__name__
__module____qualname____doc__r   r   r7   rG   rg   __classcell__r"   s   @r#   r
   r
   t   s        
& 
& 
& 
& 
& 
&  ! ! !&
 
 
*( *( *( *( *( *( *(r$   r
   c                   (     e Zd ZdZ fdZd Z xZS )KeysExtensionz(Add `keys`` extension to Markdown class.c                 h    ddgddgddgddgi dgd	| _          t                      j        |i | d
S )r   rK   z+Provide a keyboard separator - Default: "+"Fz>Format keys and menus according to HTML5 spec - Default: Falsekeysz8Provide class(es) for the kbd elements - Default: "keys"zGAllow camelCase conversion for key names PgDn -> pg-dn - Default: Falsez<Additional keys to include or keys to override - Default: {})r   r   r   r   r   N)r    r   r   )r   argskwargsr"   s      r#   r   zKeysExtension.__init__   sd     NO^_Z[ "klZ[
 
 	$)&)))))r$   c                 >   t          j        |dg           |j                            t	          t
          |                                 |d          dd           |j                            t	          t          |                                 |          dd           dS )	zAdd support for keys.rK   T)r   zkeys-custom   rq   F   N)r   escape_charsinlinePatternsregisterr
   RE_EARLY_KBD
getConfigsRE_KBD)r   r!   s     r#   extendMarkdownzKeysExtension.extendMarkdown   s     	"se$$$
"";|T__=N=NPRZ^#_#_#_anpsttt
"";vt7H7H"#M#MvWYZZZZZr$   )rh   ri   rj   rk   r   r}   rl   rm   s   @r#   ro   ro      sT        22
* 
* 
* 
* 
*[ [ [ [ [ [ [r$   ro   c                      t          | i |S )zReturn extension.)ro   )rr   rs   s     r#   makeExtensionr      s     $)&)))r$   )rk   r>   markdownr   markdown.inlinepatternsr   r   r\   xml.etree.ElementTreerY   ElementTreer,   r   r   rerz   r|   compiler@   rX   formatSTXordETXrU   rT   r
   ro   r   rM   r$   r#   <module>r      sq  S Sh        3 3 3 3 3 3 $ $ $ $ $ $ % % % % % % % % %       ! ! ! ! ! ! 				 
/BJ344	788cc$iiEE_( _( _( _( _(/ _( _( _(D[ [ [ [ [I [ [ [.* * * * *r$   