Skip to content
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

Feature request: Fancy styling of kbd tag #9242

Closed
2 of 7 tasks
FWDekker opened this issue Dec 3, 2019 · 3 comments · Fixed by #9245
Closed
2 of 7 tasks

Feature request: Fancy styling of kbd tag #9242

FWDekker opened this issue Dec 3, 2019 · 3 comments · Fixed by #9245
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.

Comments

@FWDekker
Copy link
Contributor

FWDekker commented Dec 3, 2019

  • Gitea version (or commit ref): 1.10.0
  • Git version: 2.23.0
  • Operating system: FreeBSD
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
    • Not relevant
  • Log gist: N/A

Description

The <kbd> tag can be used to display a keyboard shortcut in HTML/Markdown. While it is similar to using backticks (`) to display code, some websites style it to appear like an actual button. For example, on GitHub the input <kbd>Ctrl + C</kbd> is rendered as Ctrl + C. I think this representation clearly indicates to readers that it's a keyboard shortcut rather than code.

To give an example of a real-world usage of <kbd>, consider the README of this repository of mine where I explain which shortcuts my program accepts.

I think Gitea should style <kbd> similar to how GitHub styles it, or should at the very least apply a monospace font to it.

Screenshots

The screenshots below show how the following snippet of markdown is rendered differently by GitHub than by Gitea.

Input

<kbd>Ctrl + C</kbd> vs `Ctrl + C`

Output (GitHub)

Rendering of above snipper by GitHub

Output (Gitea)

Rendering of above snippet by Gitea

@lunny lunny added the type/proposal The new feature has not been accepted yet but needs to be discussed first. label Dec 3, 2019
@FWDekker
Copy link
Contributor Author

FWDekker commented Dec 3, 2019

Looking at the Markdown stylesheet, it looks like the styling is already inplace. The issue appears to be that the Markdown parser replaces the <kbd> tag with a <p> tag. Manually replacing the <p> tag with a <kbd> tag using inspect element will actually apply the expected styling. I have absolutely 0 experience with Go so I have no idea how to go about fixing the parser.

@axifive
Copy link
Member

axifive commented Dec 3, 2019

@FWDekker Gitea use Blackfriday as markdown processor and it looks like that blackfriday can't process <kbd> tags

@guillep2k
Copy link
Member

It's probably a setting in the sanitizer:

func ReplaceSanitizer() {
sanitizer.policy = bluemonday.UGCPolicy()
// We only want to allow HighlightJS specific classes for code blocks
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^language-\w+$`)).OnElements("code")
// Checkboxes
sanitizer.policy.AllowAttrs("type").Matching(regexp.MustCompile(`^checkbox$`)).OnElements("input")
sanitizer.policy.AllowAttrs("checked", "disabled").OnElements("input")
// Custom URL-Schemes
sanitizer.policy.AllowURLSchemes(setting.Markdown.CustomURLSchemes...)
// Allow keyword markup
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`^` + keywordClass + `$`)).OnElements("span")
}

@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/proposal The new feature has not been accepted yet but needs to be discussed first.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants