Documentation
¶
Overview ¶
Package blocks turns an HTML document tree into the blocks of the shared model: headings, paragraphs, list items, tables, code, quotes, captions, images, comments and form values, with white space collapsed as CSS white-space: normal does, links and styles as spans, and the display reasons the page declares.
Index ¶
Constants ¶
const ( NoteAttribute = gofastcore.NoteAttribute AttrAttribute = "attribute" // AttrChecked is set on a list item that begins with a checkbox (a // task-list item): "true" when checked, "false" when not. AttrChecked = "checked" )
The note an attribute's text becomes says so in Attrs: type "attribute" (core's NoteAttribute), and the attribute's name under "attribute".
const MaxAnchor = 1024
MaxAnchor bounds the length of an id used as Loc.Anchor; a longer id is not used.
const MaxLang = 64
MaxLang bounds the length of the html element's lang and of a code block's language; a longer one is left out.
const MaxMeta = 64 << 10
MaxMeta bounds the length of one metadata value.
const MaxMetaList = 256
MaxMetaList bounds the author and the keyword declarations read.
const StoredStylesheet = gofastcore.StoredStylesheet
StoredStylesheet is the Attrs["stored"] value of the text of a style element in the stored part.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Spans bool
Images gofastcore.ImageMode
Budget *gofastcore.TextBudget
Decode *gofastcore.DecodeBudget
// Source maps an offset in the decoded text to one in the source.
Source func(int) int64
// Image resolves the address of an image inside the container the
// page is in; Internal reports an address inside it, which is not
// counted as an external reference. Both are nil for a page alone.
Image func(src string) (ImageRef, bool)
Internal func(ref string) bool
// MaxDepth bounds element nesting, counted through iframe srcdoc
// documents into the page; zero means dom.DefaultMaxDepth.
MaxDepth int
}
Config says what to produce.
type ImageRef ¶
type ImageRef struct {
ID, MIME string
// Data reads the image's bytes, within the decode budget.
Data func() ([]byte, bool)
}
ImageRef is an image a page refers to that is inside the container the page is in (an EPUB).
type Result ¶
type Result struct {
Blocks []gofastcore.Block
Meta gofastcore.Metadata
Title bool // a <title> was found
Cut bool // the text budget ran out; the blocks stop there
Active int // scripts, event handler attributes, javascript: links
External int // resources the page loads from elsewhere
// ImageData counts images given as data: URIs whose bytes could not
// be decoded.
ImageData int
// ImageBudget counts images given as data: URIs that were not
// decoded, their bytes passing the decode budget: they have no ID
// and no data.
ImageBudget int
// MetaCut counts the metadata values longer than MaxMeta, cut there;
// TitleCut reports that the title was one of them.
MetaCut int
TitleCut bool
// AuthorsLeftOut and KeywordsLeftOut count the author and keyword
// declarations past MaxMetaList, left out.
AuthorsLeftOut, KeywordsLeftOut int
// LangLeftOut reports an html lang longer than MaxLang, left out.
LangLeftOut bool
// AnchorsLeftOut counts the elements whose id (or an a's name) is
// longer than MaxAnchor, not used as Loc.Anchor.
AnchorsLeftOut int
// LanguagesLeftOut counts the code blocks whose language is longer
// than MaxLang, left out.
LanguagesLeftOut int
// Controls counts the control characters with no meaning as text
// dropped from the text: of blocks, notes, alt text and metadata
// values. White space, line ends and tabs are not counted, nor what
// is dropped from addresses and names (anchors, links, languages).
Controls int
// Images counts img elements, whether or not blocks were made.
Images int
// Stylesheets counts style elements and linked stylesheets, whose
// rules are not evaluated.
Stylesheets int
// Stored holds what the page keeps and shows nowhere: script and
// style text, hidden form values. It goes to the stored part.
Stored []gofastcore.Block
// FrameDepth: an iframe srcdoc document was not read, being nested
// at the depth limit. FrameFlattened: one was nested deeper than the
// limit inside and was read side by side. FrameDecode: the decode
// budget ran out in a srcdoc document, which was cut there.
FrameDepth, FrameFlattened, FrameDecode bool
// FrameCaps reports the bounds of the tree builder reached in iframe
// srcdoc documents.
FrameCaps dom.Caps
// FrameReplaced counts the character references read as U+FFFD in
// iframe srcdoc documents (dom.Doc.Replaced).
FrameReplaced int
}
Result is what a walk produced.