1
2
3
4
5 package markdown
6
7 import (
8 "bytes"
9 )
10
11 type Quote struct {
12 Position
13 Blocks []Block
14 }
15
16 func (b *Quote) PrintHTML(buf *bytes.Buffer) {
17 buf.WriteString("<blockquote>\n")
18 for _, c := range b.Blocks {
19 c.PrintHTML(buf)
20 }
21 buf.WriteString("</blockquote>\n")
22 }
23
24 func (b *Quote) printMarkdown(buf *bytes.Buffer, s mdState) {
25 s.prefix += "> "
26 printMarkdownBlocks(b.Blocks, buf, s)
27 }
28
29 func trimQuote(s line) (line, bool) {
30 t := s
31 t.trimSpace(0, 3, false)
32 if !t.trim('>') {
33 return s, false
34 }
35 t.trimSpace(0, 1, true)
36 return t, true
37 }
38
39 type quoteBuilder struct{}
40
41 func newQuote(p *parseState, s line) (line, bool) {
42 if line, ok := trimQuote(s); ok {
43 p.addBlock(new(quoteBuilder))
44 return line, true
45 }
46 return s, false
47 }
48
49 func (b *quoteBuilder) extend(p *parseState, s line) (line, bool) {
50 return trimQuote(s)
51 }
52
53 func (b *quoteBuilder) build(p buildState) Block {
54 return &Quote{p.pos(), p.blocks()}
55 }
56
View as plain text