engine

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine reads a document with a profile (PROFILE_FORMAT.md): it consumes the element events of package xmlread, as the generic reader does, and makes the blocks the profile's rules say. Elements with no rule are read generically and counted.

Index

Constants

View Source
const (
	// AttrChildren is the indexes in Document.Children of the documents
	// that came from a section, comma separated, on its heading (else
	// its first block).
	AttrChildren = "children"
	// AttrMediaType is the media type of a document rule's text kept in
	// the body (the child was not extracted, or not handed over).
	AttrMediaType = "media_type"
)

Keys the engine writes for embedded documents ("document" rules).

View Source
const (
	// MaxTableColumns bounds the columns of a table.
	MaxTableColumns = 1024
	// MaxRowSpan bounds how many rows one cell spans.
	MaxRowSpan = 65535
	// MaxNamesCounted bounds the distinct names counted in the
	// xml.unmapped_* warnings; the rest are counted together.
	MaxNamesCounted = 1000
	// MaxParts bounds the parts a profile's part rules start.
	MaxParts = 100000
)

Fixed bounds. What they cut is reported with limit.exceeded.

View Source
const (
	// AttrAnchorParent is the identifier of the nearest enclosing element
	// a rule names with "anchor", on a block with no identifier of its own.
	AttrAnchorParent = "anchor_parent"
	// AttrHeaderSource is "profile" on a table whose header row is the
	// profile's fixed text.
	AttrHeaderSource = "header_source"
	// AttrTitle is a link's title ("title") in its stored record.
	AttrTitle = "title"
	// AttrHref is the address of a link, on its record in the stored part.
	AttrHref = "href"
)

Keys of Block.Attrs the engine writes.

View Source
const (
	WarnUnmappedElements   = "xml.unmapped_elements"
	WarnUnmappedAttributes = "xml.unmapped_attributes"
	WarnSkipped            = "xml.skipped_elements"
)

Warning codes of the engine.

View Source
const MaxAttachmentBytes = 64 << 20

MaxAttachmentBytes bounds the base64 text of one attachment (an "encoding": "base64" document rule) that is decoded and handed over: 64 MiB, 48 MiB decoded. A longer one is not handed over.

View Source
const MaxChildNameBytes = 256

MaxChildNameBytes bounds the anchor written into a child's name.

View Source
const MaxNamesListed = 100

MaxNamesListed bounds the names a warning lists.

Variables

This section is empty.

Functions

func HasMarkup added in v0.2.0

func HasMarkup(t []byte) bool

HasMarkup reports whether text holds a tag (`<` followed by a letter, `/` or `!`, and later a `>`) or a character or entity reference (`&` name `;`, `&#` digits `;`, `&#x` hex digits `;`).

Types

type ChildLoc added in v0.2.0

type ChildLoc struct {
	Offset, Length int64
	Anchor         string
	Element        string
	// contains filtered or unexported fields
}

ChildLoc is where a child came from: its element in the file (start tag to end tag), the anchor of the nearest enclosing identified element and the element's path.

type Engine

type Engine struct {

	// Meta collects the metadata the rules give.
	Meta gofastcore.Metadata

	// Counts for the whole reading.
	ValuesCut, ColumnsCut, SpansCut, TextCut, PartsCut int
	// RowSpanCut counts cells whose row span was cut to MaxRowSpan.
	RowSpanCut int
	// PendingCut counts blocks cut because more than MaxPendingBlocks
	// attribute notes waited for them.
	PendingCut        int
	Controls, Invalid int

	// Embedded documents ("document" rules): the documents and where each
	// came from, in file order. DocsCut counts contents cut to
	// MaxBlockBytes, ChildrenCut those not handed over past MaxChildren,
	// Plain those kept as a paragraph because they held no markup.
	Children                    []*gofastcore.Document
	ChildLocs                   []ChildLoc
	DocsCut, ChildrenCut, Plain int
	// AttachmentsCut counts attachments (base64) not handed over: past
	// MaxAttachmentBytes or MaxChildren; AttachmentsBad those whose text
	// is not base64.
	AttachmentsCut, AttachmentsBad int
	// contains filtered or unexported fields
}

Engine is the profile consumer. It implements xmlread.Handler.

func New

func New(p *profile.Profile, out *generic.Out, opts Options) *Engine

New returns an engine reading with p into out, whose Part is the first part.

func (*Engine) Attr

func (e *Engine) Attr(i int, q profile.QName) (string, bool)

func (*Engine) Comment

func (e *Engine) Comment(r *xmlread.Reader, t []byte, final bool, start, end int64)

Comment implements xmlread.Handler: a comment is a note marked stored, at its place.

func (*Engine) Counts

func (e *Engine) Counts() (controls, invalid int)

Counts returns the control characters removed and invalid bytes met in all the text made.

func (*Engine) EndElement

func (e *Engine) EndElement(r *xmlread.Reader, el *xmlread.Element, start, end int64)

EndElement implements xmlread.Handler.

func (*Engine) Finish

func (e *Engine) Finish(end int64)

Finish ends the reading at offset end.

func (*Engine) HasToken

func (e *Engine) HasToken(i int, q profile.QName, tok string) bool

HasToken implements profile.TokenPath: an element's tested value is split into its tokens once, the first time a rule tests it.

func (*Engine) Len

func (e *Engine) Len() int

func (*Engine) Name

func (e *Engine) Name(i int) profile.QName

func (*Engine) PartWarnings

func (e *Engine) PartWarnings(p *gofastcore.Part)

PartWarnings writes the engine's warnings about part p.

func (*Engine) Parts

func (e *Engine) Parts() []*gofastcore.Part

Parts returns the parts made, the stored part last if there is one.

func (*Engine) StartElement

func (e *Engine) StartElement(r *xmlread.Reader, el *xmlread.Element)

StartElement implements xmlread.Handler.

func (*Engine) Stop

func (e *Engine) Stop() bool

Stop implements xmlread.Handler.

func (*Engine) Text

func (e *Engine) Text(r *xmlread.Reader, t []byte, start, end int64)

Text implements xmlread.Handler.

type Options

type Options struct {
	Spans    bool
	NoImages bool
	// Child hands over the content of a "document" rule's element; it
	// returns the document to list in Children and whether it was
	// extracted. Without it the content is kept as a paragraph.
	Child func(name, mediaType string, data []byte) (*gofastcore.Document, bool)
	// Raw returns the bytes of the file from start to end, for XHTML
	// content; nil when the file is not UTF-8 (the content is then
	// written from the decoded text).
	Raw func(start, end int64) []byte
	// MaxChildren bounds the documents handed over.
	MaxChildren int
	// PartWanted reports whether the part of that number is in the
	// output; the content of document rules in other parts is not handed
	// over.
	PartWanted func(number int) bool
}

Options are the engine's settings.

Jump to

Keyboard shortcuts

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