Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

feat: Copy Notes and Copy Everything paste into document apps with headings, lists and the fishbone as a picture

wqugurud8471f73e3d7
diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index fbb2332..8e42cc3 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -1119,7 +1119,7 @@
"转完后生成" = "After transcribing";
"收起原话" = "Hide original";
"在纪要旁显示原话" = "Show the original beside the notes";
-"复制为 Markdown" = "Copy as Markdown";
+"复制全文" = "Copy Everything";
"导出 Markdown…" = "Export Markdown…";
"导出 Word…" = "Export Word…";
"导出字幕 SRT…" = "Export SRT Subtitles…";
diff --git a/Resources/ja.lproj/Localizable.strings b/Resources/ja.lproj/Localizable.strings
index ecaf10d..1e0d565 100644
--- a/Resources/ja.lproj/Localizable.strings
+++ b/Resources/ja.lproj/Localizable.strings
@@ -1119,7 +1119,7 @@
"转完后生成" = "文字起こし後";
"收起原话" = "原文を隠す";
"在纪要旁显示原话" = "議事録の横に原文を表示";
-"复制为 Markdown" = "Markdown としてコピー";
+"复制全文" = "すべてコピー";
"导出 Markdown…" = "Markdown を書き出す…";
"导出 Word…" = "Word を書き出す…";
"导出字幕 SRT…" = "SRT 字幕を書き出す…";
diff --git a/Resources/ko.lproj/Localizable.strings b/Resources/ko.lproj/Localizable.strings
index 5f2c11a..2b66585 100644
--- a/Resources/ko.lproj/Localizable.strings
+++ b/Resources/ko.lproj/Localizable.strings
@@ -1119,7 +1119,7 @@
"转完后生成" = "받아쓰기 후";
"收起原话" = "원문 숨기기";
"在纪要旁显示原话" = "회의록 옆에 원문 표시";
-"复制为 Markdown" = "Markdown으로 복사하기";
+"复制全文" = "전체 복사하기";
"导出 Markdown…" = "Markdown 내보내기…";
"导出 Word…" = "Word 내보내기…";
"导出字幕 SRT…" = "SRT 자막 내보내기…";
diff --git a/Sources/Cicada/AppMenu.swift b/Sources/Cicada/AppMenu.swift
index 82cd39f..bd8c5fa 100644
--- a/Sources/Cicada/AppMenu.swift
+++ b/Sources/Cicada/AppMenu.swift
@@ -210,8 +210,7 @@ final class AppMenu: NSObject, NSMenuItemValidation {
@objc private func copyNotes() {
guard let model else { return }
- NSPasteboard.general.clearContents()
- NSPasteboard.general.setString(TranscriptExport.notesMarkdown(model.notes.notes), forType: .string)
+ RichCopy.notes(model.notes.notes, title: model.notes.notes.title)
}
@objc private func exportNotes(_ sender: NSMenuItem) {
diff --git a/Sources/Cicada/AppModel.swift b/Sources/Cicada/AppModel.swift
index 028c886..6448ab7 100644
--- a/Sources/Cicada/AppModel.swift
+++ b/Sources/Cicada/AppModel.swift
@@ -1930,8 +1930,7 @@ final class AppModel: ObservableObject {
func export(_ session: Session, kind: String) {
if kind == "copy" {
- NSPasteboard.general.clearContents()
- NSPasteboard.general.setString(TranscriptExport.markdown(session), forType: .string)
+ RichCopy.session(session)
return
}
let panel = NSSavePanel()
diff --git a/Sources/Cicada/NotesViews.swift b/Sources/Cicada/NotesViews.swift
index 12f3938..a8f78a7 100644
--- a/Sources/Cicada/NotesViews.swift
+++ b/Sources/Cicada/NotesViews.swift
@@ -424,6 +424,8 @@ struct TimeLink: View {
struct FishboneView: View {
let fishbone: Fishbone
var onJump: (Double) -> Void = { _ in }
+ /// Drawn for 复制为图片 or 复制纪要: no hint, no menu.
+ var forPicture = false
var body: some View {
VStack(alignment: .leading, spacing: 10) {
@@ -447,7 +449,9 @@ struct FishboneView: View {
.fixedSize(horizontal: false, vertical: true)
}
}
- Text("点击分支跳回原话").font(.system(size: 11)).foregroundStyle(Palette.tertiary)
+ if !forPicture {
+ Text("点击分支跳回原话").font(.system(size: 11)).foregroundStyle(Palette.tertiary)
+ }
}
.padding(12)
.background(RoundedRectangle(cornerRadius: 16).stroke(Palette.line, lineWidth: 1))
diff --git a/Sources/Cicada/RichCopy.swift b/Sources/Cicada/RichCopy.swift
new file mode 100644
index 0000000..9f38293
--- /dev/null
+++ b/Sources/Cicada/RichCopy.swift
@@ -0,0 +1,146 @@
+import AppKit
+import SwiftUI
+
+/// 复制纪要 as rich text: one copy puts HTML (document apps: Feishu, DingTalk, Notion, web
+/// editors), RTFD (Notes, Pages, Word) and the Markdown as plain text (chats, code editors) on the
+/// pasteboard, and each app takes the one it reads. No app's API, no sign-in, no token.
+extension TranscriptExport {
+ /// A fishbone as a picture: PNG data and the width to show it at (points; the PNG is 2x).
+ struct Picture: Equatable {
+ var png: Data
+ var width: Int
+ }
+
+ /// The notes as an HTML fragment (empty when there are none). A fishbone is its picture, when
+ /// there is one, followed by the same branches as a list: an app that drops pasted images
+ /// still keeps the text.
+ static func notesHTML(_ n: MeetingNotes?, picture: (Fishbone) -> Picture? = { _ in nil }) -> String {
+ guard let n, !n.isEmpty else { return "" }
+ var out = "<h2>\(esc(L("纪要")))</h2>\n<p>\(esc(n.summary))</p>\n"
+ for t in n.topics {
+ out += "<h3>\(clock(t.start)) \(esc(t.title))</h3>\n"
+ if !t.summary.isEmpty { out += "<p>\(esc(t.summary))</p>\n" }
+ out += list(t.points.map(esc))
+ if let f = t.fishbone {
+ out += "<p><b>\(esc(f.question))</b></p>\n"
+ if let p = picture(f) {
+ out += "<p><img src=\"data:image/png;base64,\(p.png.base64EncodedString())\" width=\"\(p.width)\" alt=\"\(esc(f.question))\"></p>\n"
+ }
+ out += list(f.branches.map { "<b>\(esc($0.label))</b>:\(esc($0.detail))" })
+ }
+ }
+ if !n.conclusions.isEmpty { out += "<h3>\(esc(L("结论")))</h3>\n" + list(n.conclusions.map { esc($0.text) }) }
+ // A checkbox doesn't survive a paste; the ballot box does.
+ if !n.todos.isEmpty { out += "<h3>\(esc(L("待办")))</h3>\n" + list(n.todos.map { "☐ " + esc($0.withOwner) }) }
+ if !n.terms.isEmpty { out += "<h3>\(esc(L("人名和术语")))</h3>\n" + list(n.terms.map { "<b>\(esc($0.name))</b> \(esc($0.note))" }) }
+ return out
+ }
+
+ /// The whole record as HTML, in the order and wording of `markdown(_:)`.
+ static func html(_ s: Session, picture: (Fishbone) -> Picture? = { _ in nil }) -> String {
+ var out = "<h1>\(esc(s.displayTitle))</h1>\n<p>\(esc(header(s)))</p>\n"
+ let notes = notesHTML(s.notes, picture: picture)
+ if !notes.isEmpty { out += notes + "<h2>\(esc(L("文字记录")))</h2>\n" }
+ let numbers = speakerNumbers(s), names = SpeakerLabels.names(s)
+ for l in s.lines {
+ let who = saysWho(s, numbers) ? " \(esc(speakerName(l, numbers, names)))" : ""
+ var p = "<p><b>[\(clock(l.t))]\(who)</b><br>\(esc(l.shown))"
+ if let d = l.dst, d != l.shown { p += "<br><span style=\"color:#5A5F6B\">\(esc(d))</span>" }
+ out += p + "</p>\n"
+ }
+ return out
+ }
+
+ /// A fragment as a document a pasting app reads as UTF-8 whatever it assumes.
+ static func htmlDocument(_ body: String) -> String {
+ "<html><head><meta charset=\"utf-8\"></head><body>\n\(body)</body></html>"
+ }
+
+ private static func list(_ items: [String]) -> String {
+ items.isEmpty ? "" : "<ul>\n" + items.map { "<li>\($0)</li>\n" }.joined() + "</ul>\n"
+ }
+
+ static func esc(_ s: String) -> String {
+ var out = ""
+ for c in s {
+ switch c {
+ case "&": out += "&amp;"
+ case "<": out += "&lt;"
+ case ">": out += "&gt;"
+ case "\"": out += "&quot;"
+ case "\n": out += "<br>"
+ default: out.append(c)
+ }
+ }
+ return out
+ }
+}
+
+@MainActor
+enum RichCopy {
+ /// Puts `markdown` as plain text and `html` as HTML and RTFD on the general pasteboard.
+ static func put(markdown: String, html: String) {
+ let doc = TranscriptExport.htmlDocument(html)
+ let pb = NSPasteboard.general
+ pb.clearContents()
+ pb.setString(markdown, forType: .string)
+ pb.setString(doc, forType: .html)
+ // AppKit's HTML reader loads data: images in place, so the RTFD carries the fishbone too.
+ if let data = doc.data(using: .utf8),
+ let text = try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html,
+ .characterEncoding: String.Encoding.utf8.rawValue],
+ documentAttributes: nil),
+ let rtfd = text.rtfd(from: NSRange(location: 0, length: text.length), documentAttributes: [:]) {
+ pb.setData(rtfd, forType: .rtfd)
+ } else {
+ debugLog("rich copy: no RTFD, HTML and text only")
+ }
+ }
+
+ static func notes(_ n: MeetingNotes?, title: String?) {
+ put(markdown: TranscriptExport.notesMarkdown(n), html: TranscriptExport.notesHTML(n) { picture($0, caption: title) })
+ }
+
+ static func session(_ s: Session) {
+ put(markdown: TranscriptExport.markdown(s), html: TranscriptExport.html(s) { picture($0, caption: s.displayTitle) })
+ }
+
+ /// 复制为图片: the PNG alone, so a chat or a slide takes it as a picture.
+ static func image(_ f: Fishbone, caption: String?) {
+ guard let p = picture(f, caption: caption) else { return }
+ let pb = NSPasteboard.general
+ pb.clearContents()
+ pb.setData(p.png, forType: .png)
+ }
+
+ /// 复制为文字: the question and its branches, as the notes' Markdown has them.
+ static func text(_ f: Fishbone) {
+ let pb = NSPasteboard.general
+ pb.clearContents()
+ pb.setString("**\(f.question)**\n\n" + f.branches.map { "- \($0.label):\($0.detail)\n" }.joined(), forType: .string)
+ }
+
+ static let pictureWidth = 520
+
+ /// The fishbone as it looks in the notes, always light on white (a dark window's picture pasted
+ /// into a white document is a black block), without hints that only mean something in the app,
+ /// and with the meeting's name under it so a forwarded picture says where it came from.
+ static func picture(_ f: Fishbone, caption: String?) -> TranscriptExport.Picture? {
+ let view = VStack(alignment: .trailing, spacing: 8) {
+ FishboneView(fishbone: f, forPicture: true)
+ if let caption, !caption.isEmpty {
+ Text("\(caption) · Cicada").font(.system(size: 10)).foregroundStyle(Palette.tertiary)
+ }
+ }
+ .padding(16)
+ .frame(width: CGFloat(pictureWidth))
+ .background(Color.white)
+ .environment(\.colorScheme, .light)
+ let r = ImageRenderer(content: view)
+ r.scale = 2
+ guard let cg = r.cgImage else { return nil }
+ let rep = NSBitmapImageRep(cgImage: cg)
+ guard let png = rep.representation(using: .png, properties: [:]) else { return nil }
+ return .init(png: png, width: pictureWidth)
+ }
+}
diff --git a/Sources/Cicada/Views.swift b/Sources/Cicada/Views.swift
index 68c54f9..57f584d 100644
--- a/Sources/Cicada/Views.swift
+++ b/Sources/Cicada/Views.swift
@@ -1225,7 +1225,7 @@ struct MainWindowView: View {
.help(L("用保存的录音重新识别,替换现在的文字记录和纪要;旧记录会先备份"))
}
Menu {
- Button("复制为 Markdown") { model.export(s, kind: "copy") }
+ Button("复制全文") { model.export(s, kind: "copy") }
Divider()
Button("导出 Markdown…") { model.export(s, kind: "md") }
Button("导出 Word…") { model.export(s, kind: "word") }
diff --git a/Tests/CicadaTests/ExportTests.swift b/Tests/CicadaTests/ExportTests.swift
index 3098572..ccfa1c3 100644
--- a/Tests/CicadaTests/ExportTests.swift
+++ b/Tests/CicadaTests/ExportTests.swift
@@ -42,3 +42,38 @@ import Testing
#expect(!md.contains("> Same"))
}
}
+
+@Suite struct RichCopyTests {
+ private var notes: MeetingNotes {
+ var n = MeetingNotes()
+ n.summary = "A <b> & \"c\""
+ n.topics = [NoteTopic(start: 65, title: "Why late", summary: "", points: ["one"],
+ fishbone: Fishbone(question: "Why?", branches: [FishboneBranch(label: "Tests", detail: "not run", t: 70, support: 2)]))]
+ n.todos = [NoteItem(text: "Ship", owner: nil, support: 1)]
+ return n
+ }
+
+ @Test func escapesAndKeepsStructure() {
+ let html = TranscriptExport.notesHTML(notes)
+ #expect(html.contains("<p>A &lt;b&gt; &amp; &quot;c&quot;</p>"))
+ #expect(html.contains("<h3>01:05 Why late</h3>"))
+ #expect(html.contains("<li>one</li>"))
+ // A to-do keeps a ballot box, as a checkbox doesn't survive a paste.
+ #expect(html.contains("<li>☐ Ship</li>"))
+ #expect(!html.contains("<img"))
+ }
+
+ /// The picture comes first and the same branches follow as text, for an app that drops images.
+ @Test func fishboneIsPictureThenList() {
+ let html = TranscriptExport.notesHTML(notes) { _ in .init(png: Data([1, 2, 3]), width: 520) }
+ let img = html.range(of: "<img src=\"data:image/png;base64,AQID\" width=\"520\" alt=\"Why?\">")
+ let list = html.range(of: "<li><b>Tests</b>:not run</li>")
+ #expect(img != nil && list != nil)
+ if let img, let list { #expect(img.lowerBound < list.lowerBound) }
+ }
+
+ @Test func emptyNotesGiveNothing() {
+ #expect(TranscriptExport.notesHTML(nil).isEmpty)
+ #expect(TranscriptExport.notesHTML(MeetingNotes()).isEmpty)
+ }
+}