wiki/editor.go
2020-06-09 20:36:41 +02:00

34 lines
712 B
Go

package main
import (
"bytes"
"html/template"
)
type editorJsJson struct {
Page string
ContentType string
BaseURL string
Data template.JS
}
func renderEditor(pageName, inputText, contentType string, baseurl string) (template.HTML, error) {
if contentType == "json" {
t, err := template.ParseFiles("templates/editorjs.html")
if err != nil {
return "", err
}
if inputText == "" {
inputText = "null"
}
data := editorJsJson{Page: pageName, Data: template.JS(inputText), ContentType: contentType, BaseURL: baseurl}
var buf bytes.Buffer
err = t.Execute(&buf, data)
if err != nil {
return "", err
}
return template.HTML(buf.String()), nil
}
return "", nil
}