gotools/godoc/format.go

type Segment

func (seg *Segment) isEmpty() bool {}

type Selection

type LinkWriter

type SegmentWriter

// FormatSelections takes a text and writes it to w using link and segment
// writers lw and sw as follows: lw is invoked for consecutive segment starts
// and ends as specified through the links selection, and sw is invoked for
// consecutive segments of text overlapped by the same selections as specified
// by selections. The link writer lw may be nil, in which case the links
// Selection is ignored.
func FormatSelections(w io.Writer, text []byte, lw LinkWriter, links Selection, sw SegmentWriter, selections ...Selection) {}

type merger

const infinity

func newMerger(selections []Selection) *merger {}

// next returns the next segment change: index specifies the Selection
// to which the segment belongs, offs is the segment start or end offset
// as determined by the start value. If there are no more segment changes,
// next returns an index value < 0.
func (m *merger) next() (index, offs int, start bool) {}

// lineSelection returns the line segments for text as a Selection.
func lineSelection(text []byte) Selection {}

// tokenSelection returns, as a selection, the sequence of
// consecutive occurrences of token sel in the Go src text.
func tokenSelection(src []byte, sel token.Token) Selection {}

// makeSelection is a helper function to make a Selection from a slice of pairs.
// Pairs describing empty segments are ignored.
func makeSelection(matches [][]int) Selection {}

// regexpSelection computes the Selection for the regular expression expr in text.
func regexpSelection(text []byte, expr string) Selection {}

var selRx

// RangeSelection computes the Selection for a text range described
// by the argument str; the range description must match the selRx
// regular expression.
func RangeSelection(str string) Selection {}

var startTags

var endTag

func selectionTag(w io.Writer, text []byte, selections int) {}

// FormatText HTML-escapes text and writes it to w.
// Consecutive text segments are wrapped in HTML spans (with tags as
// defined by startTags and endTag) as follows:
//
//   - if line >= 0, line number (ln) spans are inserted before each line,
//     starting with the value of line
//   - if the text is Go source, comments get the "comment" span class
//   - each occurrence of the regular expression pattern gets the "highlight"
//     span class
//   - text segments covered by selection get the "selection" span class
//
// Comments, highlights, and selections may overlap arbitrarily; the respective
// HTML span classes are specified in the startTags variable.
func FormatText(w io.Writer, text []byte, line int, goSource bool, pattern string, selection Selection) {}