article

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package article contains the bounded, text-only rendering used by article extraction. It deliberately accepts a DOM instead of an HTML string so the extractor does not need to serialize and parse its result again.

Index

Constants

View Source
const (
	// MaxMarkdownDepth is separate from readability's element limit. A deeply
	// nested, otherwise small document must not consume an unbounded Go stack.
	MaxMarkdownDepth = core.MaxNestingDepth
)

Variables

View Source
var (
	// ErrNilNode reports an invalid conversion root.
	ErrNilNode = errors.New("article markdown: nil HTML node")
	// ErrMarkdownTooLarge reports output that cannot be retained safely.
	ErrMarkdownTooLarge = errors.New("article markdown: rendered output exceeds the size limit")
)
View Source
var ErrUnsupportedContentType = errors.New("article mode requires HTML or Markdown content")

ErrUnsupportedContentType identifies a response that article mode cannot extract. Article mode accepts HTML/XHTML and Markdown responses.

Functions

func Convert

func Convert(root *html.Node) (string, error)

Convert renders root and its descendants as deterministic CommonMark-style Markdown. root may be a document node or any content node. The result has a single trailing newline when it contains content.

The renderer is intentionally conservative. It omits executable and presentation-only elements, treats unknown elements according to their block/inline role, and skips descendants beyond MaxMarkdownDepth.

func ReadLimited

func ReadLimited(source io.Reader) ([]byte, error)

ReadLimited reads at most the configured decoded article-body limit. It does not retain a sentinel byte when the input is exactly at the limit.

func Render

func Render(source []byte, contentType, pageURL string) ([]byte, error)

Render extracts readable HTML or adds article frontmatter to Markdown. pageURL is the final response URL. The returned bytes are uncolored and are suitable for files, pipes, and terminal presentation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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