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

Add blockquote support for HTML and MD2 #138

Merged
merged 1 commit into from
Feb 7, 2024
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
39 changes: 25 additions & 14 deletions parse_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type ParseMode interface {
// Preformated text
Pre(v ...string) string

// Blockquote
Blockquote(v ...string) string

// Escape
Escape(v string) string
}
Expand All @@ -61,13 +64,14 @@ var (
name: "HTML",
separator: " ",

bold: parseModeTag{"<b>", "</b>"},
italic: parseModeTag{"<i>", "</i>"},
underline: parseModeTag{"<u>", "</u>"},
strike: parseModeTag{"<s>", "</s>"},
spoiler: parseModeTag{"<tg-spoiler>", "</tg-spoiler>"},
code: parseModeTag{"<code>", "</code>"},
pre: parseModeTag{"<pre>", "</pre>"},
bold: parseModeTag{"<b>", "</b>"},
italic: parseModeTag{"<i>", "</i>"},
underline: parseModeTag{"<u>", "</u>"},
strike: parseModeTag{"<s>", "</s>"},
spoiler: parseModeTag{"<tg-spoiler>", "</tg-spoiler>"},
code: parseModeTag{"<code>", "</code>"},
pre: parseModeTag{"<pre>", "</pre>"},
blockquote: parseModeTag{"<blockquote>", "</blockquote>"},

linkTemplate: `<a href="{url}">{title}</a>`,

Expand Down Expand Up @@ -95,13 +99,14 @@ var (
name: "MarkdownV2",
separator: " ",

bold: parseModeTag{"*", "*"},
italic: parseModeTag{"_", "_"},
underline: parseModeTag{"__", "__"},
strike: parseModeTag{"~", "~"},
spoiler: parseModeTag{"||", "||"},
code: parseModeTag{"`", "`"},
pre: parseModeTag{"```", "```"},
bold: parseModeTag{"*", "*"},
italic: parseModeTag{"_", "_"},
underline: parseModeTag{"__", "__"},
strike: parseModeTag{"~", "~"},
spoiler: parseModeTag{"||", "||"},
code: parseModeTag{"`", "`"},
pre: parseModeTag{"```", "```"},
blockquote: parseModeTag{">", ""},

linkTemplate: `[{title}]({url})`,

Expand All @@ -121,6 +126,7 @@ type parseMode struct {
spoiler parseModeTag
code parseModeTag
pre parseModeTag
blockquote parseModeTag
linkTemplate string

escape func(string) string
Expand Down Expand Up @@ -199,6 +205,11 @@ func (pm parseMode) Pre(v ...string) string {
return pm.pre.wrap(strings.Join(v, pm.separator))
}

// Blockquote
func (pm parseMode) Blockquote(v ...string) string {
return pm.blockquote.wrap(strings.Join(v, pm.separator))
}

func (pm parseMode) Escape(v string) string {
return pm.escape(v)
}
2 changes: 2 additions & 0 deletions parse_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestParseModeHTML(t *testing.T) {
assert.Equal(t, "<code>Hello World</code>", HTML.Code("Hello World"))
assert.Equal(t, "<pre>Hello World</pre>", HTML.Pre("Hello World"))
assert.Equal(t, "<b>Hello, World</b>", HTML.Sep(", ").Bold("Hello", "World"))
assert.Equal(t, "<blockquote>Hello, World</blockquote>", HTML.Sep(", ").Blockquote("Hello", "World"))
assert.Equal(t, "Me &amp; You", HTML.Escape("Me & You"))
}

Expand Down Expand Up @@ -55,6 +56,7 @@ func TestParseModeMarkdownV2(t *testing.T) {
assert.Equal(t, "[Hello World](https://telegram.org)", MD2.Link("Hello World", "https://telegram.org"))
assert.Equal(t, "`Hello World`", MD2.Code("Hello World"))
assert.Equal(t, "```Hello World```", MD2.Pre("Hello World"))
assert.Equal(t, ">Hello World", MD2.Blockquote("Hello World"))
assert.Equal(t, "*Hello, World*", MD2.Sep(", ").Bold("Hello", "World"))

assert.Equal(t, "\\[\\*go\\_tg\\*\\]", MD2.Escape("[*go_tg*]"))
Expand Down
Loading