Skip to content

Commit 89153a0

Browse files
committed
Handle file ending in list item on HTML conversion
1 parent 4221457 commit 89153a0

File tree

5 files changed

+43
-9
lines changed

5 files changed

+43
-9
lines changed

generator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ func ToHTML(asl ASL) string {
168168
prev = e
169169
})
170170

171+
if prev.Type() == ElementTypes.List() {
172+
b.WriteString("</ul>\n")
173+
}
174+
171175
if isPreformattedMode {
172176
b.WriteString("</pre>")
173177

generator_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,17 @@ func TestToGemtext(t *testing.T) {
2020
func TestToHTML(t *testing.T) {
2121
parsedInput, _ := ParseFile("testdata/input.gmi")
2222
actual := ToHTML(parsedInput)
23-
2423
expectedOutput, _ := os.ReadFile("testdata/output.html")
2524
expected := string(expectedOutput)
26-
2725
if actual != expected {
2826
errorfRaw(t, "html", actual, expected)
2927
}
28+
29+
parsedInput, _ = ParseFile("testdata/input_list_only.gmi")
30+
actual = ToHTML(parsedInput)
31+
expectedOutput, _ = os.ReadFile("testdata/output_list_only.html")
32+
expected = string(expectedOutput)
33+
if actual != expected {
34+
errorfRaw(t, "html_listOnly", actual, expected)
35+
}
3036
}

testdata/input_list_only.gmi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Some
2+
* Bullet
3+
* Points

testdata/output_list_only.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ul>
2+
<li>Some</li>
3+
<li>Bullet</li>
4+
<li>Points</li>
5+
</ul>

testdata/update.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// A helper to update test data generated from input.gmi.
1+
// A helper to update generated test data.
22
package main
33

44
import (
@@ -27,9 +27,10 @@ func printerrln(a ...any) (int, error) {
2727
func main() {
2828
flag.CommandLine.Init("", flag.ContinueOnError)
2929
flag.CommandLine.SetOutput(io.Discard)
30-
updateInputDump := flag.Bool("input-dump", false, "")
31-
updateOutputGMI := flag.Bool("output-gmi", false, "")
32-
updateOutputHTML := flag.Bool("output-html", false, "")
30+
updateDump := flag.Bool("dump", false, "")
31+
updateGMI := flag.Bool("gmi", false, "")
32+
updateHTML := flag.Bool("html", false, "")
33+
updateListOnlyHTML := flag.Bool("list-only-html", false, "")
3334
flag.Parse()
3435

3536
if flag.NArg() > 0 || flag.NFlag() < 1 {
@@ -76,7 +77,12 @@ func main() {
7677
printerrln(err)
7778
}
7879

79-
if *updateInputDump {
80+
listOnlyASL, err := p.ParseFile(filepath.Join(testdataDir, "input_list_only.gmi"))
81+
if err != nil {
82+
printerrln(err)
83+
}
84+
85+
if *updateDump {
8086
if err := os.WriteFile(
8187
filepath.Join(testdataDir, "input.dump"),
8288
[]byte(dumper.Sdump(asl)),
@@ -86,7 +92,7 @@ func main() {
8692
}
8793
}
8894

89-
if *updateOutputGMI {
95+
if *updateGMI {
9096
if err := p.ToGemtextFile(
9197
filepath.Join(testdataDir, "output.gmi"),
9298
asl,
@@ -96,7 +102,7 @@ func main() {
96102
}
97103
}
98104

99-
if *updateOutputHTML {
105+
if *updateHTML {
100106
if err := p.ToHTMLFile(
101107
filepath.Join(testdataDir, "output.html"),
102108
asl,
@@ -105,4 +111,14 @@ func main() {
105111
printerrln(err)
106112
}
107113
}
114+
115+
if *updateListOnlyHTML {
116+
if err := p.ToHTMLFile(
117+
filepath.Join(testdataDir, "output_list_only.html"),
118+
listOnlyASL,
119+
0600,
120+
); err != nil {
121+
printerrln(err)
122+
}
123+
}
108124
}

0 commit comments

Comments
 (0)