Correct capitalization in quoted_reply
This commit is contained in:
parent
cb7d7a0438
commit
08574104bc
3 changed files with 40 additions and 16 deletions
|
@ -72,12 +72,16 @@ available always.
|
||||||
{{wrapText .OriginalText 72}}
|
{{wrapText .OriginalText 72}}
|
||||||
```
|
```
|
||||||
|
|
||||||
_quote_ function prepends each line with "> " and wraps the text to
|
_quote_ function prepends each line with "> ".
|
||||||
72 characters pre line.
|
|
||||||
```
|
```
|
||||||
{{quote .OriginalText}}
|
{{quote .OriginalText}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
All of the above can be chained together if needed, for example
|
||||||
|
```
|
||||||
|
{{wrapText .OriginalText 72 | quote}}
|
||||||
|
```
|
||||||
|
|
||||||
# SEE ALSO
|
# SEE ALSO
|
||||||
|
|
||||||
*aerc*(1) *aerc-config*(5)
|
*aerc*(1) *aerc-config*(5)
|
||||||
|
|
|
@ -70,39 +70,59 @@ func wrapLine(text string, lineWidth int) string {
|
||||||
if len(words) == 0 {
|
if len(words) == 0 {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
wrapped := words[0]
|
var wrapped strings.Builder
|
||||||
spaceLeft := lineWidth - len(wrapped)
|
wrapped.WriteString(words[0])
|
||||||
|
spaceLeft := lineWidth - wrapped.Len()
|
||||||
for _, word := range words[1:] {
|
for _, word := range words[1:] {
|
||||||
if len(word)+1 > spaceLeft {
|
if len(word)+1 > spaceLeft {
|
||||||
wrapped += "\n" + word
|
wrapped.WriteRune('\n')
|
||||||
|
wrapped.WriteString(word)
|
||||||
spaceLeft = lineWidth - len(word)
|
spaceLeft = lineWidth - len(word)
|
||||||
} else {
|
} else {
|
||||||
wrapped += " " + word
|
wrapped.WriteRune(' ')
|
||||||
|
wrapped.WriteString(word)
|
||||||
spaceLeft -= 1 + len(word)
|
spaceLeft -= 1 + len(word)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return wrapped
|
return wrapped.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func wrapText(text string, lineWidth int) string {
|
func wrapText(text string, lineWidth int) string {
|
||||||
text = strings.ReplaceAll(text, "\r\n", "\n")
|
text = strings.ReplaceAll(text, "\r\n", "\n")
|
||||||
lines := strings.Split(text, "\n")
|
lines := strings.Split(text, "\n")
|
||||||
var wrapped string
|
var wrapped strings.Builder
|
||||||
|
|
||||||
for _, line := range lines {
|
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 {
|
func quote(text string) string {
|
||||||
text = strings.ReplaceAll(text, "\r\n", "\n")
|
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)
|
return quoted.String()
|
||||||
quoted = strings.ReplaceAll(quoted, "\n", "\n> ")
|
|
||||||
return quoted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var templateFuncs = template.FuncMap{
|
var templateFuncs = template.FuncMap{
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
on {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}, {{(index .OriginalFrom 0).Name}} wrote:
|
On {{dateFormat .OriginalDate "Mon Jan 2, 2006 at 3:04 PM"}}, {{(index .OriginalFrom 0).Name}} wrote:
|
||||||
{{quote .OriginalText}}
|
{{wrapText .OriginalText 72 | quote }}
|
||||||
|
|
Loading…
Reference in a new issue