godown

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: MIT Imports: 7 Imported by: 44

README

godown

Build Status Codecov GoDoc Go Report Card

Convert HTML into Markdown

This is work in progress.

Usage

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

Command Line

$ godown < index.html > index.md

Installation

$ go get github.com/mattn/godown/cmd/godown

TODO

  • escape strings in HTML

License

MIT

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 convert 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
	CustomRules []CustomRule
}

Option is optional information for Convert.

type WalkFunc

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

WalkFunc type is an signature for functions traversing HTML nodes

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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