extract

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPDFNoText = errors.New("PDF contains no extractable text")

ErrPDFNoText reports a valid PDF with no extractable text layer.

Functions

func DetectJSShell

func DetectJSShell(rawHTML string) string

DetectJSShell analyzes raw HTML and returns whether the page appears to be a JavaScript shell that needs browser rendering for content extraction. Returns: "static" (has content), "likely_shell" (needs browser), or "ambiguous".

It uses only the built-in markers. Callers with operator-configured markers should build a Detector via NewDetector and call its method instead.

func DetectJSShellFromDoc

func DetectJSShellFromDoc(doc *goquery.Document, rawHTML string) string

DetectJSShellFromDoc is the core detector given an already-parsed document and its raw source. Useful when callers have already paid for the parse. It uses only the built-in markers; see NewDetector for operator markers.

func ExtractSelector

func ExtractSelector(rawHTML, selector string) (string, error)

ExtractSelector runs a CSS selector against raw HTML and returns the matched elements converted to markdown. If no elements match, returns an empty string and no error.

func PostProcess

func PostProcess(s string, trim bool, maxChars int) string

PostProcess applies trim (StripMarkdown) then Truncate to markdown content. It is the shared output post-processing step for the CLI's --trim/--max-chars flags and the MCP tools' trim/max_chars params.

func StripMarkdown

func StripMarkdown(s string) string

StripMarkdown removes markdown formatting syntax while preserving content text. Images are removed entirely; links keep their text; headings keep their text. Fenced code blocks (``` ... ```) are left intact — their content is code, not prose.

func Title

func Title(html string) string

Title pulls the <title> tag content from raw HTML.

func Truncate

func Truncate(s string, maxChars int) string

Truncate caps s at maxChars Unicode code points, appending a truncation marker. maxChars <= 0 disables truncation.

Types

type Detector

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

Detector classifies raw HTML as "static" (has content), "likely_shell" (needs browser rendering), or "ambiguous". The zero value is ready to use and matches only the built-in framework markers; NewDetector folds in operator-configured markers (config spa_markers) on top of the built-ins.

func NewDetector

func NewDetector(extraMarkers []string) *Detector

NewDetector returns a Detector that also matches the given operator-supplied SPA markers (substrings of the lowercased HTML) in addition to the built-in ones. Markers are lowercased and trimmed; blank entries are dropped so a stray "" can never match every page.

func (*Detector) DetectJSShell

func (d *Detector) DetectJSShell(rawHTML string) string

DetectJSShell parses rawHTML and classifies it. See DetectJSShell.

func (*Detector) DetectJSShellFromDoc

func (d *Detector) DetectJSShellFromDoc(doc *goquery.Document, rawHTML string) string

DetectJSShellFromDoc classifies an already-parsed document. See DetectJSShellFromDoc.

type Extractor

type Extractor struct{}

Extractor converts raw HTML into clean markdown.

func New

func New() *Extractor

New creates an Extractor.

func (*Extractor) Extract

func (e *Extractor) Extract(pageURL, html string) (*Result, error)

Extract takes a URL and raw HTML, extracts the main content, and converts it to markdown. Falls back to direct HTML→markdown conversion if readability extraction fails.

type PDFExtractor added in v0.12.0

type PDFExtractor interface {
	Extract(ctx context.Context, src []byte) (markdown string, err error)
}

PDFExtractor converts PDF bytes into markdown-compatible text.

func NewExternalPDFExtractor added in v0.12.0

func NewExternalPDFExtractor(command string, timeout time.Duration) (PDFExtractor, error)

NewExternalPDFExtractor creates a PDF extractor that invokes command directly (without a shell). The shlex-parsed template must contain exactly one {input} placeholder, which is replaced with a temporary PDF path.

func NewPDFExtractor added in v0.12.0

func NewPDFExtractor() PDFExtractor

NewPDFExtractor returns the built-in pure-Go PDF text extractor.

type Result

type Result struct {
	Title    string
	Markdown string
}

Result holds extracted content from a page.

Jump to

Keyboard shortcuts

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