Phase F of the AFFiNE plan (ADR-16): - Calendars: people subscribe to iCal feeds (webcal, Google's secret address, Outlook) or CalDAV accounts in account settings; their events show at the top of journal pages in the reader's time zone. Repeats, moved and cancelled occurrences, IANA and Windows zones are handled. Events are read on demand and kept in memory for 15 minutes; passwords are sealed with DOCWELL_SECRET_KEY; sources follow the webhook address rules. New calendar_accounts collection. - Importers: zips of Markdown (Obsidian vaults, Bear TextBundles and .bear2bk, Readwise's Markdown, Docwell's own space export) keep folders as pages, resolve [[wikilinks]] and embeds by name, and turn front matter and #tags into properties and tags. OneNote .mht exports, Readwise CSV, and any other CSV as a database page. - Exports: PNG of a page drawn in the browser, print styles that print only the page in the light theme, and workspace snapshots (records, Yjs states, JSON and files in one zip) that restore as a new workspace. Old ids are swapped byte for byte inside the Yjs updates, so links point at the restored pages and comments stay anchored. - Web-Clipper/: a Manifest V3 extension for Chrome, Edge and Firefox that saves the article or the selection as Markdown through the import API with a personal API token. - OpenAPI, generated clients, translations and user docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
3.7 KiB
Go
88 lines
3.7 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package convert
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestReadMHTOneNoteSection(t *testing.T) {
|
|
img := base64.StdEncoding.EncodeToString(pngOf(t, 3, 3))
|
|
var wrapped strings.Builder
|
|
for i := 0; i < len(img); i += 60 {
|
|
wrapped.WriteString(img[i:min(i+60, len(img))] + "\r\n")
|
|
}
|
|
mht := "MIME-Version: 1.0\r\n" +
|
|
"Content-Type: multipart/related; boundary=\"----=_NextPart_01\"\r\n\r\n" +
|
|
"------=_NextPart_01\r\nContent-Location: file:///C:/Export/Section.htm\r\nContent-Type: text/html; charset=\"utf-8\"\r\n\r\n" +
|
|
"<html><frameset><frame src=\"Section_files/page1.htm\"></frameset></html>\r\n" +
|
|
"------=_NextPart_01\r\nContent-Location: file:///C:/Export/Section_files/page1.htm\r\n" +
|
|
"Content-Transfer-Encoding: quoted-printable\r\nContent-Type: text/html; charset=\"windows-1252\"\r\n\r\n" +
|
|
"<html><head><title>Caf=E9 notes</title></head><body><div style=3D\"position:absolute\">" +
|
|
"<p>First line</p><img src=3D\"image001.png\"><p><a href=3D\"page2.htm\">next</a> " +
|
|
"<a href=3D\"https://example.com/\">web</a></p></div></body></html>\r\n" +
|
|
"------=_NextPart_01\r\nContent-Location: file:///C:/Export/Section_files/page2.htm\r\nContent-Type: text/html\r\n\r\n" +
|
|
"<html><body><h1>Second</h1><p>Two</p></body></html>\r\n" +
|
|
"------=_NextPart_01\r\nContent-Location: file:///C:/Export/Section_files/image001.png\r\n" +
|
|
"Content-Transfer-Encoding: base64\r\nContent-Type: image/png\r\n\r\n" + wrapped.String() +
|
|
"------=_NextPart_01--\r\n"
|
|
pages, assets, err := ReadMHT([]byte(mht), "Section.mht")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(pages) != 2 || pages[0].Title != "Café notes" || pages[1].Title != "Second" {
|
|
t.Fatalf("pages = %+v", pages)
|
|
}
|
|
if len(assets) != 1 || assets[0].Name != "image001.png" || string(assets[0].Data[1:4]) != "PNG" {
|
|
t.Fatalf("assets = %v", assets)
|
|
}
|
|
j := asJSON(t, pages[0].Doc)
|
|
for _, want := range []string{`"src":"asset:0"`, `"href":"page:1"`, `"href":"https://example.com/"`, "First line"} {
|
|
if !strings.Contains(j, want) {
|
|
t.Errorf("page lacks %s: %s", want, j)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReadMHTRejectsOtherFiles(t *testing.T) {
|
|
if _, _, err := ReadMHT([]byte("just text"), "x.mht"); err == nil {
|
|
t.Fatal("plain text read as MHTML")
|
|
}
|
|
}
|
|
|
|
func TestReadReadwise(t *testing.T) {
|
|
csv := "Highlight,Book Title,Book Author,Amazon Book ID,Note,Color,Tags,Location Type,Location,Highlighted at,Document tags\n" +
|
|
"\"First idea,\nover two lines\",Deep Work,Cal Newport,B00X,My note,yellow,focus,location,120,2024-03-01 10:00:00+00:00,\"productivity, books\"\n" +
|
|
"Second idea,Deep Work,Cal Newport,B00X,,yellow,,location,130,,\n" +
|
|
"Web quote,An Article,,,,,,,,2024-04-02 08:00:00+00:00,\n"
|
|
if !IsReadwiseCSV([]byte(csv)) || IsReadwiseCSV([]byte("Name,Value\na,1\n")) {
|
|
t.Fatal("IsReadwiseCSV")
|
|
}
|
|
pages, err := ReadReadwise([]byte(csv))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(pages) != 3 || pages[0].Title != "Readwise" || pages[1].Title != "Deep Work" || pages[2].Parent != 0 {
|
|
t.Fatalf("pages = %+v", pages)
|
|
}
|
|
dw := pages[1]
|
|
if dw.Props["Author"] != "Cal Newport" || len(dw.Tags) != 2 || dw.Tags[1] != "books" {
|
|
t.Errorf("Deep Work props %v tags %v", dw.Props, dw.Tags)
|
|
}
|
|
j := asJSON(t, dw.Doc)
|
|
for _, want := range []string{`"type":"blockquote"`, `"First idea,"},{"type":"hardBreak"}`, "My note", "location 120 · 2024-03-01 · #focus", "Second idea"} {
|
|
if !strings.Contains(j, want) {
|
|
t.Errorf("Deep Work lacks %s: %s", want, j)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFromCSV(t *testing.T) {
|
|
doc, err := FromCSV([]byte("Name,Count\nApples,3\nPears,4\n"))
|
|
if err != nil || len(doc.Content) != 1 || doc.Content[0].Type != "database" {
|
|
t.Fatalf("doc = %+v, %v", doc, err)
|
|
}
|
|
}
|