Compare commits
2 commits
527fd069df
...
fa2c75ebca
Author | SHA1 | Date | |
---|---|---|---|
fa2c75ebca | |||
dcc8cadaf3 |
2 changed files with 34 additions and 8 deletions
|
@ -40,6 +40,7 @@ func (p Printer) convertHTMLToText(text string, wrapLines bool) string {
|
|||
if wrapLines {
|
||||
return p.wrapLines(builder.String(), 0)
|
||||
}
|
||||
|
||||
return builder.String()
|
||||
case html.TextToken:
|
||||
text := token.Token().Data
|
||||
|
|
|
@ -5,10 +5,16 @@
|
|||
package printer
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type extraIndentConditiion struct {
|
||||
pattern *regexp.Regexp
|
||||
indent string
|
||||
}
|
||||
|
||||
func (p Printer) wrapLines(text string, nIndent int) string {
|
||||
if nIndent >= p.lineWrapCharacterLimit {
|
||||
nIndent = 0
|
||||
|
@ -24,16 +30,25 @@ func (p Printer) wrapLines(text string, nIndent int) string {
|
|||
|
||||
var builder strings.Builder
|
||||
|
||||
for i, line := range lines {
|
||||
extraIndent := ""
|
||||
extraIndentConditions := []extraIndentConditiion{
|
||||
{
|
||||
pattern: regexp.MustCompile(`^` + symbolBullet + `\s.*$`),
|
||||
indent: " ",
|
||||
},
|
||||
{
|
||||
pattern: regexp.MustCompile(`^[0-9]{1}\.\s.*$`),
|
||||
indent: " ",
|
||||
},
|
||||
{
|
||||
pattern: regexp.MustCompile(`^[0-9]{2}\.\s.*$`),
|
||||
indent: " ",
|
||||
},
|
||||
}
|
||||
|
||||
if strings.HasPrefix(line, symbolBullet) {
|
||||
extraIndent = " "
|
||||
}
|
||||
for ind, line := range lines {
|
||||
builder.WriteString(wrapLine(line, separator+extraIndent(line, extraIndentConditions), p.lineWrapCharacterLimit-nIndent))
|
||||
|
||||
builder.WriteString(wrapLine(line, separator+extraIndent, p.lineWrapCharacterLimit-nIndent))
|
||||
|
||||
if i < len(lines)-1 {
|
||||
if ind < len(lines)-1 {
|
||||
builder.WriteString(separator)
|
||||
}
|
||||
}
|
||||
|
@ -69,3 +84,13 @@ func wrapLine(line, separator string, charLimit int) string {
|
|||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func extraIndent(line string, conditions []extraIndentConditiion) string {
|
||||
for ind := range conditions {
|
||||
if conditions[ind].pattern.MatchString(line) {
|
||||
return conditions[ind].indent
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue