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
- func HasMarkup(t []byte) bool
- type ChildLoc
- type Engine
- func (e *Engine) Attr(i int, q profile.QName) (string, bool)
- func (e *Engine) Comment(r *xmlread.Reader, t []byte, final bool, start, end int64)
- func (e *Engine) Counts() (controls, invalid int)
- func (e *Engine) EndElement(r *xmlread.Reader, el *xmlread.Element, start, end int64)
- func (e *Engine) Finish(end int64)
- func (e *Engine) HasToken(i int, q profile.QName, tok string) bool
- func (e *Engine) Len() int
- func (e *Engine) Name(i int) profile.QName
- func (e *Engine) PartWarnings(p *gofastcore.Part)
- func (e *Engine) Parts() []*gofastcore.Part
- func (e *Engine) StartElement(r *xmlread.Reader, el *xmlread.Element)
- func (e *Engine) Stop() bool
- func (e *Engine) Text(r *xmlread.Reader, t []byte, start, end int64)
- type Options
Constants ¶
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).
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.
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.
const ( WarnUnmappedElements = "xml.unmapped_elements" WarnUnmappedAttributes = "xml.unmapped_attributes" WarnSkipped = "xml.skipped_elements" )
Warning codes of the engine.
const MaxChildNameBytes = 256
MaxChildNameBytes bounds the anchor written into a child's name.
const MaxNamesListed = 100
MaxNamesListed bounds the names a warning lists.
Variables ¶
This section is empty.
Functions ¶
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
// contains filtered or unexported fields
}
Engine is the profile consumer. It implements xmlread.Handler.
func (*Engine) Comment ¶
Comment implements xmlread.Handler: a comment is a note marked stored, at its place.
func (*Engine) Counts ¶
Counts returns the control characters removed and invalid bytes met in all the text made.
func (*Engine) EndElement ¶
EndElement implements xmlread.Handler.
func (*Engine) HasToken ¶
HasToken implements profile.TokenPath: an element's tested value is split into its tokens once, the first time a rule tests it.
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 ¶
StartElement 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.