diff --git a/cethttp/editor.go b/cethttp/editor.go index ca7cf1c..1ff19c4 100644 --- a/cethttp/editor.go +++ b/cethttp/editor.go @@ -57,9 +57,6 @@ const editorTemplate = ` background-color: #ffffff; } - - - @@ -74,16 +71,15 @@ const editorTemplate = `
-
{{.MarkdownContent}}
+
+ + - ` diff --git a/cethttp/editor_handlers.go b/cethttp/editor_handlers.go index ad9372d..b7b169a 100644 --- a/cethttp/editor_handlers.go +++ b/cethttp/editor_handlers.go @@ -1,6 +1,7 @@ package cethttp import ( + "database/sql" "net/http" "strconv" @@ -31,7 +32,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) { editedTitle := r.FormValue("title") // Update the post content. - post.Content = editedContent + post.GemtextContent = sql.NullString{String: editedContent, Valid: true} post.Title = editedTitle // Save the edited post to the database. diff --git a/cetvorke b/cetvorke index e7c2c3b..862afa0 100755 Binary files a/cetvorke and b/cetvorke differ diff --git a/database/post.go b/database/post.go index e2334c5..90cecba 100644 --- a/database/post.go +++ b/database/post.go @@ -3,9 +3,8 @@ package database import ( "database/sql" "fmt" + "strings" "time" - - "github.com/russross/blackfriday/v2" ) type Post struct { @@ -25,10 +24,49 @@ func (p *Post) GemtextPage() string { } func (p *Post) HTMLPage() string { - extensions := blackfriday.CommonExtensions | blackfriday.HardLineBreak - result := fmt.Sprintf("

%s

\n%s", p.Title, blackfriday.Run([]byte(p.MarkdownContent), blackfriday.WithExtensions(extensions))) - result += fmt.Sprintf("%s", p.Date) - return result + var content string + if p.GemtextContent.Valid { + content = p.GemtextContent.String + if strings.HasPrefix(content, "{") { + content = strings.TrimPrefix(content, "{") + } + if strings.HasSuffix(content, "true}") { + content = strings.TrimSuffix(content, "true}") + } + } else { + content = "" + } + + lines := strings.Split(content, "\n") + var htmlLines []string + + for _, line := range lines { + if strings.HasPrefix(line, "#") { + htmlLines = append(htmlLines, "

"+line[1:]+"

") + } else if strings.HasPrefix(line, "##") { + htmlLines = append(htmlLines, "

"+line[2:]+"

") + } else if strings.HasPrefix(line, "###") { + htmlLines = append(htmlLines, "

"+line[3:]+"

") + } else if strings.HasPrefix(line, "* ") { + htmlLines = append(htmlLines, "") + } else if strings.HasPrefix(line, ">") { + htmlLines = append(htmlLines, "
"+line[1:]+"
") + } else if strings.HasPrefix(line, "=>") { + parts := strings.Fields(line[2:]) + if len(parts) > 1 { + url := parts[0] + text := strings.Join(parts[1:], " ") + htmlLines = append(htmlLines, fmt.Sprintf(`%s`, url, text)) + } else if len(parts) == 1 { + url := parts[0] + htmlLines = append(htmlLines, fmt.Sprintf(`%s`, url, url)) + } + } else { + htmlLines = append(htmlLines, "

"+line+"

") + } + } + + return strings.Join(htmlLines, "\n") } func GetPost(id int) (*Post, error) { diff --git a/go.sum b/go.sum index a54e760..efe9802 100644 --- a/go.sum +++ b/go.sum @@ -11,3 +11,5 @@ github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6 github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +tildegit.org/nihilazo/go-gemtext v0.0.0-20201114202124-890be6eb3742 h1:SE9EroZwQEH3mHxWah4UoHQGgBTa008VIjmh2PqSZXw= +tildegit.org/nihilazo/go-gemtext v0.0.0-20201114202124-890be6eb3742/go.mod h1:KOdDbr9CNSpgmfNfCEjpDhaGPCd86Mp5+XGrZDBKZvo= diff --git a/vendor/modules.txt b/vendor/modules.txt index f93566b..b4841bd 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -16,3 +16,5 @@ github.com/mattn/go-sqlite3 # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2 +# tildegit.org/nihilazo/go-gemtext v0.0.0-20201114202124-890be6eb3742 +## explicit; go 1.15