github.com/huner2/gomarkdoc@v0.3.6/lang/value.go (about)

     1  package lang
     2  
     3  import (
     4  	"go/doc"
     5  )
     6  
     7  // Value holds documentation for a var or const declaration within a package.
     8  type Value struct {
     9  	cfg *Config
    10  	doc *doc.Value
    11  }
    12  
    13  // NewValue creates a new Value from the raw const or var documentation and the
    14  // token.FileSet of files for the containing package.
    15  func NewValue(cfg *Config, doc *doc.Value) *Value {
    16  	return &Value{cfg, doc}
    17  }
    18  
    19  // Level provides the default level that headers for the value should be
    20  // rendered.
    21  func (v *Value) Level() int {
    22  	return v.cfg.Level
    23  }
    24  
    25  // Location returns a representation of the node's location in a file within a
    26  // repository.
    27  func (v *Value) Location() Location {
    28  	return NewLocation(v.cfg, v.doc.Decl)
    29  }
    30  
    31  // Summary provides the one-sentence summary of the value's documentation
    32  // comment.
    33  func (v *Value) Summary() string {
    34  	return extractSummary(v.doc.Doc)
    35  }
    36  
    37  // Doc provides the structured contents of the documentation comment for the
    38  // example.
    39  func (v *Value) Doc() *Doc {
    40  	return NewDoc(v.cfg.Inc(1), v.doc.Doc)
    41  }
    42  
    43  // Decl provides the raw text representation of the code for declaring the const
    44  // or var.
    45  func (v *Value) Decl() (string, error) {
    46  	return printNode(v.doc.Decl, v.cfg.FileSet)
    47  }