Link previews: link cards for GitHub issues, pull requests and repositories, Linear issues and Figma files are read through the services' APIs and show a status pill (Open, Merged, In Progress…) and a line of details. Public items need nothing; a workspace's tokens, set by its admins under Workspace settings → Integrations and checked with each service before being sealed, reach private ones and Linear. GET /link-preview takes the workspace; the link card stores kind, status, state and meta. Slack: each workspace connects its own Slack app, made from a manifest the settings page fills in. Docwell posts chosen page and comment events to a channel (edits at most every 30 minutes per page), previews links to Docwell pages posted in Slack, and answers /docwell with a search as the member whose email matches the Slack user, shown only to them. Only pages every member can open are posted or previewed. Requests from Slack are signature-checked; the webhook dispatcher gained listeners so Slack follows the same events. Confluence: a space's HTML export imports with its page tree (from index.html, else breadcrumbs), links between pages, pictures and attachments. Panels become callouts, code macros code blocks with their language, expand macros toggles, task lists to-dos. New collection workspace_integrations (schema snapshot regenerated), OpenAPI and generated Go, TypeScript and Dart types, strings in all five languages, the user guide, and a rebuilt mobile editor bundle. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
177 lines
6.9 KiB
Go
177 lines
6.9 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||
|
||
package convert
|
||
|
||
import (
|
||
"archive/zip"
|
||
"bytes"
|
||
"errors"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
func confluenceZip(t *testing.T, files map[string]string) []byte {
|
||
t.Helper()
|
||
var buf bytes.Buffer
|
||
zw := zip.NewWriter(&buf)
|
||
for name, body := range files {
|
||
w, err := zw.Create(name)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
_, _ = w.Write([]byte(body))
|
||
}
|
||
if err := zw.Close(); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
return buf.Bytes()
|
||
}
|
||
|
||
func confluencePage(title, crumbs, main, after string) string {
|
||
return `<!DOCTYPE html><html><head><title>DOCS : ` + title + `</title></head><body><div id="page"><div id="main">
|
||
<div id="main-header"><div id="breadcrumb-section"><ol id="breadcrumbs"><li class="first"><span><a href="index.html">Docs</a></span></li>` + crumbs + `</ol></div>
|
||
<h1 id="title-heading" class="pagetitle"><span id="title-text"> Docs : ` + title + ` </span></h1></div>
|
||
<div id="content" class="view"><div class="page-metadata">Created by Ann, last modified on Nov 02, 2026</div>
|
||
<div id="main-content" class="wiki-content group">` + main + `</div>` + after + `</div></div></div></body></html>`
|
||
}
|
||
|
||
func findNodes(n Node, typ string) []Node {
|
||
var out []Node
|
||
if n.Type == typ {
|
||
out = append(out, n)
|
||
}
|
||
for _, c := range n.Content {
|
||
out = append(out, findNodes(c, typ)...)
|
||
}
|
||
return out
|
||
}
|
||
|
||
func plain(n Node) string {
|
||
if n.Type == "text" {
|
||
return n.Text
|
||
}
|
||
var b strings.Builder
|
||
for _, c := range n.Content {
|
||
b.WriteString(plain(c))
|
||
}
|
||
return b.String()
|
||
}
|
||
|
||
func linkTargets(n Node) []string {
|
||
var out []string
|
||
for _, m := range n.Marks {
|
||
if m.Type == "link" {
|
||
out = append(out, m.Attrs["href"].(string))
|
||
}
|
||
}
|
||
for _, c := range n.Content {
|
||
out = append(out, linkTargets(c)...)
|
||
}
|
||
return out
|
||
}
|
||
|
||
func TestReadConfluence(t *testing.T) {
|
||
home := confluencePage("Home", "", `
|
||
<div class="confluence-information-macro confluence-information-macro-information"><p class="title">Read me</p>
|
||
<span class="aui-icon confluence-information-macro-icon"></span>
|
||
<div class="confluence-information-macro-body"><p>Start <a href="Child_2.html">here</a>.</p></div></div>
|
||
<div class="code panel pdl"><div class="codeContent panelContent pdl">
|
||
<pre class="syntaxhighlighter-pre" data-syntaxhighlighter-params="brush: java; gutter: false" data-theme="Confluence">class A {}
|
||
</pre></div></div>
|
||
<div id="expander-1" class="expand-container"><div class="expand-control"><span class="expand-control-text">More</span></div>
|
||
<div class="expand-content"><p>Hidden text</p></div></div>
|
||
<ul class="inline-task-list"><li class="checked" data-inline-task-id="1"><span>Done thing</span></li><li data-inline-task-id="2"><span>Open thing</span></li></ul>
|
||
<p>State: <span class="status-macro aui-lozenge aui-lozenge-success">done</span> <img class="emoticon emoticon-smile" alt="(smile)" data-emoji-fallback="🙂" src="images/icons/emoticons/smile.svg">
|
||
by <a href="/display/~ann" class="confluence-userlink user-mention">Ann Lee</a></p>
|
||
<p><span class="confluence-embedded-file-wrapper"><img class="confluence-embedded-image" src="https://docs.example/download/thumbnails/1/pic.png" data-image-src="/download/attachments/1/pic.png"></span></p>`,
|
||
`<div class="pageSection group"><div class="pageSectionHeader"><h2 id="attachments" class="pageSectionTitle">Attachments:</h2></div>
|
||
<div class="greybox" align="left"><img src="images/icons/bullet_blue.gif"> <a href="attachments/1/spec.pdf">spec.pdf</a> (application/pdf)<br/>
|
||
<img src="images/icons/bullet_blue.gif"> <a href="attachments/1/pic.png">pic.png</a> (image/png)<br/></div></div>`)
|
||
files := map[string]string{
|
||
"DOCS/index.html": `<html><body><div id="main-content"><div class="pageSection"><h2>Available Pages:</h2>
|
||
<ul><li><a href="Home_1.html">Home</a><ul><li><a href="Child_2.html">Child</a><ul><li><a href="Grandchild_3.html">Grandchild</a></li></ul></li></ul></li></ul></div></div></body></html>`,
|
||
"DOCS/styles/site.css": "body{}",
|
||
"DOCS/Home_1.html": home,
|
||
"DOCS/Child_2.html": confluencePage("Child", `<li><a href="Home_1.html">Home</a></li>`, `<p>Child body</p>`, ""),
|
||
"DOCS/Grandchild_3.html": confluencePage("Grandchild", "", `<p>Deep</p>`, ""),
|
||
// Left out of index.html: its breadcrumbs name the parent.
|
||
"DOCS/Orphan_4.html": confluencePage("Orphan", `<li><a href="Home_1.html">Home</a></li>`, `<p>Lost</p>`, ""),
|
||
"DOCS/attachments/1/pic.png": "PNG",
|
||
"DOCS/attachments/1/spec.pdf": "%PDF",
|
||
}
|
||
data := confluenceZip(t, files)
|
||
if kind, err := DetectArchive(data); err != nil || kind != VaultConfluence {
|
||
t.Fatalf("detected %q, %v", kind, err)
|
||
}
|
||
pages, assets, err := ReadConfluence(data)
|
||
if err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
var got []string
|
||
for _, p := range pages {
|
||
parent := "-"
|
||
if p.Parent >= 0 {
|
||
parent = pages[p.Parent].Title
|
||
}
|
||
got = append(got, p.Title+"<"+parent)
|
||
}
|
||
if strings.Join(got, ", ") != "Home<-, Child<Home, Orphan<Home, Grandchild<Child" {
|
||
t.Fatalf("pages %v", got)
|
||
}
|
||
doc := pages[0].Doc
|
||
|
||
callouts := findNodes(doc, "callout")
|
||
if len(callouts) != 1 || callouts[0].Attrs["emoji"] != "ℹ️" || callouts[0].Attrs["color"] != "blue" ||
|
||
!strings.Contains(plain(callouts[0]), "Read me") || !strings.Contains(plain(callouts[0]), "Start here.") {
|
||
t.Errorf("callout %+v", callouts)
|
||
}
|
||
if links := linkTargets(callouts[0]); len(links) != 1 || links[0] != PageRef(1) {
|
||
t.Errorf("page link %v", links)
|
||
}
|
||
code := findNodes(doc, "codeBlock")
|
||
if len(code) != 1 || code[0].Attrs["language"] != "java" || plain(code[0]) != "class A {}" {
|
||
t.Errorf("code %+v", code)
|
||
}
|
||
if d := findNodes(doc, "details"); len(d) != 1 || !strings.Contains(plain(d[0]), "More") || !strings.Contains(plain(d[0]), "Hidden text") {
|
||
t.Errorf("expand %+v", d)
|
||
}
|
||
tasks := findNodes(doc, "taskItem")
|
||
if len(tasks) != 2 || tasks[0].Attrs["checked"] != true || tasks[1].Attrs["checked"] != false || plain(tasks[1]) != "Open thing" {
|
||
t.Errorf("tasks %+v", tasks)
|
||
}
|
||
text := plain(doc)
|
||
for _, want := range []string{"State: DONE 🙂 by @Ann Lee", "Attachments"} {
|
||
if !strings.Contains(text, want) {
|
||
t.Errorf("text lacks %q:\n%s", want, text)
|
||
}
|
||
}
|
||
imgs := findNodes(doc, "image")
|
||
if len(imgs) != 1 || !strings.HasPrefix(imgs[0].Attrs["src"].(string), "asset:") {
|
||
t.Errorf("images %+v", imgs)
|
||
}
|
||
// The attachment list links both files; the picture is one asset, not two.
|
||
if len(assets) != 2 {
|
||
t.Errorf("assets %d", len(assets))
|
||
}
|
||
names := map[string]bool{}
|
||
for _, a := range assets {
|
||
names[a.Name] = true
|
||
}
|
||
if !names["pic.png"] || !names["spec.pdf"] {
|
||
t.Errorf("asset names %v", names)
|
||
}
|
||
lists := findNodes(doc, "bulletList")
|
||
if last := lists[len(lists)-1]; len(linkTargets(last)) != 2 {
|
||
t.Errorf("attachment list %+v", last)
|
||
}
|
||
|
||
// A zip of HTML pages without Confluence's layout is not Confluence.
|
||
other := confluenceZip(t, map[string]string{"a.html": "<p>x</p>"})
|
||
if kind, _ := DetectArchive(other); kind == VaultConfluence {
|
||
t.Error("plain HTML zip detected as Confluence")
|
||
}
|
||
if _, _, err := ReadConfluence(other); !errors.Is(err, ErrNoConfluence) {
|
||
t.Errorf("plain zip: %v", err)
|
||
}
|
||
}
|