texthtml

package
v0.0.0-...-ceae1e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package texthtml formats text files to HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(text []byte, cfg Config) (html []byte)

Format formats text to HTML according to the configuration cfg.

Types

type Config

type Config struct {
	Line       int       // if >= 1, number lines beginning with number Line, with <span class="ln">
	GoComments bool      // mark comments in Go text with <span class="comment">
	Playground bool      // format for playground sample
	Highlight  string    // highlight matches for this regexp with <span class="highlight">
	HL         string    // highlight lines that end with // HL (x/tools/present convention)
	Selection  Selection // mark selected spans with <span class="selection">
	AST        ast.Node  // link uses to declarations, assuming text is formatting of AST
	OldDocs    bool      // emit links to ?m=old docs
}

A Config configures how to format text as HTML.

type Selection

type Selection func() Span

A Selection is an "iterator" function returning a text span. Repeated calls to a selection return consecutive, non-overlapping, non-empty spans, followed by an infinite sequence of empty spans. The first empty span marks the end of the selection.

func Spans

func Spans(spans ...Span) Selection

Spans is a helper function to make a Selection from a slice of spans. Empty spans are discarded.

type Span

type Span struct {
	Start, End int
}

A Span describes a text span [start, end). The zero value of a Span is an empty span.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL