Return errors properly from gmi2html
This commit is contained in:
@@ -22,7 +22,10 @@ func runApp() error {
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
// 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
|
||||
func Gmi2html(text string, title string) string {
|
||||
func Gmi2html(text string, title string) (string, error) {
|
||||
content := convertGeminiContent(text)
|
||||
|
||||
// Handle any template errors with container
|
||||
@@ -26,10 +26,10 @@ func Gmi2html(text string, title string) string {
|
||||
})
|
||||
if err != nil {
|
||||
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
|
||||
|
||||
@@ -61,7 +61,7 @@ func TestConvertGeminiContent(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"
|
||||
result := Gmi2html(sample, "Gemini Test")
|
||||
result, _ := Gmi2html(sample, "Gemini Test")
|
||||
|
||||
// Check that it contains the expected elements
|
||||
if !strings.Contains(result, "<title>Gemini Test</title>") {
|
||||
|
||||
@@ -51,7 +51,8 @@ body {
|
||||
color: var(--text-color);
|
||||
/* background-color: var(--bg-color); */
|
||||
max-width: 34rem;
|
||||
margin: 0 auto;
|
||||
/* margin: 0 auto; */
|
||||
margin-left: 2rem;
|
||||
padding: 1rem 1rem;
|
||||
font-size: 16px;
|
||||
text-align: justify;
|
||||
|
||||
Reference in New Issue
Block a user