htmlmd

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package htmlmd turns a part of an HTML page into Markdown, selected and cleaned with simple CSS selectors.

Index

Constants

This section is empty.

Variables

View Source
var ErrSelector = errors.New("invalid selector")

ErrSelector is wrapped by every selector parse error.

Functions

This section is empty.

Types

type Document

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

Document is a parsed HTML page. Its methods don't change it, so one page can be converted in parts.

func Parse

func Parse(src []byte, pageURL string) (*Document, error)

Parse parses an HTML page fetched from pageURL, which makes relative links absolute.

func (*Document) Anchor

func (d *Document) Anchor(ctx context.Context, id string, o Options) (string, bool, error)

Anchor converts the element whose id is id. For a heading that is the heading and the siblings after it up to the next heading of the same or a higher level. The second result is false when the page has no such element.

func (*Document) Markdown

func (d *Document) Markdown(ctx context.Context, o Options) (string, error)

Markdown converts the content element of the page.

type Options

type Options struct {
	Content string   // selector of the element to convert; empty means main, else body
	Strip   []string // selectors of elements to drop before converting
}

Options selects and cleans the part of a page to convert.

type Selector

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

Selector matches elements by tag, id and classes, such as div.body, a.headerlink or #main. It has no combinators: one selector names one element.

func ParseSelector

func ParseSelector(s string) (Selector, error)

ParseSelector parses tag, #id and .class parts written together without spaces.

func (Selector) Match

func (s Selector) Match(n *html.Node) bool

Match reports whether n is an element the selector names.

Jump to

Keyboard shortcuts

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