First implementation of web based editor to HTML pipeline
This commit is contained in:
18
cmd/articles/markdown.go
Normal file
18
cmd/articles/markdown.go
Normal file
@ -0,0 +1,18 @@
|
||||
package articles
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/yuin/goldmark"
|
||||
)
|
||||
|
||||
func ConvertToHTML(markdown string) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
if err := goldmark.Convert([]byte(markdown), &buf); err != nil {
|
||||
return "", fmt.Errorf("error: cmd/articles/markdown.go ConvertToHTML goldmark.Convert(): %v", err)
|
||||
}
|
||||
|
||||
return buf.String(), nil
|
||||
}
|
23
cmd/handlers/editor.go
Normal file
23
cmd/handlers/editor.go
Normal file
@ -0,0 +1,23 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"streifling.com/jason/cpolis/cmd/articles"
|
||||
)
|
||||
|
||||
func HandleFinishedEdit() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
md := r.PostFormValue("editor-textarea")
|
||||
|
||||
html, err := articles.ConvertToHTML(md)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
fmt.Println(html)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user