Skip to content

Commit

Permalink
Support TightLinks option
Browse files Browse the repository at this point in the history
This removes spaces around URLs inside parentheses.
  • Loading branch information
thebaer committed Sep 2, 2020
1 parent 0da0d4a commit aab264b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion html2text.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Options struct {
PrettyTables bool // Turns on pretty ASCII rendering for table elements.
PrettyTablesOptions *PrettyTablesOptions // Configures pretty ASCII rendering for table elements.
OmitLinks bool // Turns on omitting links
TightLinks bool // Removes whitespace around links
}

// PrettyTablesOptions overrides tablewriter behaviors
Expand Down Expand Up @@ -255,7 +256,11 @@ func (ctx *textifyTraverseContext) handleElement(node *html.Node) error {
attrVal = ctx.normalizeHrefLink(attrVal)
// Don't print link href if it matches link element content or if the link is empty.
if !ctx.options.OmitLinks && attrVal != "" && linkText != attrVal {
hrefLink = "( " + attrVal + " )"
if ctx.options.TightLinks {
hrefLink = "(" + attrVal + ")"
} else {
hrefLink = "( " + attrVal + " )"
}
}
}

Expand Down

0 comments on commit aab264b

Please sign in to comment.