html-to-markdown: Index | Files | Directories

package md

import ""

Package md converts html to markdown.

converter := md.NewConverter("", true, nil)

html = `<strong>Important</strong>`

markdown, err := converter.ConvertString(html)
if err != nil {
fmt.Println("md ->", markdown)

Or if you are already using goquery:

markdown, err := converter.Convert(selec)


Package Files

commonmark.go from.go markdown.go


var Timeout = time.Second * 10

Timeout for the http client

func DomainFromURL Uses

func DomainFromURL(rawURL string) string

DomainFromURL removes the path from the url.

func IsBlockElement Uses

func IsBlockElement(e string) bool

func IsInlineElement Uses

func IsInlineElement(e string) bool

func String Uses

func String(text string) *string

String is a helper function to return a pointer.

type AdvancedResult Uses

type AdvancedResult struct {
    Header   string
    Markdown string
    Footer   string

type Converter Uses

type Converter struct {
    Before func(selec *goquery.Selection)
    // contains filtered or unexported fields

Converter is initialized by NewConverter.

func NewConverter Uses

func NewConverter(domain string, enableCommonmark bool, options *Options) *Converter

NewConverter initializes a new converter and holds all the rules. - `domain` is used for links and images to convert relative urls ("/image.png") to absolute urls. - CommonMark is the default set of rules. Set enableCommonmark to false if you want

to customize everything using AddRules and DONT want to fallback to default rules.

func (*Converter) AddRules Uses

func (c *Converter) AddRules(rules ...Rule) *Converter

AddRules adds the rules that are passed in to the converter.

func (*Converter) Convert Uses

func (c *Converter) Convert(selec *goquery.Selection) string

Convert returns the content from a goquery selection. If you have a goquery document just pass in doc.Selection.

func (*Converter) ConvertBytes Uses

func (c *Converter) ConvertBytes(bytes []byte) ([]byte, error)

ConvertBytes returns the content from a html byte array.

func (*Converter) ConvertReader Uses

func (c *Converter) ConvertReader(reader io.Reader) (bytes.Buffer, error)

ConvertReader returns the content from a reader and returns a buffer.

func (*Converter) ConvertResponse Uses

func (c *Converter) ConvertResponse(res *http.Response) (string, error)

ConvertResponse returns the content from a html response.

func (*Converter) ConvertString Uses

func (c *Converter) ConvertString(html string) (string, error)

ConvertString returns the content from a html string. If you already have a goquery selection use `Convert`.

func (*Converter) ConvertURL Uses

func (c *Converter) ConvertURL(url string) (string, error)

ConvertURL returns the content from the page with that url.

func (*Converter) Keep Uses

func (c *Converter) Keep(tags ...string) *Converter

Keep certain html tags in the generated output.

func (*Converter) Remove Uses

func (c *Converter) Remove(tags ...string) *Converter

Remove certain html tags from the source.

func (*Converter) Use Uses

func (c *Converter) Use(plugins ...Plugin) *Converter

Use can be used to add additional functionality to the converter. It is used when its not sufficient to use only rules for example in Plugins.

type Options Uses

type Options struct {
    // "setext" or "atx"
    // default: "atx"
    HeadingStyle string

    // Any Thematic break
    // default: "* * *"
    HorizontalRule string

    // "-", "+", or "*"
    // default: "-"
    BulletListMarker string

    // "indented" or "fenced"
    // default: "indented"
    CodeBlockStyle string

    // ``` or ~~~
    // default: ```
    Fence string

    // _ or *
    // default: _
    EmDelimiter string

    // ** or __
    // default: **
    StrongDelimiter string

    // inlined or referenced
    // default: inlined
    LinkStyle string

    // full, collapsed, or shortcut
    // default: full
    LinkReferenceStyle string

Options to customize the output. You can change stuff like the character that is used for strong text.

type Plugin Uses

type Plugin func(conv *Converter) []Rule

Plugin can be used to extends functionality beyond what is offered by commonmark.

type Rule Uses

type Rule struct {
    Filter              []string
    Replacement         func(content string, selec *goquery.Selection, options *Options) *string
    AdvancedReplacement func(content string, selec *goquery.Selection, options *Options) (res AdvancedResult, skip bool)

Rule to convert certain html tags to markdown.

  Filter: []string{"del", "s", "strike"},
  Replacement: func(content string, selec *goquery.Selection, opt *md.Options) *string {
    // You need to return a pointer to a string (md.String is just a helper function).
    // If you return nil the next function for that html element
    // will be picked. For example you could only convert an element
    // if it has a certain class name and fallback if not.
    return md.String("~" + content + "~")


escapePackage escape escapes characters that are commonly used in markdown like the * for strong/italic.
pluginPackage plugin contains all the rules that are not part of Commonmark like GitHub Flavored Markdown.

Package md imports 14 packages (graph) and is imported by 1 packages. Updated 2018-05-27. Refresh now. Tools for package owners.