1// Copyright 2021 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package markdown 6 7import ( 8 "bytes" 9) 10 11type Quote struct { 12 Position 13 Blocks []Block 14} 15 16func (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 24func (b *Quote) printMarkdown(buf *bytes.Buffer, s mdState) { 25 s.prefix += "> " 26 printMarkdownBlocks(b.Blocks, buf, s) 27} 28 29func 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 39type quoteBuilder struct{} 40 41func 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 49func (b *quoteBuilder) extend(p *parseState, s line) (line, bool) { 50 return trimQuote(s) 51} 52 53func (b *quoteBuilder) build(p buildState) Block { 54 return &Quote{p.pos(), p.blocks()} 55} 56