From 3eed99716105481dffddc9a74db0d444a9c469a2 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 21 May 2023 11:13:02 +1000 Subject: Update cheatsheet Now that we're using the angle-bracket syntax everywhere for consistency, we need to escape the angle brackets in the markdown of the cheatsheets. --- pkg/cheatsheet/generate.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'pkg/cheatsheet') diff --git a/pkg/cheatsheet/generate.go b/pkg/cheatsheet/generate.go index ee2538c1f..ec2c84dbd 100644 --- a/pkg/cheatsheet/generate.go +++ b/pkg/cheatsheet/generate.go @@ -12,6 +12,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/jesseduffield/generics/maps" "github.com/jesseduffield/generics/slices" @@ -183,6 +184,8 @@ func getHeader(binding *types.Binding, tr *i18n.TranslationSet) header { func formatSections(tr *i18n.TranslationSet, bindingSections []*bindingSection) string { content := fmt.Sprintf("# Lazygit %s\n", tr.Keybindings) + content += fmt.Sprintf("\n%s\n", italicize(tr.KeybindingsLegend)) + for _, section := range bindingSections { content += formatTitle(section.title) content += "
\n"
@@ -200,13 +203,21 @@ func formatTitle(title string) string {
 }
 
 func formatBinding(binding *types.Binding) string {
+	result := fmt.Sprintf("  %s: %s", escapeAngleBrackets(keybindings.LabelFromKey(binding.Key)), binding.Description)
 	if binding.Alternative != "" {
-		return fmt.Sprintf(
-			"  %s: %s (%s)\n",
-			keybindings.LabelFromKey(binding.Key),
-			binding.Description,
-			binding.Alternative,
-		)
+		result += fmt.Sprintf(" (%s)", binding.Alternative)
 	}
-	return fmt.Sprintf("  %s: %s\n", keybindings.LabelFromKey(binding.Key), binding.Description)
+	result += "\n"
+
+	return result
+}
+
+func escapeAngleBrackets(str string) string {
+	result := strings.ReplaceAll(str, ">", ">")
+	result = strings.ReplaceAll(result, "<", "<")
+	return result
+}
+
+func italicize(str string) string {
+	return fmt.Sprintf("_%s_", str)
 }
-- 
cgit v1.2.3