Files
tajniak81andClaude Opus 5.5 e441880f2f
CI / desktop (ubuntu-latest) (push) Successful in 1h15m48s
CI / mobile (push) Failing after 3m6s
CI / desktop (macos-latest) (push) Canceled after 0s
CI / desktop (windows-latest) (push) Canceled after 0s
CI / go (Media) (push) Successful in 10m21s
CI / go (Server) (push) Failing after 19m16s
CI / go (Web-App) (push) Successful in 10m27s
CI / frontend (push) Failing after 7m25s
CI / docker (push) Successful in 46m48s
Add the block types Docmost has and Docwell lacked
The slash menu gains Video, Audio, Page break, Footnote, Tabs, Status,
Emoji, Subpages, Synced block and a fifth column size:
- Video and audio upload a file that plays on the page.
- Page breaks show as a labelled line and start a new page in print,
  Word and PDF.
- Footnotes are numbered in reading order and listed at the end of the
  page. Their notes hold bold, italic, code and links, with a plain copy
  kept for search.
- Tabs hold blocks on several named tabs; which one shows is each
  reader's own choice.
- Status badges are coloured words in the text.
- Typing ":" and a word picks an emoji, from the list the page icon
  picker uses, now kept in the editor package.
- Subpages lists the page's child pages, read afresh from the page tree.
- A synced block is a synced page that shows one block of another page,
  made from a copied block link.

Exports (HTML, Markdown, Word, PDF) and search handle every new block.
Page and space exports list a page's subpages. Labels are translated in
all five languages.

The phone toolbar gets Tabs, Footnote, Status, Emoji, Subpages and Page
break, and the app answers the editor's request for the page's
subpages. The bridge protocol goes to version 5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 17:37:32 +01:00

129 lines
4.5 KiB
Go

// SPDX-License-Identifier: AGPL-3.0-or-later
package convert
import (
"bytes"
"strings"
"testing"
)
const docmostBlocks = `{"type":"doc","content":[
{"type":"paragraph","content":[{"type":"text","text":"Plan "},
{"type":"status","attrs":{"text":"In review","color":"green"}},
{"type":"text","text":" see"},{"type":"footnote","attrs":{"text":"First note"}},
{"type":"text","text":" and"},{"type":"footnote","attrs":{"text":"Second note"}}]},
{"type":"pageBreak"},
{"type":"tabs","content":[
{"type":"tab","attrs":{"title":"Mac"},"content":[{"type":"paragraph","content":[{"type":"text","text":"Cmd"}]}]},
{"type":"tab","attrs":{"title":""},"content":[{"type":"paragraph","content":[{"type":"text","text":"Ctrl"}]}]}]},
{"type":"video","attrs":{"src":"/api/v1/files/v1","name":"demo.mp4"}},
{"type":"audio","attrs":{"src":"javascript:alert(1)","name":"x"}},
{"type":"subpages"},
{"type":"syncedPage","attrs":{"page":"P1","block":"k3j9x2a1"}}]}`
func TestDocmostBlocksExport(t *testing.T) {
doc, err := Parse([]byte(docmostBlocks))
if err != nil {
t.Fatal(err)
}
h := HTML(doc, Options{})
for _, want := range []string{
`data-type="status" data-color="green"`, `>In review</span>`,
`<a href="#fn-1">[1]</a>`, `<a href="#fn-2">[2]</a>`,
`<li id="fn-2">Second note <a href="#fnref-2">↩</a></li>`,
`break-after:page`,
`<h4>Mac</h4>`, `<h4>Tab 2</h4>`, `<p>Ctrl</p>`,
`<video src="/api/v1/files/v1" controls`,
`<a href="/p/P1#b-k3j9x2a1">Synced block</a>`,
} {
if !strings.Contains(h, want) {
t.Errorf("html lacks %q:\n%s", want, h)
}
}
if strings.Contains(h, "javascript:") {
t.Errorf("html keeps an unsafe media address:\n%s", h)
}
md := Markdown(doc, Options{})
for _, want := range []string{
"Plan `In review` see[^1] and[^2]",
"[^1]: First note\n[^2]: Second note\n",
"**Mac**\n\nCmd\n\n**Tab 2**\n\nCtrl",
"[demo.mp4](/api/v1/files/v1)",
} {
if !strings.Contains(md, want) {
t.Errorf("markdown lacks %q:\n%s", want, md)
}
}
if got := PlainText(doc.Content[0]); got != "Plan In review see (First note) and (Second note)" {
t.Errorf("plain text: %q", got)
}
if _, err := DOCX("T", doc, DOCXOptions{}); err != nil {
t.Errorf("docx: %v", err)
}
pdf, err := PDF("T", doc, PDFOptions{})
if err != nil || !bytes.HasPrefix(pdf, []byte("%PDF")) {
t.Errorf("pdf: %v", err)
}
}
func TestFootnotesAreNumberedWithoutChangingTheDocument(t *testing.T) {
doc, _ := Parse([]byte(docmostBlocks))
numbered, notes := numberFootnotes(doc)
if len(notes) != 2 || PlainText(Node{Content: notes[1]}) != "Second note" {
t.Fatalf("notes: %v", notes)
}
if footnoteNumber(numbered.Content[0].Content[5]) != "2" {
t.Errorf("second footnote: %+v", numbered.Content[0].Content[5])
}
if _, ok := doc.Content[0].Content[3].Attrs["n"]; ok {
t.Error("numbering changed the original document")
}
}
func TestFormattedFootnotesAndSubpagesExport(t *testing.T) {
doc, err := Parse([]byte(`{"type":"doc","content":[
{"type":"paragraph","content":[{"type":"text","text":"See"},
{"type":"footnote","attrs":{"text":"Read the guide now","content":[
{"type":"text","text":"Read "},
{"type":"text","text":"the guide","marks":[{"type":"bold"},{"type":"link","attrs":{"href":"https://example.com"}}]},
{"type":"hardBreak"},
{"type":"text","text":"now"},
{"type":"paragraph","content":[{"type":"text","text":"dropped"}]}]}}]},
{"type":"subpages"}]}`))
if err != nil {
t.Fatal(err)
}
o := Options{Subpages: []PageLink{{ID: "c1", Title: "Setup", Icon: "🛠"}, {ID: "c2"}}}
h := HTML(doc, o)
for _, want := range []string{
`<li id="fn-1">Read <strong><a href="https://example.com">the guide</a></strong><br>now <a href="#fnref-1">`,
`<ul data-type="subpages">`, `<li><a href="/p/c1">🛠 Setup</a></li>`, `<li><a href="/p/c2">Untitled</a></li>`,
} {
if !strings.Contains(h, want) {
t.Errorf("html lacks %q:\n%s", want, h)
}
}
if strings.Contains(h, "dropped") {
t.Errorf("html keeps a block inside a footnote:\n%s", h)
}
md := Markdown(doc, o)
for _, want := range []string{"[^1]: Read [**the guide**](https://example.com) now\n", "- [🛠 Setup](/p/c1)\n- [Untitled](/p/c2)"} {
if !strings.Contains(md, want) {
t.Errorf("markdown lacks %q:\n%s", want, md)
}
}
if strings.Contains(Markdown(doc, Options{}), "/p/c1") {
t.Error("subpages listed without any given")
}
if _, err := DOCX("T", doc, DOCXOptions{Options: o}); err != nil {
t.Errorf("docx: %v", err)
}
if _, err := PDF("T", doc, PDFOptions{Options: o}); err != nil {
t.Errorf("pdf: %v", err)
}
}