Editor:
- Toggles (Tiptap Details). Open state is per reader, not saved.
- Embeds for YouTube, Vimeo, Loom, Figma, CodePen, Spotify, Google Docs
and Maps, in sandboxed frames. Other addresses become link cards.
- Link cards with title, description and picture read by docwell-server
(GET /link-preview). The fetcher refuses private, loopback, link-local
and CGNAT addresses after DNS resolution, redirects included.
- Block links: a margin button gives a block a short id and copies
/p/<id>#b-<block>. Opening one jumps to the block and flashes it.
- Markdown, HTML and PDF exports handle the new blocks; HTML import reads
<details> as a toggle.
Pages and spaces:
- History gets a Changes view: block and word diff against the previous
version or the page as it is now.
- Archive: archived pages leave the tree and become read-only but stay
readable; a space's Archive lists them with Unarchive. New migration
(pages.archived_at) and page.archived / page.unarchived webhook events.
- Full space export (GET /spaces/{id}/export): a zip of Markdown or HTML
files with subpages in folders, an index, and attachments under _files/.
Links between exported pages and to attachments become relative paths.
Desktop 1.0:
- Several servers, each with its own sign-in; old settings files carry over.
- Session tokens in the system keychain (go-keyring), moved out of
localStorage on first start.
- Native menu bar (File, Edit, View, Window, Help) with a Server submenu.
- docwell:// links may point at a block.
- Release workflow builds Windows NSIS, macOS DMG and Linux deb, rpm and
AppImage installers and attaches them to the release;
build/set-version.mjs stamps the version into their metadata.
Not yet run: the release workflow, the desktop menus by eye, and macOS or
Linux builds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
3.1 KiB
Go
83 lines
3.1 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package convert
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestRichBlocks(t *testing.T) {
|
|
doc, err := Parse([]byte(`{"type":"doc","content":[
|
|
{"type":"tableOfContents"},
|
|
{"type":"mermaid","attrs":{"code":"graph TD\n A-->B"}},
|
|
{"type":"blockMath","attrs":{"latex":"E=mc^2"}},
|
|
{"type":"paragraph","content":[{"type":"text","text":"x is "},{"type":"inlineMath","attrs":{"latex":"x<1"}},
|
|
{"type":"text","text":" says "},{"type":"mention","attrs":{"id":"u1","label":"Ann"}}]},
|
|
{"type":"drawio","attrs":{"src":"/api/v1/files/f1"}},
|
|
{"type":"excalidraw","attrs":{"src":""}}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
md := Markdown(doc, Options{})
|
|
for _, want := range []string{"```mermaid\ngraph TD\n A-->B\n```", "$$\nE=mc^2\n$$", "x is $x<1$ says @Ann", ""} {
|
|
if !strings.Contains(md, want) {
|
|
t.Errorf("markdown lacks %q:\n%s", want, md)
|
|
}
|
|
}
|
|
h := HTML(doc, Options{})
|
|
for _, want := range []string{`<pre class="mermaid">graph TD`, `\[E=mc^2\]`, `\(x<1\)`, `@Ann`, `<img src="/api/v1/files/f1"`} {
|
|
if !strings.Contains(h, want) {
|
|
t.Errorf("html lacks %q:\n%s", want, h)
|
|
}
|
|
}
|
|
|
|
back, err := FromMarkdown(md)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if back.Content[0].Type != "mermaid" || back.Content[0].attr("code") != "graph TD\n A-->B" {
|
|
t.Fatalf("mermaid did not round-trip: %+v", back.Content[0])
|
|
}
|
|
}
|
|
|
|
func TestTogglesEmbedsAndPageLinks(t *testing.T) {
|
|
doc, err := Parse([]byte(`{"type":"doc","content":[
|
|
{"type":"details","content":[
|
|
{"type":"detailsSummary","content":[{"type":"text","text":"More"}]},
|
|
{"type":"detailsContent","content":[{"type":"paragraph","content":[{"type":"text","text":"Hidden"}]}]}]},
|
|
{"type":"embed","attrs":{"url":"https://youtu.be/dQw4w9WgXcQ"}},
|
|
{"type":"linkCard","attrs":{"url":"https://example.com/a","title":"Example","description":"About it"}},
|
|
{"type":"linkCard","attrs":{"url":"javascript:alert(1)","title":"Bad"}},
|
|
{"type":"paragraph","content":[{"type":"text","text":"see","marks":[{"type":"link","attrs":{"href":"/p/abc123#b-x1y2z3w4"}}]}]}]}`))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
o := Options{PageURL: func(id, frag string) string { return "../" + id + ".md" + frag }}
|
|
md := Markdown(doc, o)
|
|
for _, want := range []string{"<details>\n<summary>More</summary>\n\nHidden\n\n</details>", "[https://youtu.be/dQw4w9WgXcQ](https://youtu.be/dQw4w9WgXcQ)",
|
|
"[Example](https://example.com/a) — About it", "[see](../abc123.md#b-x1y2z3w4)"} {
|
|
if !strings.Contains(md, want) {
|
|
t.Errorf("markdown lacks %q:\n%s", want, md)
|
|
}
|
|
}
|
|
h := HTML(doc, o)
|
|
for _, want := range []string{"<details>\n<summary>More</summary>\n<p>Hidden</p>\n</details>", `<a href="https://example.com/a">Example</a><br>About it`, `<a href="../abc123.md#b-x1y2z3w4">see</a>`} {
|
|
if !strings.Contains(h, want) {
|
|
t.Errorf("html lacks %q:\n%s", want, h)
|
|
}
|
|
}
|
|
if strings.Contains(md+h, "javascript:") {
|
|
t.Errorf("unsafe link kept:\n%s\n%s", md, h)
|
|
}
|
|
|
|
back, err := FromHTML(h)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
d := back.Content[0]
|
|
if d.Type != "details" || PlainText(d.Content[0]) != "More" || PlainText(d.Content[1]) != "Hidden" {
|
|
t.Fatalf("details did not round-trip: %+v", d)
|
|
}
|
|
}
|