Compare commits

...

2 Commits

Author SHA1 Message Date
25c39036d3 Additional gccgo Makefile target 2025-03-02 15:00:10 +02:00
f78a89c56c Return errors properly from gmi2html 2025-03-02 15:00:01 +02:00
5 changed files with 15 additions and 8 deletions

View File

@@ -16,7 +16,7 @@ clean:
# Test # Test
test: test:
go test -race ./... go test ./...
tidy: tidy:
go mod tidy go mod tidy
@@ -36,7 +36,10 @@ lintfix: fmt
build: clean build: clean
mkdir ./dist mkdir ./dist
go build -race -o ./dist/gmi2html ./bin/gmi2html/gmi2html.go go build -o ./dist/gmi2html ./bin/gmi2html/gmi2html.go
build-gccgo: clean
go build -compiler=gccgo -o ./dist/gmi2html ./bin/gmi2html/gmi2html.go
show-updates: show-updates:
go list -m -u all go list -m -u all

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;