+
+func TestEscapeTags(t *testing.T) {
+ testCases := []struct {
+ name string
+ markdown string
+ escaped string
+ }{
+ {
+ name: "tag in prose shows as text",
+ markdown: "Use a <details> tag for the rest.",
+ escaped: `Use a \<details> tag for the rest.`,
+ },
+ {
+ name: "tag in inline code stays as written",
+ markdown: "Use `<details>` and `` a<b ``, not <b>.",
+ escaped: "Use `<details>` and `` a<b ``, not \\<b>.",
+ },
+ {
+ name: "tag in a code block stays as written",
+ markdown: "<p>\n\n```html\n<details>\n```\n\n<p>",
+ escaped: "\\<p>\n\n```html\n<details>\n```\n\n\\<p>",
+ },
+ {
+ name: "code block that does not close stays as written",
+ markdown: "a <b>\n```\n<details>",
+ escaped: "a \\<b>\n```\n<details>",
+ },
+ {
+ name: "tag in a table cell shows as text",
+ markdown: "| Tag | Use |\n|-----|-----|\n| <br> | `<br>` |",
+ escaped: "| Tag | Use |\n|-----|-----|\n| \\<br> | `<br>` |",
+ },
+ {
+ name: "autolink shows as text",
+ markdown: "See <https://example.com>.",
+ escaped: `See \<https://example.com>.`,
+ },
+ {
+ name: "backtick run that opens no code stays as text",
+ markdown: "a ``b` <c>",
+ escaped: "a ``b` \\<c>",
+ },
+ {
+ name: "escaped bracket stays as written",
+ markdown: `a \<b> and \\<c>`,
+ escaped: `a \<b> and \\\<c>`,
+ },
+ {
+ name: "dollar, pipe, and equals signs stay as written",
+ markdown: "$5 or $10, a || b, ==c==",
+ escaped: "$5 or $10, a || b, ==c==",
+ },
+ }
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ require.Equal(t, tc.escaped, telegramEscapeTags(tc.markdown))
+ })
+ }
+}