Much progress

This commit is contained in:
Maximilian Friedersdorff 2025-01-27 22:28:18 +00:00
parent ca35e6760d
commit c6975d3814
6 changed files with 133 additions and 19 deletions

View file

@ -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