Commit d201269

Eric Bower  ·  2026-01-16 10:39:06 -0500 EST
parent b224595
feat(prose): added horizontal rule to list parser

refactor(prose): replace ul/li with custom list impl
2 files changed,  +75, -53
+70, -49
......@@ -1,51 +1,72 @@
11 {{define "list"}}
2-{{$indent := 0}}
3-{{$mod := 0}}
4-<ul style="list-style-type: {{.ListType}};">
5- {{range .Items}}
6- {{if lt $indent .Indent}}
7- <ul>
8- {{else if gt $indent .Indent}}
9-
10- {{$mod = minus $indent .Indent}}
11- {{range $y := intRange 1 $mod}}
12- </li></ul>
13- {{end}}
14-
15- {{else}}
16- </li>
17- {{end}}
18- {{$indent = .Indent}}
19-
20- {{if .IsText}}
21- {{if .Value}}
22- <li>{{.Value}}
23- {{end}}
24- {{end}}
25-
26- {{if .IsURL}}
27- <li><a href="{{.URL}}">{{.Value}}</a>
28- {{end}}
29-
30- {{if .IsImg}}
31- <li><img src="{{.URL}}" alt="{{.Value}}" />
32- {{end}}
33-
34- {{if .IsBlock}}
35- <li><blockquote>{{.Value}}</blockquote>
36- {{end}}
37-
38- {{if .IsHeaderOne}}
39- </ul><h2 class="text-xl font-bold">{{.Value}}</h2><ul style="list-style-type: {{$.ListType}};">
40- {{end}}
41-
42- {{if .IsHeaderTwo}}
43- </ul><h3 class="text-lg font-bold">{{.Value}}</h3><ul style="list-style-type: {{$.ListType}};">
44- {{end}}
45-
46- {{if .IsPre}}
47- <li><pre>{{.Value}}</pre>
48- {{end}}
49- {{end}}
50-</ul>
2+ {{$indent := 0}}
3+ {{$mod := 0}}
4+
5+ <div role="list">
6+ {{range .Items}}
7+ {{if lt $indent .Indent}}
8+ <div role="list">
9+ {{else if gt $indent .Indent}}
10+ {{$mod = minus $indent .Indent}}
11+ {{range $y := intRange 1 $mod}}
12+ </div>
13+ {{end}}
14+ {{end}}
15+
16+ {{$indent = .Indent}}
17+
18+ {{if .IsText}}
19+ <div role="listitem">
20+ <div class="listitem-bullet">•</div>
21+ <div class="listitem-text">{{.Value}}</div>
22+ </div>
23+ {{end}}
24+
25+ {{if .IsURL}}
26+ <div role="listitem">
27+ <div class="listitem-bullet">•</div>
28+ <a class="listitem-text" href="{{.URL}}">{{.Value}}</a>
29+ </div>
30+ {{end}}
31+
32+ {{if .IsImg}}
33+ <div role="listitem">
34+ <div class="listitem-bullet">•</div>
35+ <img class="listeitem-text" src="{{.URL}}" alt="{{.Value}}" />
36+ </div>
37+ {{end}}
38+
39+ {{if .IsBlock}}
40+ <div role="listitem">
41+ <div class="listitem-bullet">•</div>
42+ <blockquote class="listitem-text">{{.Value}}</blockquote>
43+ </div>
44+ {{end}}
45+
46+ {{if .IsPre}}
47+ <div role="listitem">
48+ <div class="listitem-bullet">•</div>
49+ <pre class="listitem-text">{{.Value}}</pre>
50+ </div>
51+ {{end}}
52+
53+ {{if .IsHeaderOne}}
54+ </div>
55+ <h2 class="text-xl font-bold">{{.Value}}</h2>
56+ <div role="list" aria-label="{{.Value}}">
57+ {{end}}
58+
59+ {{if .IsHeaderTwo}}
60+ </div>
61+ <h3 class="text-lg font-bold">{{.Value}}</h3>
62+ <div role="list" aria-label="{{.Value}}">
63+ {{end}}
64+
65+ {{if .IsHr}}
66+ </div>
67+ <hr />
68+ <div role="list" aria-label="{{.Value}}">
69+ {{end}}
70+ {{end}}
71+ </div>
5172 {{end}}
+5, -4
......@@ -39,6 +39,7 @@ type ListItem struct {
3939 IsHeaderTwo bool
4040 IsImg bool
4141 IsPre bool
42+ IsHr bool
4243 Indent int
4344 }
4445
......@@ -50,7 +51,6 @@ type ListMetaData struct {
5051 Image string
5152 ImageCard string
5253 Layout string
53- ListType string // https://developer.mozilla.org/en-US/docs/Web/CSS/list-style-type
5454 PublishAt *time.Time
5555 Tags []string
5656 Title string
......@@ -69,6 +69,7 @@ var imgToken = "=<"
6969 var headerOneToken = "#"
7070 var headerTwoToken = "##"
7171 var preToken = "```"
72+var hrToken = "=="
7273
7374 type SplitToken struct {
7475 Key string
......@@ -121,8 +122,6 @@ func TokenToMetaField(meta *ListMetaData, token *SplitToken) error {
121122 meta.Image = token.Value
122123 case "image_card":
123124 meta.ImageCard = token.Value
124- case "list_type":
125- meta.ListType = token.Value
126125 case "draft":
127126 if token.Value == "true" {
128127 meta.Hidden = true
......@@ -210,6 +209,9 @@ func parseItem(meta *ListMetaData, li *ListItem, prevItem *ListItem, pre bool, m
210209 } else if strings.HasPrefix(li.Value, headerOneToken) {
211210 li.IsHeaderOne = true
212211 li.Value = strings.Replace(li.Value, headerOneToken, "", 1)
212+ } else if strings.HasPrefix(li.Value, hrToken) {
213+ li.IsHr = true
214+ li.Value = ""
213215 } else if reIndent.MatchString(li.Value) {
214216 trim := reIndent.ReplaceAllString(li.Value, "")
215217 old := len(li.Value)
......@@ -241,7 +243,6 @@ func ListParseText(text string) *ListParsedText {
241243 Aliases: []string{},
242244 InlineContent: true,
243245 Layout: "default",
244- ListType: "disc",
245246 PublishAt: &time.Time{},
246247 Tags: []string{},
247248 Hidden: false,