github.com/huner2/gomarkdoc@v0.3.6/lang/block.go (about) 1 package lang 2 3 type ( 4 // Block defines a single block element (e.g. paragraph, code block) in the 5 // documentation for a symbol or package. 6 Block struct { 7 cfg *Config 8 kind BlockKind 9 text string 10 } 11 12 // BlockKind identifies the type of block element represented by the 13 // corresponding Block. 14 BlockKind string 15 ) 16 17 const ( 18 // ParagraphBlock defines a block that represents a paragraph of text. 19 ParagraphBlock BlockKind = "paragraph" 20 21 // CodeBlock defines a block that represents a section of code. 22 CodeBlock BlockKind = "code" 23 24 // HeaderBlock defines a block that represents a section header. 25 HeaderBlock BlockKind = "header" 26 ) 27 28 // NewBlock creates a new block element of the provided kind and with the given 29 // text contents. 30 func NewBlock(cfg *Config, kind BlockKind, text string) *Block { 31 return &Block{cfg, kind, text} 32 } 33 34 // Level provides the default level that a block of kind HeaderBlock will render 35 // at in the output. The level is not used for other block types. 36 func (b *Block) Level() int { 37 return b.cfg.Level 38 } 39 40 // Kind provides the kind of data that this block's text should be interpreted 41 // as. 42 func (b *Block) Kind() BlockKind { 43 return b.kind 44 } 45 46 // Text provides the raw text of the block's contents. The text is pre-scrubbed 47 // and sanitized as determined by the block's Kind(), but it is not wrapped in 48 // any special constructs for rendering purposes (such as markdown code blocks). 49 func (b *Block) Text() string { 50 return b.text 51 }