godown

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 8 Imported by: 0

README

godown

A library to convert HTML into Markdown

Usage

err := godown.Convert(w, r, nil)
checkError(err)

Usage

$ go get github.com/wormi4ok/godown

License

MIT

Original Author

Yasuhiro Matsumoto (a.k.a. mattn)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(w io.Writer, r io.Reader, option *Option) error

Convert converts HTML to Markdown. Read HTML from r and write to w.

Types

type CustomRule

type CustomRule interface {
	Rule(next WalkFunc) (tagName string, customRule WalkFunc)
}

CustomRule is an interface to define custom conversion rules

Rule method accepts `next WalkFunc` as an argument, which `customRule` should call to let walk function continue parsing the content inside the HTML tag. It returns a tagName to indicate what HTML element this `customRule` handles and the `customRule` function itself, where conversion logic should reside.

See example TestRule implementation in godown_test.go

type Option

type Option struct {
	GuessLang      func(string) (string, error)
	Script         bool
	Style          bool
	TrimSpace      bool
	CustomRules    []CustomRule
	IgnoreComments bool
	ItalicsAsterix bool // Used to know if to use _ or * for italics
	DoNotEscape    bool // Used to know if to escape certain characters
	// contains filtered or unexported fields
}

Option is optional information for Convert.

func (*Option) Clone added in v0.2.0

func (o *Option) Clone() *Option

Clone makes a copy of an option without changing the original

type WalkFunc

type WalkFunc func(node *html.Node, w io.Writer, nest int, option *Option)

WalkFunc type is a signature for functions traversing HTML nodes

Jump to

Keyboard shortcuts

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