Package: kbdextension
KBD Extension for Python-MarkdownThisPython-Markdownextension adds markdown syntax for the HTML<kbd>tag.  The<kbd>tag is typically used to indicate user input.  This extension provides markdown syntax for up to three different styled<kbd>tags.  For example, the author of a guide to using a UI might want to style<kbd>tags to indicate user input via keyboard keys, buttons, and menu choices.  The KBD Extension makes it possible for the author to create css specific for each type of user input and use markdown syntax to style their guide accordingly.SeeUsagefor more information.Installationpip install kbdextensionUsageThe KBD Extension is an inline processor for adding markdown syntax for inline<kbd>tags.  Text wrapped in double brackets, double braces, or double parenthesis will be wrapped with an HTML<kbd>tag.  The KBD Extension was designed to work with Python-Markdown default extensions. The KBD Extension markdown indicators can be individually enabled or disabled if conflicts are encountered when paired with other 3rd party extensions.  Brackets are enabled by default (but can be disabled).  Braces and parenthesis are disabled by default (but can be individually enabled).  By default, the page's default css implementation will be applied to the<kbd>tag(s).  The KBD Extension can be configured to use custom css for each of the KBD markdown indicators.Brackets Markdownmarkdown.markdown("Press the [[Enter]] key!",extensions=[KbdExtension()])The bracket syntax is enabled by default.  This will produce the following HTML:<p>Press the<kbd>Enter</kbd>key!</p>Custom css classes can be applied to<kbd>tags produced by brackets markdown.markdown.markdown("Press the [[Enter]] key!",extensions=[KbdExtension(brackets_css="bracket_css")])This will produce the following HTML:<p>Press the<kbdclass="bracket_css">Enter</kbd>key!</p>Braces MarkdownBraces markdown is disabled by default.  It can be enabled by settingenable_bracestoTruein the constructor.markdown.markdown("Click the {{Search}} button!",extensions=[KbdExtension(enable_braces=True)])This will produce the following HTML:<p>Click the<kbd>Search</kbd>button!</p>As with bracket syntax, custom css classes can be applied to<kbd>tags produced by braces markdown.markdown.markdown("Click the {{Search}} button!",extensions=[KbdExtension(enable_braces=True,braces_css="braces-css")],)This will produce the following HTML:<p>Click the<kbdclass="braces-css">Search</kbd>button!</p>Parenthesis MarkdownParenthesis markdown is disabled by default.  It can be enabled by settingenable_parenstoTruein the constructor.markdown.markdown("Click the ((File)) menu!",extensions=[KbdExtension(enable_parens=True)])This will produce the following HTML:<p>Click the<kbd>File</kbd>menu!</p>As with bracket syntax, custom css classes can be applied to<kbd>tags produced by parenthesis markdown.markdown.markdown("Click the ((File)) menu!",extensions=[KbdExtension(enable_parens=True,parens_css="parens-css")],)This will produce the following HTML:<p>Click the<kbdclass="parens-css">File</kbd>menu!</p>MkDocs ConfigurationThe KBD Extension can be configured for use withMkDocs.  This extension provides configuration options of its own as described in theusage notesabove. Configuration options are nested in a key/value mapping in themarkdown_extensions:section of themkdocs.ymlconfiguration file.  Example configurations for this extension are provided below.  For more on configuring markdown extensions in MkDocs, refer toMkDocs configuration documentation.Default ConfigurationThe default configuration enables bracket syntax only.markdown_extensions:-kbdextensionPartial ConfigurationThis partial configuration example disables the brackets markdown indicator and enables the braces markdown indicator with a custom css class for the<kbd>tag that it renders.extra_css:-css/extra.cssmarkdown_extensions:-kbdextension:enable_brackets:falseenable_braces:truebraces_css:braces_kbd_cssFull ConfigurationA full configuration enables brackets, braces, and parenthesis markdown indicators along with custom css for each.  Note that brackets are enabled by default so it is not necessary to set theenable_bracketsconfiguration totrue.extra_css:-css/extra.cssmarkdown_extensions:-kbdextension:brackets_css:brackets_kbd_cssenable_braces:truebraces_css:braces_kbd_cssenable_parens:trueparens_css:parens_kbd_cssFor more on configuring custom css in MkDocs, refer toMkDocs configuration documentation.MkDocs ExampleThe following example demonstrates the use of all three markdown indicators available with the KBD Extension.First we created the custom css for the site.   For this example, theextra.cssfile defines each of the three custom KBD css classes we will require.  Theextra.cssfile is saved in acsssubdirectory of MkDocsdocs_dirdirectory.  The following css was used for this example:kbd.button-css{font-family:Menlo,Consolas,monospace;font-size:75%;padding:2px6px;color:#ffffff;background-color:#6699cc;border-radius:3px;-webkit-box-shadow:inset0001px#333333;box-shadow:inset0001px#333333;}kbd.menu-css{font-family:Menlo,Consolas,monospace;font-size:75%;padding:2px4px;color:#333333;background-color:#f2f2f2;border-radius:3px;-webkit-box-shadow:inset0001px#333333;box-shadow:inset0001px#333333;}kbd.keyboard-css{font-family:Menlo,Consolas,monospace;font-size:75%;padding:2px6px;color:#ffffff;background-color:#333333;border-radius:3px;-webkit-box-shadow:inset0-1px0rgba(0,0,0,0.25);box-shadow:inset0-1px0rgba(0,0,0,0.25);}Next, we create the markdown for the example.  We make use of all three KBD syntax indicators in this example to render three distinct<kbd>HTML tags.  The markdown is shown here:Click the {{Open...}} menu or press ((CTRL)) + ((O)) to open.
Click the [[SAVE]] button to save changes.Next, themkdocs.ymlconfiguration file is updated to includeextra_css:and a full KBD Extension configuration as follows:extra_css:-css/extra.cssmarkdown_extensions:-kbdextension:brackets_css:button-cssenable_braces:truebraces_css:menu-cssenable_parens:trueparens_css:keyboard-cssKBD Extension together with MkDocs and Python-Markdown renders the following HTML:Click the<kbdclass="menu-css">Open...</kbd>menu or press<kbdclass="keyboard-css">CTRL</kbd>+<kbdclass="keyboard-css">O</kbd>to open.
Click the<kbdclass="button-css">SAVE</kbd>button to save changes.LicenseThis software is provided under the MIT License. SeeLICENSEfor details.