Skip to content

Commit d6c6357

Browse files
committed
Change html formatted message newline to html break
1 parent b0bf4a3 commit d6c6357

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

internal/message/message.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package message
33
import (
44
"bytes"
55
"fmt"
6+
"strings"
67
"text/template"
78
"time"
89

@@ -15,10 +16,11 @@ const (
1516
)
1617

1718
type Event struct {
18-
Summary string
19-
StartTime string
20-
EndTime string
21-
Description string
19+
Summary string
20+
StartTime string
21+
EndTime string
22+
HtmlDescription string
23+
TxtDescription string
2224
}
2325

2426
type TemplatedMessage struct {
@@ -53,10 +55,11 @@ func NewTemplatedMessage(htmlTemplate, txtTemplate string, events []ical.Event,
5355
description = ""
5456
}
5557
evt := Event{
56-
Summary: summary,
57-
StartTime: startTime.Format(timeLayout),
58-
EndTime: endTime.Format(timeLayout),
59-
Description: description,
58+
Summary: summary,
59+
StartTime: startTime.Format(timeLayout),
60+
EndTime: endTime.Format(timeLayout),
61+
HtmlDescription: strings.ReplaceAll(strings.ReplaceAll(description, "\\n", "<br>"), "\\", ""),
62+
TxtDescription: description,
6063
}
6164
if startTime.Hour() == 0 && startTime.Minute() == 0 {
6265
evt.StartTime = ""

templates/event.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<h3>Events on {{ today }}</h3>
22
<ul>
3-
{{range .Events}}
4-
<li>{{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .Description `` }}
5-
({{.Description}}) {{end}}</li>
6-
{{end}}
3+
{{range .Events}}
4+
<li>{{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .HtmlDescription `` }}
5+
({{.HtmlDescription}}) {{end}}</li>
6+
{{end}}
77
</ul>

templates/event.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Events on {{ today }}:
22
{{range .Events}}
3-
- {{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .Description `` }}
4-
({{.Description}}) {{end}}
3+
- {{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .TxtDescription `` }}
4+
({{.TxtDescription}}) {{end}}
55
{{end}}

0 commit comments

Comments
 (0)