Skip to content

Commit aab264b

Browse files
committed
Support TightLinks option
This removes spaces around URLs inside parentheses.
1 parent 0da0d4a commit aab264b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

html2text.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Options struct {
1818
PrettyTables bool // Turns on pretty ASCII rendering for table elements.
1919
PrettyTablesOptions *PrettyTablesOptions // Configures pretty ASCII rendering for table elements.
2020
OmitLinks bool // Turns on omitting links
21+
TightLinks bool // Removes whitespace around links
2122
}
2223

2324
// PrettyTablesOptions overrides tablewriter behaviors
@@ -255,7 +256,11 @@ func (ctx *textifyTraverseContext) handleElement(node *html.Node) error {
255256
attrVal = ctx.normalizeHrefLink(attrVal)
256257
// Don't print link href if it matches link element content or if the link is empty.
257258
if !ctx.options.OmitLinks && attrVal != "" && linkText != attrVal {
258-
hrefLink = "( " + attrVal + " )"
259+
if ctx.options.TightLinks {
260+
hrefLink = "(" + attrVal + ")"
261+
} else {
262+
hrefLink = "( " + attrVal + " )"
263+
}
259264
}
260265
}
261266

0 commit comments

Comments
 (0)