-
Notifications
You must be signed in to change notification settings - Fork 18k
/
Copy pathquote.go
55 lines (45 loc) · 1.04 KB
/
quote.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
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package markdown
import (
"bytes"
)
type Quote struct {
Position
Blocks []Block
}
func (b *Quote) PrintHTML(buf *bytes.Buffer) {
buf.WriteString("<blockquote>\n")
for _, c := range b.Blocks {
c.PrintHTML(buf)
}
buf.WriteString("</blockquote>\n")
}
func (b *Quote) printMarkdown(buf *bytes.Buffer, s mdState) {
s.prefix += "> "
printMarkdownBlocks(b.Blocks, buf, s)
}
func trimQuote(s line) (line, bool) {
t := s
t.trimSpace(0, 3, false)
if !t.trim('>') {
return s, false
}
t.trimSpace(0, 1, true)
return t, true
}
type quoteBuilder struct{}
func newQuote(p *parseState, s line) (line, bool) {
if line, ok := trimQuote(s); ok {
p.addBlock(new(quoteBuilder))
return line, true
}
return s, false
}
func (b *quoteBuilder) extend(p *parseState, s line) (line, bool) {
return trimQuote(s)
}
func (b *quoteBuilder) build(p buildState) Block {
return &Quote{p.pos(), p.blocks()}
}