Skip to content

Commit 9a33adc

Browse files
jolheisertechknowlogick
authored andcommitted
Allow kbd tags (#9245)
* Allow kbd tags Signed-off-by: jolheiser <[email protected]> * Add test Signed-off-by: jolheiser <[email protected]>
1 parent bdbdd66 commit 9a33adc

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

modules/markup/sanitizer.go

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func ReplaceSanitizer() {
4747

4848
// Allow keyword markup
4949
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^` + keywordClass + `$`)).OnElements("span")
50+
51+
// Allow <kbd> tags for keyboard shortcut styling
52+
sanitizer.policy.AllowElements("kbd")
5053
}
5154

5255
// Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist.

modules/markup/sanitizer_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func Test_Sanitizer(t *testing.T) {
3535
<code class="language-lol&#32;ui&#32;container&#32;input&#32;massive&#32;basic&#32;segment">Hello there! Something has gone wrong, we are working on it.</code>
3636
<code class="language-lol&#32;ui&#32;container&#32;input&#32;huge&#32;basic&#32;segment">In the meantime, play a game with us at&nbsp;<a href="http://example.com/">example.com</a>.</code>
3737
</code>`, "<code>\n<code>\u00a0</code>\n<img src=\"https://try.gogs.io/img/favicon.png\" width=\"200\" height=\"200\">\n<code>Hello there! Something has gone wrong, we are working on it.</code>\n<code>In the meantime, play a game with us at\u00a0<a href=\"http://example.com/\" rel=\"nofollow\">example.com</a>.</code>\n</code>",
38+
39+
// <kbd> tags
40+
`<kbd>Ctrl + C</kbd>`, `<kbd>Ctrl + C</kbd>`,
3841
}
3942

4043
for i := 0; i < len(testCases); i += 2 {

0 commit comments

Comments
 (0)