Render keybinding cheatsheet as markdown table

We're going to be adding tooltips to the cheatsheet to better explain what each actions
does. As such, we're switching to a table format rather than a list.

I'm also changing how the keys are represented, using a markdown approach rather than
an html approach
This commit is contained in:
Jesse Duffield 2024-01-04 13:17:45 +11:00
parent cb1b13e95e
commit 0aa6109d4d
9 changed files with 2336 additions and 2333 deletions

View file

@ -14,7 +14,6 @@ import (
"fmt"
"log"
"os"
"strings"
"github.com/jesseduffield/generics/maps"
"github.com/jesseduffield/lazycore/pkg/utils"
@ -191,11 +190,11 @@ func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection)
for _, section := range bindingSections {
content += formatTitle(section.title)
content += "<pre>\n"
content += "| Key | Action | Info |\n"
content += "|-----|--------|-------------|\n"
for _, binding := range section.bindings {
content += formatBinding(binding)
}
content += "</pre>\n"
}
return content
@ -206,19 +205,15 @@ func formatTitle(title string) string {
}
func formatBinding(binding *types.Binding) string {
result := fmt.Sprintf(" <kbd>%s</kbd>: %s", escapeAngleBrackets(keybindings.LabelFromKey(binding.Key)), binding.Description)
action := keybindings.LabelFromKey(binding.Key)
description := binding.Description
if binding.Alternative != "" {
result += fmt.Sprintf(" (%s)", binding.Alternative)
action += fmt.Sprintf(" (%s)", binding.Alternative)
}
result += "\n"
return result
}
func escapeAngleBrackets(str string) string {
result := strings.ReplaceAll(str, ">", "&gt;")
result = strings.ReplaceAll(result, "<", "&lt;")
return result
// Use backticks for keyboard keys. Two backticks are needed with an inner space
// to escape a key that is itself a backtick.
return fmt.Sprintf("| `` %s `` | %s | %s |\n", action, description, binding.Tooltip)
}
func italicize(str string) string {