-
Notifications
You must be signed in to change notification settings - Fork 32
Add kbd element #1537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add kbd element #1537
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea0d057
Add kbd
reakaleek d110ece
Styling adjustments
reakaleek be6391e
Revert req.md
reakaleek 69eae10
Merge branch 'main' into feature/kbd
reakaleek 9c5891e
Add test
reakaleek 634768b
Use keywords for special keys and allow combined keys
reakaleek 462ae29
Fix formatting
reakaleek 1909a66
Emit error when parsing fails
reakaleek 7f000bf
Use unknown key on error
reakaleek b65fcbc
Add aria-label
reakaleek 4d4690a
Fix heading casing
reakaleek c3cb493
Add ability to show alternate keys with '|'
reakaleek bd2d7fa
Adjust tests
reakaleek fa30512
Run prettier
reakaleek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Keyboard shortcuts | ||
|
|
||
| You can represent keyboard keys and shortcuts in your documentation using the `{kbd}` role. This is useful for showing keyboard commands and shortcuts in a visually consistent way. | ||
|
|
||
| ## Basic usage | ||
|
|
||
| To display a keyboard key, use the syntax `` {kbd}`key-name` ``. For example, writing `` {kbd}`Enter` `` will render as a styled keyboard key. | ||
|
|
||
| ::::{tab-set} | ||
|
|
||
| :::{tab-item} Output | ||
| Press {kbd}`Enter` to submit. | ||
| ::: | ||
|
|
||
| :::{tab-item} Markdown | ||
| ```markdown | ||
| Press {kbd}`Enter` to submit. | ||
| ``` | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
| ## Keyboard combinations | ||
|
|
||
| You can represent keyboard combinations by joining multiple `{kbd}` roles with a plus sign (+). | ||
|
|
||
| ::::{tab-set} | ||
|
|
||
| :::{tab-item} Output | ||
| {kbd}`ctrl` + {kbd}`C` to copy text. | ||
|
|
||
| {kbd}`Shift` + {kbd}`Alt` + {kbd}`F` to format the document. | ||
| ::: | ||
|
|
||
| :::{tab-item} Markdown | ||
| ```markdown | ||
| {kbd}`Ctrl` + {kbd}`C` to copy text. | ||
|
|
||
| {kbd}`Shift` + {kbd}`Alt` + {kbd}`F` to format the document. | ||
| ``` | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
| ## Common shortcuts by platform | ||
|
|
||
| Here are some common keyboard shortcuts across different platforms: | ||
|
|
||
| ::::{tab-set} | ||
|
|
||
| :::{tab-item} Output | ||
| | Mac | Windows/Linux | Description | | ||
| |-------------------------|----------------------------|-----------------------------| | ||
| | {kbd}`⌘` + {kbd}`C` | {kbd}`Ctrl` + {kbd}`C` | Copy | | ||
| | {kbd}`⌘` + {kbd}`V` | {kbd}`Ctrl` + {kbd}`V` | Paste | | ||
| | {kbd}`⌘` + {kbd}`Z` | {kbd}`Ctrl` + {kbd}`Z` | Undo | | ||
| | {kbd}`⌘` + {kbd}`Enter` | {kbd}`Ctrl` + {kbd}`Enter` | Run a query | | ||
| | {kbd}`⌘` + {kbd}`/` | {kbd}`Ctrl` + {kbd}`/` | Comment or uncomment a line | | ||
| ::: | ||
|
|
||
| :::{tab-item} Markdown | ||
| ```markdown | ||
| | Mac | Windows/Linux | Description | | ||
| |-------------------------|----------------------------|-----------------------------| | ||
| | {kbd}`⌘` + {kbd}`C` | {kbd}`Ctrl` + {kbd}`C` | Copy | | ||
| | {kbd}`⌘` + {kbd}`V` | {kbd}`Ctrl` + {kbd}`V` | Paste | | ||
| | {kbd}`⌘` + {kbd}`Z` | {kbd}`Ctrl` + {kbd}`Z` | Undo | | ||
| | {kbd}`⌘` + {kbd}`Enter` | {kbd}`Ctrl` + {kbd}`Enter` | Run a query | | ||
| | {kbd}`⌘` + {kbd}`/` | {kbd}`Ctrl` + {kbd}`/` | Comment or uncomment a line | | ||
| ``` | ||
| ::: | ||
|
|
||
| :::: | ||
|
|
||
| ## Special keys | ||
|
|
||
| Some commonly used special keys: | ||
|
|
||
| ::::{tab-set} | ||
|
|
||
| :::{tab-item} Output | ||
| | Symbol | Key Description | | ||
| |-----------|------------------| | ||
| | {kbd}`⌘` | Command (Mac) | | ||
| | {kbd}`⌥` | Option/Alt (Mac) | | ||
| | {kbd}`⇧` | Shift | | ||
| | {kbd}`⌃` | Control | | ||
| | {kbd}`↩` | Return/Enter | | ||
| | {kbd}`⌫` | Delete/Backspace | | ||
| | {kbd}`⇥` | Tab | | ||
| | {kbd}`↑` | Up Arrow | | ||
| | {kbd}`↓` | Down Arrow | | ||
| | {kbd}`←` | Left Arrow | | ||
| | {kbd}`→` | Right Arrow | | ||
| | {kbd}`⎋` | Escape | | ||
| ::: | ||
|
|
||
| :::{tab-item} Markdown | ||
| ```markdown | ||
| | Symbol | Key Description | | ||
| |-----------|------------------| | ||
| | {kbd}`⌘` | Command (Mac) | | ||
reakaleek marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| | {kbd}`⌥` | Option/Alt (Mac) | | ||
| | {kbd}`⇧` | Shift | | ||
| | {kbd}`⌃` | Control | | ||
| | {kbd}`↩` | Return/Enter | | ||
| | {kbd}`⌫` | Delete/Backspace | | ||
| | {kbd}`⇥` | Tab | | ||
| | {kbd}`↑` | Up Arrow | | ||
| | {kbd}`↓` | Down Arrow | | ||
| | {kbd}`←` | Left Arrow | | ||
| | {kbd}`→` | Right Arrow | | ||
| | {kbd}`⎋` | Escape | | ||
| ``` | ||
| ::: | ||
|
|
||
| :::: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @layer components { | ||
| kbd { | ||
| @apply bg-grey-20 text-grey-100 border-grey-50 shadow-grey-50 relative top-[-2px] inline-block min-w-[18px] cursor-default rounded-sm border px-1 pt-[3px] pb-[2px] text-center align-middle font-mono text-sm leading-none capitalize shadow-[0_2px_0_1px]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using System; | ||
| using Markdig.Parsers; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Roles.Kbd; | ||
|
|
||
| public class KbdParser : RoleParser<KbdRole> | ||
| { | ||
|
|
||
| protected override KbdRole CreateRole(string role, string content, InlineProcessor parserContext) => | ||
| new(role, content); | ||
|
|
||
| protected override bool Matches(ReadOnlySpan<char> role) => role is "{kbd}"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using System.Diagnostics; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Roles.Kbd; | ||
|
|
||
| [DebuggerDisplay("{GetType().Name} Line: {Line}, Role: {Role}, Content: {Content}")] | ||
| public class KbdRole(string role, string content) : RoleLeaf(role, content) | ||
| { | ||
| public string KeyboardText { get; } = content; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Licensed to Elasticsearch B.V under one or more agreements. | ||
| // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
| // See the LICENSE file in the project root for more information | ||
|
|
||
| using Markdig; | ||
| using Markdig.Parsers.Inlines; | ||
| using Markdig.Renderers; | ||
| using Markdig.Renderers.Html; | ||
| using Markdig.Renderers.Html.Inlines; | ||
|
|
||
| namespace Elastic.Markdown.Myst.Roles.Kbd; | ||
|
|
||
| public class KbdRoleHtmlRenderer : HtmlObjectRenderer<KbdRole> | ||
| { | ||
| protected override void Write(HtmlRenderer renderer, KbdRole role) | ||
| { | ||
| _ = renderer.Write("<kbd>"); | ||
| _ = renderer.Write(role.KeyboardText); | ||
| _ = renderer.Write("</kbd>"); | ||
| } | ||
| } | ||
|
|
||
| public static class InlineKbdExtensions | ||
| { | ||
| public static MarkdownPipelineBuilder UseInlineKbd(this MarkdownPipelineBuilder pipeline) | ||
| { | ||
| pipeline.Extensions.AddIfNotAlready<InlineKbdExtension>(); | ||
| return pipeline; | ||
| } | ||
| } | ||
|
|
||
| public class InlineKbdExtension : IMarkdownExtension | ||
| { | ||
| public void Setup(MarkdownPipelineBuilder pipeline) => _ = pipeline.InlineParsers.InsertBefore<CodeInlineParser>(new KbdParser()); | ||
|
|
||
| public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) => | ||
| renderer.ObjectRenderers.InsertBefore<CodeInlineRenderer>(new KbdRoleHtmlRenderer()); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.