Compare commits
3 Commits
47340aebb8
...
v0.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 8126ded0a6 | |||
| 25c39036d3 | |||
| f78a89c56c |
7
Makefile
7
Makefile
@@ -16,7 +16,7 @@ clean:
|
||||
|
||||
# Test
|
||||
test:
|
||||
go test -race ./...
|
||||
go test ./...
|
||||
|
||||
tidy:
|
||||
go mod tidy
|
||||
@@ -36,7 +36,10 @@ lintfix: fmt
|
||||
|
||||
build: clean
|
||||
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:
|
||||
go list -m -u all
|
||||
|
||||
@@ -22,7 +22,10 @@ func runApp() error {
|
||||
return err
|
||||
}
|
||||
|
||||
html := gmi2html.Gmi2html(string(data), "")
|
||||
html, err := gmi2html.Gmi2html(string(data), "", false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = fmt.Fprintf(os.Stdout, "%s", html)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
11
gmi2html.go
11
gmi2html.go
@@ -12,10 +12,13 @@ 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, contentOnly bool) (string, error) {
|
||||
content := convertGeminiContent(text)
|
||||
|
||||
// Handle any template errors with container
|
||||
if contentOnly {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
var buffer bytes.Buffer
|
||||
err := containerTmpl.Execute(&buffer, struct {
|
||||
Title string
|
||||
@@ -26,10 +29,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", false)
|
||||
|
||||
// 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