33 lines
658 B
Go
33 lines
658 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"html/template"
|
|
)
|
|
|
|
type editorJsJson struct {
|
|
Page string
|
|
ContentType string
|
|
Data template.JS
|
|
}
|
|
|
|
func renderEditor(pageName, inputText, contentType 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}
|
|
var buf bytes.Buffer
|
|
err = t.Execute(&buf, data)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return template.HTML(buf.String()), nil
|
|
}
|
|
return "", nil
|
|
}
|