Return errors properly from gmi2html

This commit is contained in:
2025-03-02 15:00:01 +02:00
parent 47340aebb8
commit f78a89c56c
4 changed files with 10 additions and 6 deletions

View File

@@ -22,7 +22,10 @@ func runApp() error {
return err return err
} }
html := gmi2html.Gmi2html(string(data), "") html, err := gmi2html.Gmi2html(string(data), "")
if err != nil {
return err
}
_, err = fmt.Fprintf(os.Stdout, "%s", html) _, err = fmt.Fprintf(os.Stdout, "%s", html)
if err != nil { if err != nil {
return err return err

View File

@@ -12,7 +12,7 @@ import (
// Based on https://geminiprotocol.net/docs/gemtext-specification.gmi // Based on https://geminiprotocol.net/docs/gemtext-specification.gmi
// Gmi2html converts Gemini text to HTML with proper escaping and wraps it in a container with typography-focused CSS // Gmi2html converts Gemini text to HTML with proper escaping and wraps it in a container with typography-focused CSS
func Gmi2html(text string, title string) string { func Gmi2html(text string, title string) (string, error) {
content := convertGeminiContent(text) content := convertGeminiContent(text)
// Handle any template errors with container // Handle any template errors with container
@@ -26,10 +26,10 @@ func Gmi2html(text string, title string) string {
}) })
if err != nil { if err != nil {
fmt.Printf("Error executing container template: %s\n", err) fmt.Printf("Error executing container template: %s\n", err)
return "" return "", err
} }
return buffer.String() return buffer.String(), nil
} }
// convertGeminiContent converts Gemini text to HTML with proper escaping // convertGeminiContent converts Gemini text to HTML with proper escaping

View File

@@ -61,7 +61,7 @@ func TestConvertGeminiContent(t *testing.T) {
func TestGmi2html(t *testing.T) { func TestGmi2html(t *testing.T) {
sample := "# Hello Gemini\n\nThis is a test document.\n\n=> https://gemini.circumlunar.space/ Project Gemini" sample := "# Hello Gemini\n\nThis is a test document.\n\n=> https://gemini.circumlunar.space/ Project Gemini"
result := Gmi2html(sample, "Gemini Test") result, _ := Gmi2html(sample, "Gemini Test")
// Check that it contains the expected elements // Check that it contains the expected elements
if !strings.Contains(result, "<title>Gemini Test</title>") { if !strings.Contains(result, "<title>Gemini Test</title>") {

View File

@@ -51,7 +51,8 @@ body {
color: var(--text-color); color: var(--text-color);
/* background-color: var(--bg-color); */ /* background-color: var(--bg-color); */
max-width: 34rem; max-width: 34rem;
margin: 0 auto; /* margin: 0 auto; */
margin-left: 2rem;
padding: 1rem 1rem; padding: 1rem 1rem;
font-size: 16px; font-size: 16px;
text-align: justify; text-align: justify;