Documentation
¶
Overview ¶
Package md converts html to markdown.
converter := md.NewConverter("", true, nil)
html = `<strong>Important</strong>`
markdown, err := converter.ConvertString(html)
if err != nil {
log.Fatal(err)
}
fmt.Println("md ->", markdown)
Or if you are already using goquery:
markdown, err := converter.Convert(selec)
Index ¶
- Variables
- func DomainFromURL(rawURL string) string
- func IsBlockElement(e string) bool
- func IsInlineElement(e string) bool
- func String(text string) *string
- type AdvancedResult
- type Converter
- func (c *Converter) AddRules(rules ...Rule) *Converter
- func (c *Converter) Convert(selec *goquery.Selection) string
- func (c *Converter) ConvertBytes(bytes []byte) ([]byte, error)
- func (c *Converter) ConvertReader(reader io.Reader) (bytes.Buffer, error)
- func (c *Converter) ConvertResponse(res *http.Response) (string, error)
- func (c *Converter) ConvertString(html string) (string, error)
- func (c *Converter) ConvertURL(url string) (string, error)
- func (c *Converter) Keep(tags ...string) *Converter
- func (c *Converter) Remove(tags ...string) *Converter
- func (c *Converter) Sanitize(html string) string
- func (c *Converter) Use(plugins ...Plugin) *Converter
- type Options
- type Plugin
- type Rule
Constants ¶
This section is empty.
Variables ¶
var Timeout = time.Second * 10
Timeout for the http client
Functions ¶
func DomainFromURL ¶
DomainFromURL removes the path from the url.
func IsBlockElement ¶
func IsInlineElement ¶
Types ¶
type AdvancedResult ¶
type Converter ¶
type Converter struct {
Before func(selec *goquery.Selection)
// contains filtered or unexported fields
}
Converter is initialized by NewConverter.
func NewConverter ¶
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) Convert ¶
Convert returns the content from a goquery selection. If you have a goquery document just pass in doc.Selection.
func (*Converter) ConvertBytes ¶
ConvertBytes returns the content from a html byte array.
func (*Converter) ConvertReader ¶
ConvertReader returns the content from a reader and returns a buffer.
func (*Converter) ConvertResponse ¶
ConvertResponse returns the content from a html response.
func (*Converter) ConvertString ¶
ConvertString returns the content from a html string. If you already have a goquery selection use `Convert`.
func (*Converter) ConvertURL ¶
ConvertURL returns the content from the page with that url.
type Options ¶
type Options struct {
PreSanitize bool //sanitise the input before go with the conversion
// "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 Rule ¶
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.
md.Rule{
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 + "~")
},
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package escape escapes characters that are commonly used in markdown like the * for strong/italic.
|
Package escape escapes characters that are commonly used in markdown like the * for strong/italic. |
|
examples
|
|
|
add_rules
command
|
|
|
github_flavored
command
|
|
|
goquery
command
|
|
|
options
command
|
|
|
Package plugin contains all the rules that are not part of Commonmark like GitHub Flavored Markdown.
|
Package plugin contains all the rules that are not part of Commonmark like GitHub Flavored Markdown. |
