Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions pkg/app/passage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ func escapeMarkdownV2(s string) string {
// Note: '^' is not in this list. Let's assume it doesn't need escaping.
// The logic should be to escape these characters *only* when they are not part of a formatting tag.
// However, since we are processing raw text nodes, any special character should be escaped.
r := strings.NewReplacer(
"_", `\_`, "*", `\*`, "[", `\[`, "]", `\]`, "(", `\(`, ")", `\)`,
"~", `\~`, "`", "\\`", ">", `\>`, "#", `\#`, "+", `\+`, "-", `\-`,
"=", `\=`, "|", `\|`, "{", `\{`, "}", `\}`, ".", `\.`, "!", `\!`,
`\`, `\\`,
)
return r.Replace(s)
var sb strings.Builder
for _, r := range s {
switch r {
case '_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!', '\\':
sb.WriteRune('\\')
}
sb.WriteRune(r)
}
return sb.String()
}

// Helper functions for parsing
Expand Down
8 changes: 8 additions & 0 deletions pkg/app/passage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ func TestParsePassageFromHtml(t *testing.T) {
t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected)
}
})

t.Run("Dot escaping", func(t *testing.T) {
html := `heaven.`
expected := `heaven\.`
if got := ParsePassageFromHtml(html); got != expected {
t.Errorf("ParsePassageFromHtml() = %v, want %v", got, expected)
}
})
}

func TestCheckBibleReference(t *testing.T) {
Expand Down
Loading