Correct capitalization in quoted_reply

This commit is contained in:
Drew DeVault 2019-11-10 13:35:09 -05:00
parent cb7d7a0438
commit 08574104bc
3 changed files with 40 additions and 16 deletions

View file

@ -72,12 +72,16 @@ available always.
{{wrapText .OriginalText 72}}
```
_quote_ function prepends each line with "> " and wraps the text to
72 characters pre line.
_quote_ function prepends each line with "> ".
```
{{quote .OriginalText}}
```
All of the above can be chained together if needed, for example
```
{{wrapText .OriginalText 72 | quote}}
```
# SEE ALSO
*aerc*(1) *aerc-config*(5)

View file

@ -70,39 +70,59 @@ func wrapLine(text string, lineWidth int) string {
if len(words) == 0 {
return text
}
wrapped := words[0]
spaceLeft := lineWidth - len(wrapped)
var wrapped strings.Builder
wrapped.WriteString(words[0])
spaceLeft := lineWidth - wrapped.Len()
for _, word := range words[1:] {
if len(word)+1 > spaceLeft {
wrapped += "\n" + word
wrapped.WriteRune('\n')
wrapped.WriteString(word)
spaceLeft = lineWidth - len(word)
} else {
wrapped += " " + word
wrapped.WriteRune(' ')
wrapped.WriteString(word)
spaceLeft -= 1 + len(word)
}
}
return wrapped
return wrapped.String()
}
func wrapText(text string, lineWidth int) string {
text = strings.ReplaceAll(text, "\r\n", "\n")
lines := strings.Split(text, "\n")
var wrapped string
var wrapped strings.Builder
for _, line := range lines {
wrapped += wrapLine(line, lineWidth) + "\n"
switch {
case line == "":
// deliberately left blank
case line[0] == '>':
// leave quoted text alone
wrapped.WriteString(line)
default:
wrapped.WriteString(wrapLine(line, lineWidth))
}
wrapped.WriteRune('\n')
}
return wrapped
return wrapped.String()
}
// Wraping lines at 70 so that with the "> " of the quote it is under 72
// quote prepends "> " in front of every line in text
func quote(text string) string {
text = strings.ReplaceAll(text, "\r\n", "\n")
lines := strings.Split(text, "\n")
var quoted strings.Builder
for _, line := range lines {
if line == "" {
quoted.WriteString(">\n")
}
quoted.WriteString("> ")
quoted.WriteString(line)
quoted.WriteRune('\n')
}
quoted := "> " + wrapText(text, 70)
quoted = strings.ReplaceAll(quoted, "\n", "\n> ")
return quoted
return quoted.String()
}
var templateFuncs = template.FuncMap{

View file

@ -1,2 +1,2 @@
on {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}, {{(index .OriginalFrom 0).Name}} wrote:
{{quote .OriginalText}}
On {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}, {{(index .OriginalFrom 0).Name}} wrote:
{{wrapText .OriginalText 72 | quote }}