Much progress
This commit is contained in:
parent
ca35e6760d
commit
c6975d3814
6 changed files with 133 additions and 19 deletions
|
|
@ -5,19 +5,21 @@ package notes
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.gwairfelin.com/max/gonotes/internal/conf"
|
||||
"github.com/yuin/goldmark"
|
||||
"github.com/yuin/goldmark/extension"
|
||||
)
|
||||
|
||||
// Note is the central data structure. It can be Saved, Rendered and Loaded
|
||||
// using the Save, Render and LoadNote functions.
|
||||
type Note struct {
|
||||
Title string
|
||||
BodyRendered string
|
||||
BodyRendered template.HTML
|
||||
Body []byte
|
||||
}
|
||||
|
||||
|
|
@ -34,11 +36,17 @@ func (n *Note) Save() error {
|
|||
// Render the markdown content of the note to HTML
|
||||
func (n *Note) Render() {
|
||||
var buf bytes.Buffer
|
||||
err := goldmark.Convert(n.Body, &buf)
|
||||
md := goldmark.New(
|
||||
goldmark.WithExtensions(
|
||||
extension.TaskList,
|
||||
),
|
||||
)
|
||||
err := md.Convert(n.Body, &buf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
n.BodyRendered = buf.String()
|
||||
|
||||
n.BodyRendered = template.HTML(buf.String())
|
||||
}
|
||||
|
||||
// Load a note from the disk. The path is derived from the title
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue