html2md

package module
v0.0.0-...-61a0ad7 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2025 License: MIT Imports: 10 Imported by: 0

README

html2md

Go Reference

html2md is a Go library which provides a simple interface to convert HTML code to markdown. It aims to support the CommonMark specification as well as GitHub-flavored markdown.

It powers ananke, a CLI tool which converts HTML to Markdown.

Usage
package main

import (
	"fmt"
	"github.com/shravanasati/ananke/html2md"
)

func main() {
	converter := html2md.NewConverter()
	// pass options

	input := "<ul></ul>"
	output := converter.ConvertString()
}

The converter is NOT thread-safe and must be used exactly once for each input.

The caller should ensure that the input is UTF-8 encoded.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnchorTag

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

func NewAnchorTag

func NewAnchorTag(href, title string) *AnchorTag

func (AnchorTag) EndCode

func (a AnchorTag) EndCode() string

func (AnchorTag) StartCode

func (a AnchorTag) StartCode() string

func (AnchorTag) Type

func (a AnchorTag) Type() MarkdownElementType

type BRTag

type BRTag struct{}

func NewBRTag

func NewBRTag() *BRTag

func (BRTag) EndCode

func (p BRTag) EndCode() string

func (BRTag) StartCode

func (p BRTag) StartCode() string

func (BRTag) Type

func (p BRTag) Type() MarkdownElementType

type BlockquoteTag

type BlockquoteTag struct{}

func NewBlockquoteTag

func NewBlockquoteTag() *BlockquoteTag

func (BlockquoteTag) EndCode

func (bl BlockquoteTag) EndCode() string

func (BlockquoteTag) StartCode

func (bl BlockquoteTag) StartCode() string

func (BlockquoteTag) Type

type BoldTag

type BoldTag struct{}

func NewBoldTag

func NewBoldTag() *BoldTag

func (BoldTag) EndCode

func (bold BoldTag) EndCode() string

func (BoldTag) StartCode

func (bold BoldTag) StartCode() string

func (BoldTag) Type

func (bold BoldTag) Type() MarkdownElementType

type Converter

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

func NewConverter

func NewConverter() *Converter

func (*Converter) ConvertString

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

type FencedCodeTag

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

func NewFencedCodeTag

func NewFencedCodeTag(language string) *FencedCodeTag

func (FencedCodeTag) EndCode

func (fc FencedCodeTag) EndCode() string

func (FencedCodeTag) StartCode

func (fc FencedCodeTag) StartCode() string

func (FencedCodeTag) Type

type H1Tag

type H1Tag struct{}

func NewH1Tag

func NewH1Tag() *H1Tag

func (H1Tag) EndCode

func (h1 H1Tag) EndCode() string

func (H1Tag) StartCode

func (h1 H1Tag) StartCode() string

func (H1Tag) Type

func (h1 H1Tag) Type() MarkdownElementType

type H2Tag

type H2Tag struct{}

func NewH2Tag

func NewH2Tag() *H2Tag

func (H2Tag) EndCode

func (h2 H2Tag) EndCode() string

func (H2Tag) StartCode

func (h2 H2Tag) StartCode() string

func (H2Tag) Type

func (h2 H2Tag) Type() MarkdownElementType

type H3Tag

type H3Tag struct{}

func NewH3Tag

func NewH3Tag() *H3Tag

func (H3Tag) EndCode

func (h3 H3Tag) EndCode() string

func (H3Tag) StartCode

func (h3 H3Tag) StartCode() string

func (H3Tag) Type

func (h3 H3Tag) Type() MarkdownElementType

type H4Tag

type H4Tag struct{}

func NewH4Tag

func NewH4Tag() *H4Tag

func (H4Tag) EndCode

func (h4 H4Tag) EndCode() string

func (H4Tag) StartCode

func (h4 H4Tag) StartCode() string

func (H4Tag) Type

func (h4 H4Tag) Type() MarkdownElementType

type H5Tag

type H5Tag struct{}

func NewH5Tag

func NewH5Tag() *H5Tag

func (H5Tag) EndCode

func (h5 H5Tag) EndCode() string

func (H5Tag) StartCode

func (h5 H5Tag) StartCode() string

func (H5Tag) Type

func (h5 H5Tag) Type() MarkdownElementType

type H6Tag

type H6Tag struct{}

func NewH6Tag

func NewH6Tag() *H6Tag

func (H6Tag) EndCode

func (h6 H6Tag) EndCode() string

func (H6Tag) StartCode

func (h6 H6Tag) StartCode() string

func (H6Tag) Type

func (h6 H6Tag) Type() MarkdownElementType

type HRTag

type HRTag struct{}

func NewHRTag

func NewHRTag() *HRTag

func (HRTag) EndCode

func (p HRTag) EndCode() string

func (HRTag) StartCode

func (p HRTag) StartCode() string

func (HRTag) Type

func (p HRTag) Type() MarkdownElementType

type ImageTag

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

func NewImageTag

func NewImageTag(src, altText string) *ImageTag

func (ImageTag) EndCode

func (img ImageTag) EndCode() string

func (ImageTag) StartCode

func (img ImageTag) StartCode() string

func (ImageTag) Type

func (img ImageTag) Type() MarkdownElementType

type InlineCodeTag

type InlineCodeTag struct{}

func NewInlineCodeTag

func NewInlineCodeTag() *InlineCodeTag

func (InlineCodeTag) EndCode

func (ic InlineCodeTag) EndCode() string

func (InlineCodeTag) StartCode

func (ic InlineCodeTag) StartCode() string

func (InlineCodeTag) Type

type ItalicTag

type ItalicTag struct{}

func NewItalicTag

func NewItalicTag() *ItalicTag

func (ItalicTag) EndCode

func (italic ItalicTag) EndCode() string

func (ItalicTag) StartCode

func (italic ItalicTag) StartCode() string

func (ItalicTag) Type

func (italic ItalicTag) Type() MarkdownElementType

type ListItemTag

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

func NewListItemTag

func NewListItemTag(depth int, type_ ListOrdering, number string) *ListItemTag

func (ListItemTag) EndCode

func (li ListItemTag) EndCode() string

func (ListItemTag) StartCode

func (li ListItemTag) StartCode() string

func (ListItemTag) Type

func (li ListItemTag) Type() MarkdownElementType

type ListOrdering

type ListOrdering uint
const (
	UnorderedList ListOrdering = iota
	OrderedList
)

type ListTag

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

func NewListTag

func NewListTag(type_ ListOrdering, depth int) *ListTag

func (ListTag) EndCode

func (l ListTag) EndCode() string

func (ListTag) StartCode

func (l ListTag) StartCode() string

func (ListTag) Type

func (l ListTag) Type() MarkdownElementType

type MarkdownElement

type MarkdownElement interface {
	Type() MarkdownElementType
	StartCode() string
	EndCode() string
}

type MarkdownElementType

type MarkdownElementType int
const (
	Bold MarkdownElementType = iota
	Italic
	H1
	H2
	H3
	H4
	H5
	H6
	Paragraph
	Anchor
	Image
	List // can be ordered as well unordered
	ListItem
	Blockquote
	InlineCode
	Pre
	FencedCode
	BR
	HR
	Unknown
)

type ParagraphTag

type ParagraphTag struct{}

func NewParagraphTag

func NewParagraphTag() *ParagraphTag

func (ParagraphTag) EndCode

func (p ParagraphTag) EndCode() string

func (ParagraphTag) StartCode

func (p ParagraphTag) StartCode() string

func (ParagraphTag) Type

type PreTag

type PreTag struct{}

func NewPreTag

func NewPreTag() *PreTag

func (PreTag) EndCode

func (p PreTag) EndCode() string

func (PreTag) StartCode

func (p PreTag) StartCode() string

func (PreTag) Type

func (p PreTag) Type() MarkdownElementType

type UnknownTag

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

func NewUnknownTag

func NewUnknownTag(data string) *UnknownTag

func (UnknownTag) EndCode

func (u UnknownTag) EndCode() string

func (UnknownTag) StartCode

func (u UnknownTag) StartCode() string

func (UnknownTag) Type

Jump to

Keyboard shortcuts

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