github.com/anthonyme00/gomarkdoc@v1.0.0/lang/doc.go (about)

     1  package lang
     2  
     3  // Doc provides access to the documentation comment contents for a package or
     4  // symbol in a structured form.
     5  type Doc struct {
     6  	cfg    *Config
     7  	blocks []*Block
     8  }
     9  
    10  // NewDoc initializes a Doc struct from the provided raw documentation text and
    11  // with headers rendered by default at the heading level provided. Documentation
    12  // is separated into block level elements using the standard rules from golang's
    13  // documentation conventions.
    14  func NewDoc(cfg *Config, text string) *Doc {
    15  	// Replace CRLF with LF
    16  	rawText := normalizeDoc(text)
    17  
    18  	parsed := cfg.Pkg.Parser().Parse(rawText)
    19  
    20  	blocks := ParseBlocks(cfg, parsed.Content, false)
    21  
    22  	return &Doc{cfg, blocks}
    23  }
    24  
    25  // Level provides the default level that headers within the documentation should
    26  // be rendered
    27  func (d *Doc) Level() int {
    28  	return d.cfg.Level
    29  }
    30  
    31  // Blocks holds the list of block elements that makes up the documentation
    32  // contents.
    33  func (d *Doc) Blocks() []*Block {
    34  	return d.blocks
    35  }