""" 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 `` elements. If a key is found in the extension's database, its `` 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`` element, and then, each keystroke is wrapped into a separate inner `` element, which matches the HTML5 spec. If `strict` is `False`, an outer `` is used, which matches the practice on Github or StackOverflow. The resulting `` 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 ```

Press Shift+Alt+Page Up, type in Hello and press Enter.

``` ### Config 2 ``` pymdownx.keys: camel_case: true strict: true separator: '' ``` ### Output 2 ```

Press ShiftAltPage Up, type in Hello and press Enter.

``` Idea by Adam Twardoch and coded by Isaac Muse. Copyright (c) 2017 Isaac Muse 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. """ import html from markdown import Extension from markdown.inlinepatterns import InlineProcessor from markdown import util as md_util import xml.etree.ElementTree as etree from . import util from . import keymap_db as keymap import re RE_EARLY_KBD = r'''(?x) (?: # Escape (?(?:\\{2})+)(?=\+)| # Key (? pg-dn - Default: False'], 'key_map': [{}, 'Additional keys to include or keys to override - Default: {}'] } super().__init__(*args, **kwargs) def extendMarkdown(self, md): """Add support for keys.""" util.escape_chars(md, ['+']) md.inlinePatterns.register(KeysPattern(RE_EARLY_KBD, self.getConfigs(), md, early=True), "keys-custom", 185) md.inlinePatterns.register(KeysPattern(RE_KBD, self.getConfigs(), md), "keys", 70) def makeExtension(*args, **kwargs): """Return extension.""" return KeysExtension(*args, **kwargs)