diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 10:10:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 10:10:50 +0300 |
| commit | c053f1e04ffb0fb89743cc7bc5154efaf6e8a0bf (patch) | |
| tree | 282736aff772a899f1f1a0884c380cc82d1544c6 /internal/daemon | |
| parent | 00a015a9642baee69def9a104602b4d59f980c63 (diff) | |
Add HTML OutputFormat and report API support (ask task 03)
- Add FormatHTML with parse/string and HTMLReporter on existing report path
- Emit minimal HTML document with escaped title, description, and pre table
- Daemon /report sets text/html Content-Type for HTML format
- Integration fixtures and tests for HTML
Made-with: Cursor
Diffstat (limited to 'internal/daemon')
| -rw-r--r-- | internal/daemon/daemon.go | 2 | ||||
| -rw-r--r-- | internal/daemon/daemon_test.go | 22 |
2 files changed, 24 insertions, 0 deletions
diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index a7de45f..13e7311 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -156,6 +156,8 @@ func reportContentType(f goprecords.OutputFormat) string { return "text/markdown; charset=utf-8" case goprecords.FormatGemtext: return "text/gemini; charset=utf-8" + case goprecords.FormatHTML: + return "text/html; charset=utf-8" default: return "text/plain; charset=utf-8" } diff --git a/internal/daemon/daemon_test.go b/internal/daemon/daemon_test.go index 9f25ca3..87b3dd8 100644 --- a/internal/daemon/daemon_test.go +++ b/internal/daemon/daemon_test.go @@ -91,6 +91,28 @@ func TestReportQueryAliases(t *testing.T) { } } +func TestReportHTMLContentType(t *testing.T) { + fixtures := filepath.Join("..", "..", "fixtures") + srv := httptest.NewServer(Handler(fixtures)) + defer srv.Close() + res, err := http.Get(srv.URL + "/report?OutputFormat=HTML&limit=2") + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + if res.StatusCode != http.StatusOK { + t.Fatalf("status %d", res.StatusCode) + } + if ct := res.Header.Get("Content-Type"); ct != "text/html; charset=utf-8" { + t.Fatalf("Content-Type %q", ct) + } + b, _ := io.ReadAll(res.Body) + body := string(b) + if !strings.Contains(body, "<!DOCTYPE html>") || !strings.Contains(body, "<pre>") { + t.Fatalf("expected HTML body, got %q", body) + } +} + func TestReportGemtextContentType(t *testing.T) { fixtures := filepath.Join("..", "..", "fixtures") srv := httptest.NewServer(Handler(fixtures)) |
