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
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>
109 lines
2.6 KiB
Go
109 lines
2.6 KiB
Go
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package convert
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strconv"
|
|
)
|
|
|
|
// numberFootnotes returns a copy of doc in which each footnote carries its
|
|
// number (attr "n") in reading order, and the footnotes' texts (see
|
|
// footnoteContent) in that order. Exports show the number in the text and
|
|
// list the notes at the end, as the editor does.
|
|
func numberFootnotes(doc Node) (Node, [][]Node) {
|
|
var notes [][]Node
|
|
var walk func(n Node) Node
|
|
walk = func(n Node) Node {
|
|
if n.Type == "footnote" {
|
|
notes = append(notes, footnoteContent(n))
|
|
attrs := make(map[string]any, len(n.Attrs)+1)
|
|
for k, v := range n.Attrs {
|
|
attrs[k] = v
|
|
}
|
|
attrs["n"] = float64(len(notes))
|
|
n.Attrs = attrs
|
|
return n
|
|
}
|
|
if len(n.Content) > 0 {
|
|
content := make([]Node, len(n.Content))
|
|
for i, c := range n.Content {
|
|
content[i] = walk(c)
|
|
}
|
|
n.Content = content
|
|
}
|
|
return n
|
|
}
|
|
return walk(doc), notes
|
|
}
|
|
|
|
// footnoteContent is a footnote's text as inline nodes: its formatted text
|
|
// (attr "content": text runs with marks, and line breaks), or its plain text
|
|
// (attr "text") as one run for notes without.
|
|
func footnoteContent(n Node) []Node {
|
|
if raw, ok := n.Attrs["content"].([]any); ok && len(raw) > 0 {
|
|
var nodes []Node
|
|
if b, err := json.Marshal(raw); err == nil && json.Unmarshal(b, &nodes) == nil {
|
|
kept := nodes[:0]
|
|
for _, c := range nodes {
|
|
if (c.Type == "text" && c.Text != "") || c.Type == "hardBreak" {
|
|
c.Content = nil
|
|
kept = append(kept, c)
|
|
}
|
|
}
|
|
if len(kept) > 0 {
|
|
return kept
|
|
}
|
|
}
|
|
}
|
|
if t := n.attr("text"); t != "" {
|
|
return []Node{{Type: "text", Text: t}}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// oneLine turns a note's line breaks into spaces, for formats where a note
|
|
// must stay on one line.
|
|
func oneLine(nodes []Node) []Node {
|
|
out := make([]Node, len(nodes))
|
|
for i, n := range nodes {
|
|
if n.Type == "hardBreak" {
|
|
n = Node{Type: "text", Text: " "}
|
|
}
|
|
out[i] = n
|
|
}
|
|
return out
|
|
}
|
|
|
|
// footnoteNumber is a numbered footnote's number as text ("1"), or "*".
|
|
func footnoteNumber(n Node) string {
|
|
if v := n.intAttr("n", 0); v > 0 {
|
|
return strconv.Itoa(v)
|
|
}
|
|
return "*"
|
|
}
|
|
|
|
// statusText is a status badge's words.
|
|
func statusText(n Node) string {
|
|
if t := n.attr("text"); t != "" {
|
|
return t
|
|
}
|
|
return "Status"
|
|
}
|
|
|
|
// statusColor is a status badge's palette colour, grey when it has none.
|
|
func statusColor(n Node) string {
|
|
if c := n.attr("color"); isPaletteColor(c) {
|
|
return c
|
|
}
|
|
return "gray"
|
|
}
|
|
|
|
// tabTitle is a tab's name, or "Tab <i+1>" for one without.
|
|
func tabTitle(n Node, i int) string {
|
|
if t := n.attr("title"); t != "" {
|
|
return t
|
|
}
|
|
return "Tab " + strconv.Itoa(i+1)
|
|
}
|