diff --git a/internal/printer/wrap.go b/internal/printer/wrap.go index c55b6fe..365861e 100644 --- a/internal/printer/wrap.go +++ b/internal/printer/wrap.go @@ -10,6 +10,11 @@ import ( "unicode" ) +type extraIndentConditiion struct { + pattern *regexp.Regexp + indent string +} + func (p Printer) wrapLines(text string, nIndent int) string { if nIndent >= p.lineWrapCharacterLimit { nIndent = 0 @@ -25,11 +30,23 @@ func (p Printer) wrapLines(text string, nIndent int) string { var builder strings.Builder - singleDigitListItemRegex := regexp.MustCompile(`^[0-9]{1}\.\s.*$`) - doubleDigitListItemRegex := regexp.MustCompile(`^[0-9]{2}\.\s.*$`) + extraIndentConditions := []extraIndentConditiion{ + { + pattern: regexp.MustCompile(`^` + symbolBullet + `\s.*$`), + indent: " ", + }, + { + 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(line, singleDigitListItemRegex, doubleDigitListItemRegex), p.lineWrapCharacterLimit-nIndent)) + builder.WriteString(wrapLine(line, separator+extraIndent(line, extraIndentConditions), p.lineWrapCharacterLimit-nIndent)) if ind < len(lines)-1 { builder.WriteString(separator) @@ -68,17 +85,11 @@ func wrapLine(line, separator string, charLimit int) string { return builder.String() } -func extraIndent(line string, singleDigitListItemRegex, doubleDigitListItemRegex *regexp.Regexp) string { - if strings.HasPrefix(line, symbolBullet) { - return " " - } - - if singleDigitListItemRegex.MatchString(line) { - return " " - } - - if doubleDigitListItemRegex.MatchString(line) { - return " " +func extraIndent(line string, conditions []extraIndentConditiion) string { + for ind := range conditions { + if conditions[ind].pattern.MatchString(line) { + return conditions[ind].indent + } } return ""