Add clickable Markdown checkboxes (#182)

This commit is contained in:
Thomas Miceli
2023-12-26 03:23:47 +01:00
parent 0753c5cb54
commit 85e2da054b
11 changed files with 177 additions and 9 deletions

View File

@ -787,3 +787,39 @@ func forks(ctx echo.Context) error {
setData(ctx, "revision", "HEAD")
return html(ctx, "forks.html")
}
func checkbox(ctx echo.Context) error {
filename := ctx.FormValue("file")
checkboxNb := ctx.FormValue("checkbox")
i, err := strconv.Atoi(checkboxNb)
if err != nil {
return errorRes(400, "Invalid number", nil)
}
gist := getData(ctx, "gist").(*db.Gist)
file, err := gist.File("HEAD", filename, false)
if err != nil {
return errorRes(500, "Error getting file content", err)
} else if file == nil {
return notFound("File not found")
}
markdown, err := render.Checkbox(file.Content, i)
if err != nil {
return errorRes(500, "Error checking checkbox", err)
}
if err = gist.AddAndCommitFile(&db.FileDTO{
Filename: filename,
Content: markdown,
}); err != nil {
return errorRes(500, "Error adding and committing files", err)
}
if err = gist.UpdatePreviewAndCount(); err != nil {
return errorRes(500, "Error updating the gist", err)
}
return plainText(ctx, 200, "ok")
}

View File

@ -265,6 +265,7 @@ func NewServer(isDev bool) *Server {
g3.GET("/likes", likes)
g3.POST("/fork", fork, logged)
g3.GET("/forks", forks)
g3.PUT("/checkbox", checkbox, logged, writePermission)
}
}