html2

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package html2 converts from HTML to arbitrary formats.

Index

Constants

View Source
const (
	// ErrWalkStop indicates no more walking needed.
	ErrWalkStop err = iota + 1
	// ErrWalkSkipChildren indicates that the children of this node should not
	// be walked.
	ErrWalkSkipChildren
)
View Source
const DefaultLineWidth = 80

DefaultLineWidth is the maximum line width by default. It affects linebreaks in blockquotes, and the maximum table width. Use LineWidth() to override.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, n *html.Node, r Renderer) error

Render renders walks n, passing each node to r for rendering.

func RenderToString

func RenderToString(n *html.Node, r Renderer) (string, error)

RenderToString works like Render, but returns a string.

Types

type LettersLower

type LettersLower struct{}

LettersLower is an OLIterator that returns e.g. a., b., c....

func (*LettersLower) New

func (*LettersLower) New() OLSeries

New returns satisfies the OLIterator interface.

type LettersUpper

type LettersUpper struct{}

LettersUpper is an OLIterator that returns e.g. A., B., C....

func (*LettersUpper) New

func (*LettersUpper) New() OLSeries

New returns satisfies the OLIterator interface.

type Numbers

type Numbers struct {
	// contains filtered or unexported fields
}

Numbers is an OLIterator that returns e.g. 1., 2., 3....

func (*Numbers) New

func (*Numbers) New() OLSeries

New returns satisfies the OLIterator interface.

func (*Numbers) Next

func (n *Numbers) Next() string

Next returns the next number in the series.

type OLIterator

type OLIterator interface {
	// New returns a new instance of the OLSeries.
	New() OLSeries
}

OLIterator returns numbered list counters.

type OLSeries

type OLSeries interface {
	// Next returns the next iterator label, including any trailing punctuation
	// such as a period (e.g. "1.", "2."...)
	Next() string
}

OLSeries iterantes over sequential ordered list identifiers.

type Option added in v0.0.4

type Option interface {
	// contains filtered or unexported methods
}

Option represents an option to tweak the behavior of a Renderer.

func LineWidth added in v0.0.4

func LineWidth(width int) Option

LineWidth configures the maximum width for the plain text renderer.

type RenderFunc

type RenderFunc func(Writer, *html.Node, bool) error

RenderFunc allows handling a simple function as a Renderer.

func (RenderFunc) Render

func (rf RenderFunc) Render(w Writer, n *html.Node, entering bool) error

Render satisfies the Renderer interface.

type Renderer

type Renderer interface {
	// Render should render n by writing to w. It is not responsible for walking
	// child nodes, which means that it is perfectly valid for this function to
	// do nothing for certain node types.
	//
	// Render is called twice for each node, first with entering true, before
	// processing any children, then a second time with entering false, after
	// processing all children.
	//
	// As special cases, if ErrWalkStop or ErrWalkSkipChildren values are
	// returned,then walking is stopped (without error), or children of the
	// current node are skipped, respectively.
	//
	// Returning WalkSkipChildren when entering=false will cause a panic.
	Render(w Writer, n *html.Node, entering bool) error
}

Renderer is the interface for a generic HTML renderer.

func RenderPlainText

func RenderPlainText(opts ...Option) (Renderer, error)

RenderPlainText returns a renderer that returns plain text output.

type RomanLower

type RomanLower struct{}

RomanLower is an OLIterator that returns e.g. i., ii., iii....

func (*RomanLower) New

func (*RomanLower) New() OLSeries

New returns satisfies the OLIterator interface.

type RomanUpper

type RomanUpper struct{}

RomanUpper is an OLIterator that returns e.g. I., II., III....

func (*RomanUpper) New

func (*RomanUpper) New() OLSeries

New returns satisfies the OLIterator interface.

type Writer

type Writer interface {
	io.Writer
	io.ByteWriter
	io.StringWriter
	LastByte() (byte, bool)
}

Writer wraps a standard io.Writer, to add a few extensions useful within a Renderer.

Jump to

Keyboard shortcuts

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