Skip to content

Commit

Permalink
Change html formatted message newline to html break
Browse files Browse the repository at this point in the history
  • Loading branch information
gueldenstone committed Mar 31, 2023
1 parent b0bf4a3 commit d6c6357
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
19 changes: 11 additions & 8 deletions internal/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package message
import (
"bytes"
"fmt"
"strings"
"text/template"
"time"

Expand All @@ -15,10 +16,11 @@ const (
)

type Event struct {
Summary string
StartTime string
EndTime string
Description string
Summary string
StartTime string
EndTime string
HtmlDescription string
TxtDescription string
}

type TemplatedMessage struct {
Expand Down Expand Up @@ -53,10 +55,11 @@ func NewTemplatedMessage(htmlTemplate, txtTemplate string, events []ical.Event,
description = ""
}
evt := Event{
Summary: summary,
StartTime: startTime.Format(timeLayout),
EndTime: endTime.Format(timeLayout),
Description: description,
Summary: summary,
StartTime: startTime.Format(timeLayout),
EndTime: endTime.Format(timeLayout),
HtmlDescription: strings.ReplaceAll(strings.ReplaceAll(description, "\\n", "<br>"), "\\", ""),
TxtDescription: description,
}
if startTime.Hour() == 0 && startTime.Minute() == 0 {
evt.StartTime = ""
Expand Down
8 changes: 4 additions & 4 deletions templates/event.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h3>Events on {{ today }}</h3>
<ul>
{{range .Events}}
<li>{{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .Description `` }}
({{.Description}}) {{end}}</li>
{{end}}
{{range .Events}}
<li>{{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .HtmlDescription `` }}
({{.HtmlDescription}}) {{end}}</li>
{{end}}
</ul>
4 changes: 2 additions & 2 deletions templates/event.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Events on {{ today }}:
{{range .Events}}
- {{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .Description `` }}
({{.Description}}) {{end}}
- {{.Summary}}{{ if ne .StartTime `` }}: {{.StartTime}} - {{.EndTime}} {{end}} {{ if ne .TxtDescription `` }}
({{.TxtDescription}}) {{end}}
{{end}}

0 comments on commit d6c6357

Please sign in to comment.