godown

package module
v0.0.0-...-d118852 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 8 Imported by: 0

README

godown

Convert HTML into Markdown

This is work in progress.

A fork of https://github.com/mattn/godown.

This Fork

  • add the option to print links and references at the bottom of the generated markdown file
  • add a r flag to generate reference style links from the cli

Usage

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

Command Line

$ godown < index.html > index.md

Installation

$ go get git.sr.ht/~jonah/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
	TrimSpace      bool
	ReferenceLinks bool
	CustomRules    []CustomRule
	// contains filtered or unexported fields
}

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