kbd Markdig Plugin
An overview of a simple Markdig extension for adding support for kbd tags.
I try to keep my markdown documents plain, avoiding HTML where possible. The core cyotek.com website is mostly powered by markdown, with embedded HTML and arcane constructs with assorted regular expression processors. The new blog uses pure markdown and although currently still uses an arcane construct or two for compatibility, these are provided via Markdig extensions rather than regular expressions.
However, one area I still keep writing HTML is for kbd
tags,
mostly in the documentation for our products but also in some
blog articles. I finally decided to write another extension
library to handle this and made it available for download.
The structure of this extension follows the same approach as in my original article on writing custom Markdig extensions, so I won't describe the code here.
The easiest way of obtaining the library is via NuGet.
Install-Package Cyotek.Markdig.Keyboard
When you build your Markdig pipeline, call UseKeyboard()
. Any
text wrapped in double angled brackets will be converted to
kbd
tags.
There is also a KeyboardOptions
class you can use to control
the output. Currently it allows you either to assign a CSS class
to generated elements via the ClassName
property, or specify a
different HTML tag via the TagName
property.
This first example uses default options, which output kbd
tags
with no further processing.
This second example uses custom options to change the output tag
to code
and apply a custom class.
.NET Framework 3.5 or later.
Pre-built binaries are available via a signed NuGet package containing the following targets.
Source code is available from the GitHub repository.
The main library and the test library projects are in the SDK
style. However, the WinForms demo is in the classic csproj
format - originally it was SDK using .NET 5, but the WinForms
designer in .NET 5 is shockingly bad. I had numerous issues with
it, ranging from the designer frequently unable to load, event
handlers getting unbound, and functionality like inline editing
of MenuStrip
controls just don't work at all.
In the end I converted it back to classic .NET as it is completely unusable in its current state, in my view.
This source is licensed under the MIT license. See LICENSE.txt
for the full text.
Like what you're reading? Perhaps you like to buy us a coffee?