Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

Viewing file on branch master

1package btelegram
2
3import (
4 "bytes"
5
6 "github.com/russross/blackfriday"
7)
8
9type customHTML struct {
10 blackfriday.Renderer
11}
12
13func (options *customHTML) Paragraph(out *bytes.Buffer, text func() bool) {
14 marker := out.Len()
15
16 if !text() {
17 out.Truncate(marker)
18 return
19 }
20 out.WriteString("\n")
21}
22
23func (options *customHTML) BlockCode(out *bytes.Buffer, text []byte, lang string) {
24 out.WriteString("<pre>")
25
26 out.WriteString(string(text))
27 out.WriteString("</pre>\n")
28}
29
30func (options *customHTML) CodeSpan(out *bytes.Buffer, text []byte) {
31 out.WriteString("<code>")
32 out.WriteString(string(text))
33 out.WriteString("</code>")
34}
35
36func (options *customHTML) Header(out *bytes.Buffer, text func() bool, level int, id string) {
37 options.Paragraph(out, text)
38}
39
40func (options *customHTML) HRule(out *bytes.Buffer) {
41 out.WriteByte('\n') //nolint:errcheck
42}
43
44func (options *customHTML) BlockQuote(out *bytes.Buffer, text []byte) {
45 out.WriteString("> ")
46 out.Write(text)
47 out.WriteByte('\n')
48}
49
50func (options *customHTML) LineBreak(out *bytes.Buffer) {
51 out.WriteByte('\n')
52}
53
54func (options *customHTML) List(out *bytes.Buffer, text func() bool, flags int) {
55 options.Paragraph(out, text)
56}
57
58func (options *customHTML) ListItem(out *bytes.Buffer, text []byte, flags int) {
59 out.WriteString("- ")
60 out.Write(text)
61 out.WriteByte('\n')
62}
63
64func makeHTML(input string) string {
65 return string(blackfriday.Markdown([]byte(input),
66 &customHTML{blackfriday.HtmlRenderer(blackfriday.HTML_USE_XHTML|blackfriday.HTML_SKIP_IMAGES, "", "")},
67 blackfriday.EXTENSION_NO_INTRA_EMPHASIS|
68 blackfriday.EXTENSION_FENCED_CODE|
69 blackfriday.EXTENSION_AUTOLINK|
70 blackfriday.EXTENSION_SPACE_HEADERS|
71 blackfriday.EXTENSION_HEADER_IDS|
72 blackfriday.EXTENSION_BACKSLASH_LINE_BREAK|
73 blackfriday.EXTENSION_DEFINITION_LISTS))
74}
75