sections

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sections partitions a filing into its named 10-K item sections and renders clean free text for each, with all inline-XBRL scaffolding removed.

Like internal/ixbrl, it walks the *html.Node tree produced by golang.org/x/net/html, whose HTML5 tokenizer lowercases every element and attribute name — so the namespaced source names ("ix:header", "ix:hidden", "ix:nonFraction") appear here lowercased, and the constants are written to match.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSections = errors.New("sections: no sections detected")

ErrNoSections is returned when neither strategy can recover a section boundary — the document has no usable table of contents and no item-shaped headings.

Functions

func RenderText

func RenderText(n *html.Node) string

RenderText renders a node's subtree to clean free text: block elements become blank-line-separated paragraphs, list items are prefixed with "- ", and all inline-XBRL scaffolding is removed — ix:header and ix:hidden subtrees are dropped entirely while ix:nonNumeric/ix:nonFraction wrappers are unwrapped to their visible text (the value stays, the tag vanishes). Non-breaking spaces and whitespace runs collapse to single spaces.

func SectionFormats

func SectionFormats(p Result) map[string]router.FilingFormat

SectionFormats classifies each section's tables as fact-tagged (router.IXBRL, where statement projection applies) or plain HTML (router.PlainHTML, where the layout fallback is the only option), for populating router.Decision.SectionFormats on a PartialIXBRL filing. The map is keyed by item id; sections with no tables are omitted. It returns nil when no section carries a table.

Types

type Result

type Result struct {
	Sections   []Section        `json:"sections"`
	Confidence model.Confidence `json:"confidence"`
	Strategy   string           `json:"strategy"`
}

Result is the ordered section list, the partition confidence (migrated to model.Confidence in Phase 9), and the strategy that produced the boundaries ("toc", "heading", or "none").

func Partition

func Partition(doc *html.Node) (Result, error)

Partition splits a parsed filing into its named item sections. It tries the table-of-contents anchors first (high confidence: the filing names its own structure) and falls back to heading-text patterns (medium confidence). A section runs from its start to the next section's start in document order.

type Section

type Section struct {
	// Item is the 10-K item identifier, e.g. "1A".
	Item string `json:"item"`
	// Title is the canonical item title, e.g. "Risk Factors".
	Title string `json:"title"`
	// Heading is the heading text as it appeared at the section's start.
	Heading string `json:"heading"`
	// Kind separates narrative sections from the financial-statements section.
	Kind model.Kind `json:"kind"`
	// Text is the rendered free text of the section, iXBRL scaffolding removed.
	Text string `json:"text"`

	// StartNode is the section's first node; EndNode is the next section's start
	// (exclusive, nil for the last section). They bound the section in document
	// order so the pipeline can later bind statements to it. Tables holds the
	// <table> elements that fall inside the section. None of these serialize.
	StartNode *html.Node   `json:"-"`
	EndNode   *html.Node   `json:"-"`
	Tables    []*html.Node `json:"-"`
}

Section is one named part of a filing in document order. It is the thin working type the pipeline maps to a model.Section: it carries the same data (Item, Title, Kind, Text) plus the html node range and tables the pipeline needs to project statements into the section.

func (Section) Model

func (s Section) Model() model.Section

Model projects the section to its serializable model.Section shape, dropping the working html node range. The financial tables inside the section are left for the pipeline to fill with projected/extracted model.Tables.

Jump to

Keyboard shortcuts

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