github.com/vnforks/kid@v5.11.1+incompatible/utils/markdown/block_quote.go (about)

     1  // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package markdown
     5  
     6  type BlockQuote struct {
     7  	blockBase
     8  	markdown string
     9  
    10  	Children []Block
    11  }
    12  
    13  func (b *BlockQuote) Continuation(indentation int, r Range) *continuation {
    14  	if indentation > 3 {
    15  		return nil
    16  	}
    17  	s := b.markdown[r.Position:r.End]
    18  	if s == "" || s[0] != '>' {
    19  		return nil
    20  	}
    21  	remaining := Range{r.Position + 1, r.End}
    22  	indentation, indentationBytes := countIndentation(b.markdown, remaining)
    23  	if indentation > 0 {
    24  		indentation--
    25  	}
    26  	return &continuation{
    27  		Indentation: indentation,
    28  		Remaining:   Range{remaining.Position + indentationBytes, remaining.End},
    29  	}
    30  }
    31  
    32  func (b *BlockQuote) AddChild(openBlocks []Block) []Block {
    33  	b.Children = append(b.Children, openBlocks[0])
    34  	return openBlocks
    35  }
    36  
    37  func blockQuoteStart(markdown string, indent int, r Range, matchedBlocks, unmatchedBlocks []Block) []Block {
    38  	if indent > 3 {
    39  		return nil
    40  	}
    41  	s := markdown[r.Position:r.End]
    42  	if s == "" || s[0] != '>' {
    43  		return nil
    44  	}
    45  
    46  	block := &BlockQuote{
    47  		markdown: markdown,
    48  	}
    49  	r.Position++
    50  	if len(s) > 1 && s[1] == ' ' {
    51  		r.Position++
    52  	}
    53  
    54  	indent, bytes := countIndentation(markdown, r)
    55  
    56  	ret := []Block{block}
    57  	if descendants := blockStartOrParagraph(markdown, indent, Range{r.Position + bytes, r.End}, nil, nil); descendants != nil {
    58  		block.Children = append(block.Children, descendants[0])
    59  		ret = append(ret, descendants...)
    60  	}
    61  	return ret
    62  }