forked from getfider/fider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_renderer.go
194 lines (154 loc) · 5.5 KB
/
simple_renderer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package markdown
import (
"bytes"
"github.com/russross/blackfriday"
)
// Ensure we implement the Blackfriday Markdown Renderer interface
var _ blackfriday.Renderer = (*renderer)(nil)
// renderer renders Markdown to plain-text meant for listings and excerpts,
// and implements the blackfriday.Renderer interface.
//
// Many of the methods are stubs with no output to prevent output of HTML markup.
type proxy struct {
renderer blackfriday.Renderer
}
// SimpleRenderer renders most HTML tags, except title
func SimpleRenderer(flags int) proxy {
return proxy{
renderer: blackfriday.HtmlRenderer(flags, "", ""),
}
}
// Blocklevel callbacks
// BlockCode is the code tag callback.
func (p proxy) BlockCode(out *bytes.Buffer, text []byte, land string) {
p.renderer.BlockCode(out, text, land)
}
// BlockQuote is the quote tag callback.
func (p proxy) BlockQuote(out *bytes.Buffer, text []byte) {
p.renderer.BlockQuote(out, text)
}
// BlockHtml is the HTML tag callback.
func (p proxy) BlockHtml(out *bytes.Buffer, text []byte) {
p.renderer.BlockHtml(out, text)
}
// Header is the header tag callback.
func (p proxy) Header(out *bytes.Buffer, text func() bool, level int, id string) {
p.Paragraph(out, text)
}
// HRule is the horizontal rule tag callback.
func (p proxy) HRule(out *bytes.Buffer) {
p.renderer.HRule(out)
}
// List is the list tag callback.
func (p proxy) List(out *bytes.Buffer, text func() bool, flags int) {
p.renderer.List(out, text, flags)
}
// ListItem is the list item tag callback.
func (p proxy) ListItem(out *bytes.Buffer, text []byte, flags int) {
p.renderer.ListItem(out, text, flags)
}
// Paragraph is the paragraph tag callback. This renders simple paragraph text
// into plain text, such that summaries can be easily generated.
func (p proxy) Paragraph(out *bytes.Buffer, text func() bool) {
p.renderer.Paragraph(out, text)
}
// Table is the table tag callback.
func (p proxy) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {
p.renderer.Table(out, header, body, columnData)
}
// TableRow is the table row tag callback.
func (p proxy) TableRow(out *bytes.Buffer, text []byte) {
p.renderer.TableRow(out, text)
}
// TableHeaderCell is the table header cell tag callback.
func (p proxy) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) {
p.renderer.TableHeaderCell(out, text, flags)
}
// TableCell is the table cell tag callback.
func (p proxy) TableCell(out *bytes.Buffer, text []byte, flags int) {
p.renderer.TableCell(out, text, flags)
}
// Footnotes is the foot notes tag callback.
func (p proxy) Footnotes(out *bytes.Buffer, text func() bool) {
p.renderer.Footnotes(out, text)
}
// FootnoteItem is the footnote item tag callback.
func (p proxy) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) {
p.renderer.FootnoteItem(out, name, text, flags)
}
// TitleBlock is the title tag callback.
func (p proxy) TitleBlock(out *bytes.Buffer, text []byte) {
p.renderer.TitleBlock(out, text)
}
// Spanlevel callbacks
// AutoLink is the autolink tag callback.
func (p proxy) AutoLink(out *bytes.Buffer, link []byte, kind int) {
p.renderer.AutoLink(out, link, kind)
}
// CodeSpan is the code span tag callback. Outputs a simple Markdown version
// of the code span.
func (p proxy) CodeSpan(out *bytes.Buffer, text []byte) {
p.renderer.CodeSpan(out, text)
}
// DoubleEmphasis is the double emphasis tag callback. Outputs a simple
// plain-text version of the input.
func (p proxy) DoubleEmphasis(out *bytes.Buffer, text []byte) {
p.renderer.DoubleEmphasis(out, text)
}
// Emphasis is the emphasis tag callback. Outputs a simple plain-text
// version of the input.
func (p proxy) Emphasis(out *bytes.Buffer, text []byte) {
p.renderer.Emphasis(out, text)
}
// Image is the image tag callback.
func (p proxy) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) {
p.renderer.Image(out, link, title, alt)
}
// LineBreak is the line break tag callback.
func (p proxy) LineBreak(out *bytes.Buffer) {
p.renderer.LineBreak(out)
}
// Link is the link tag callback. Outputs a simple plain-text version
// of the input.
func (p proxy) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) {
p.renderer.Link(out, link, title, content)
}
// RawHtmlTag is the raw HTML tag callback.
func (p proxy) RawHtmlTag(out *bytes.Buffer, tag []byte) {
p.renderer.RawHtmlTag(out, tag)
}
// TripleEmphasis is the triple emphasis tag callback. Outputs a simple plain-text
// version of the input.
func (p proxy) TripleEmphasis(out *bytes.Buffer, text []byte) {
p.renderer.TripleEmphasis(out, text)
}
// StrikeThrough is the strikethrough tag callback.
func (p proxy) StrikeThrough(out *bytes.Buffer, text []byte) {
p.renderer.StrikeThrough(out, text)
}
// FootnoteRef is the footnote ref tag callback.
func (p proxy) FootnoteRef(out *bytes.Buffer, ref []byte, id int) {
p.renderer.FootnoteRef(out, ref, id)
}
// Lowlevel callbacks
// Entity callback. Outputs a simple plain-text version of the input.
func (p proxy) Entity(out *bytes.Buffer, entity []byte) {
p.renderer.Entity(out, entity)
}
// NormalText callback. Outputs a simple plain-text version of the input.
func (p proxy) NormalText(out *bytes.Buffer, text []byte) {
p.renderer.NormalText(out, text)
}
// Header and footer
// DocumentHeader callback.
func (p proxy) DocumentHeader(out *bytes.Buffer) {
p.renderer.DocumentHeader(out)
}
// DocumentFooter callback.
func (p proxy) DocumentFooter(out *bytes.Buffer) {
p.renderer.DocumentFooter(out)
}
// GetFlags returns zero.
func (p proxy) GetFlags() int {
return p.renderer.GetFlags()
}