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 {
|
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
|
||||||
|
|
|
@ -5,10 +5,16 @@
|
||||||
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
|
||||||
|
@ -24,16 +30,25 @@ func (p Printer) wrapLines(text string, nIndent int) string {
|
||||||
|
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
|
||||||
for i, line := range lines {
|
extraIndentConditions := []extraIndentConditiion{
|
||||||
extraIndent := ""
|
{
|
||||||
|
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) {
|
for ind, line := range lines {
|
||||||
extraIndent = " "
|
builder.WriteString(wrapLine(line, separator+extraIndent(line, extraIndentConditions), p.lineWrapCharacterLimit-nIndent))
|
||||||
}
|
|
||||||
|
|
||||||
builder.WriteString(wrapLine(line, separator+extraIndent, p.lineWrapCharacterLimit-nIndent))
|
if ind < len(lines)-1 {
|
||||||
|
|
||||||
if i < len(lines)-1 {
|
|
||||||
builder.WriteString(separator)
|
builder.WriteString(separator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,3 +84,13 @@ 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 ""
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue