Compare commits

..

No commits in common. "fa2c75ebca90bd336e67b591b3de44c7106d253c" and "527fd069df08bc7158e73fdb15e70669b3d7ab09" have entirely different histories.

2 changed files with 8 additions and 34 deletions

View file

@ -40,7 +40,6 @@ func (p Printer) convertHTMLToText(text string, wrapLines bool) string {
if wrapLines { if wrapLines {
return p.wrapLines(builder.String(), 0) return p.wrapLines(builder.String(), 0)
} }
return builder.String() return builder.String()
case html.TextToken: case html.TextToken:
text := token.Token().Data text := token.Token().Data

View file

@ -5,16 +5,10 @@
package printer package printer
import ( import (
"regexp"
"strings" "strings"
"unicode" "unicode"
) )
type extraIndentConditiion struct {
pattern *regexp.Regexp
indent string
}
func (p Printer) wrapLines(text string, nIndent int) string { func (p Printer) wrapLines(text string, nIndent int) string {
if nIndent >= p.lineWrapCharacterLimit { if nIndent >= p.lineWrapCharacterLimit {
nIndent = 0 nIndent = 0
@ -30,25 +24,16 @@ func (p Printer) wrapLines(text string, nIndent int) string {
var builder strings.Builder var builder strings.Builder
extraIndentConditions := []extraIndentConditiion{ for i, line := range lines {
{ extraIndent := ""
pattern: regexp.MustCompile(`^` + symbolBullet + `\s.*$`),
indent: " ", if strings.HasPrefix(line, symbolBullet) {
}, extraIndent = " "
{
pattern: regexp.MustCompile(`^[0-9]{1}\.\s.*$`),
indent: " ",
},
{
pattern: regexp.MustCompile(`^[0-9]{2}\.\s.*$`),
indent: " ",
},
} }
for ind, line := range lines { builder.WriteString(wrapLine(line, separator+extraIndent, p.lineWrapCharacterLimit-nIndent))
builder.WriteString(wrapLine(line, separator+extraIndent(line, extraIndentConditions), p.lineWrapCharacterLimit-nIndent))
if ind < len(lines)-1 { if i < len(lines)-1 {
builder.WriteString(separator) builder.WriteString(separator)
} }
} }
@ -84,13 +69,3 @@ func wrapLine(line, separator string, charLimit int) string {
return builder.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 ""
}