Editor blocks: - Math with KaTeX, inline ($...$) and as blocks ($$...$$). Clicking a formula opens its LaTeX source. - Mermaid diagrams. The text is stored and each client draws it, with a live preview while editing. Mermaid uses strict security. - Draw.io and Excalidraw drawings, stored as SVG attachments that carry the editable scene. Draw.io opens diagrams.net in a frame (address set by DOCWELL_DRAWIO_URL). Excalidraw loads React only when opened. - A table of contents block that follows the page's headings. - "[[" page links, and following a page link inside the app (Ctrl/Cmd click while editing). Mermaid and Excalidraw are handed in by the host, so the single-file mobile bridge leaves them out. There diagrams show as their text and drawings as pictures. Pages now record which pages they link to, kept current on every save and backfilled at startup. A page lists the pages linking to it that the reader can open. Any editor can mark a page as a template, and an empty page offers the workspace's templates. Applying one copies its content as a history version, and an untitled page also takes the template's title. Markdown and HTML export keep Mermaid, math, drawings and mentions, and Markdown import turns mermaid fences back into diagrams. Attachments named .svg are typed image/svg+xml and served inline under the existing sandbox CSP, so drawings display. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package httpapi
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"docwell/server/internal/access"
|
|
"docwell/server/internal/directory"
|
|
)
|
|
|
|
// LinkService is the part of directory.Service for backlinks and templates.
|
|
type LinkService interface {
|
|
Backlinks(ctx context.Context, c access.Caller, pageID string) ([]directory.PageItem, error)
|
|
ListTemplates(ctx context.Context, c access.Caller, wsID string) ([]directory.Template, error)
|
|
ApplyTemplate(ctx context.Context, c access.Caller, pageID, templateID string) (directory.Page, error)
|
|
}
|
|
|
|
func (a *api) linkRoutes(mux *routeMux) {
|
|
mux.HandleFunc("GET /api/v1/pages/{id}/backlinks", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.Backlinks(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("GET /api/v1/workspaces/{id}/templates", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
list, err := a.dir.ListTemplates(r.Context(), caller(r), r.PathValue("id"))
|
|
a.respond(w, list, err)
|
|
}))
|
|
mux.HandleFunc("POST /api/v1/pages/{id}/apply-template", a.requireUser(func(w http.ResponseWriter, r *http.Request) {
|
|
var in struct{ Template string }
|
|
if !a.decode(w, r, &in) {
|
|
return
|
|
}
|
|
p, err := a.dir.ApplyTemplate(r.Context(), caller(r), r.PathValue("id"), in.Template)
|
|
a.respond(w, p, err)
|
|
}))
|
|
}
|