Phase B items 7-9 of docs/AFFINE.md. Synced pages: "![[" or /Synced page shows another page inside this one, read-only and live. The copy follows the page over a read-only collab connection (CollabProvider readOnly: no edits, no presence) in a nested read-only editor; it folds to its title and opens the page. The node keeps the page's title, so exports (Markdown, HTML, PDF, Word) and readers without a host show it as a link to the page. Settings: Account -> Editor sets, per device, the text size, full width or a date title for new pages, showing properties and backlinks, and code line numbers. The inbox settings choose which notification types the email digest includes (users.notify_email_off, new migration). Split view: Alt+click a page link, or Open beside in the page menu, shows that page in a side pane on wide screens; it survives navigation and reloads of the tab. The page menu opens pages in a new tab on the web, and Ctrl+[ / Ctrl+] go back and forward. Strings are translated into all five languages, the user guide covers the new features, and the mobile editor bundle is rebuilt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
4.2 KiB
Go
109 lines
4.2 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":"text","text":" on "},{"type":"dateMention","attrs":{"date":"2026-11-20"}}]},
|
|
{"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 on 2026-11-20", ""} {
|
|
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`, `<time datetime="2026-11-20">2026-11-20</time>`, `<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)
|
|
}
|
|
}
|
|
|
|
func TestSyncedPageExportsAsPageLink(t *testing.T) {
|
|
doc, err := Parse([]byte(`{"type":"doc","content":[
|
|
{"type":"syncedPage","attrs":{"page":"abc123","title":"Plan","icon":"📋"}},
|
|
{"type":"syncedPage","attrs":{"page":"def456"}}]}`))
|
|
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{"[📋 Plan](../abc123.md)", "[Synced page](../def456.md)"} {
|
|
if !strings.Contains(md, want) {
|
|
t.Errorf("markdown lacks %q:\n%s", want, md)
|
|
}
|
|
}
|
|
if h := HTML(doc, Options{}); !strings.Contains(h, `<a href="/p/abc123">📋 Plan</a>`) {
|
|
t.Errorf("html lacks the page link:\n%s", h)
|
|
}
|
|
if _, err := PDF("T", doc, PDFOptions{}); err != nil {
|
|
t.Errorf("pdf: %v", err)
|
|
}
|
|
if _, err := DOCX("T", doc, DOCXOptions{}); err != nil {
|
|
t.Errorf("docx: %v", err)
|
|
}
|
|
}
|