Commit 73fcba4bfb

73fcba4bfb8709ee26c1b1ecee1b70ce400e5b7e

parent: 49c5da9709

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-27 00:04 UTC

Denote notes in Markdown and plain text

Front matter, new notes, renaming, links and backlinks in Denote's
markdown-yaml, markdown-toml and text file types, with denote-file-type
in config.toml and Import from Emacs. Rename from front matter sorts
keywords and rewrites the front matter, as Denote does.

Closes #160

Layout: unified · split

Changed files (26)
Sources/OrgApp/DenoteNote.swift +19 −13 · view
@@ -1,9 +1,9 @@
11import Foundation
22import OrgCore
33
4/// A new Denote note, as `denote` makes it: `IDENTIFIER==signature--title__keywords.org` in
5/// `denote-directory` or a folder under it, starting with the Org front matter and then the
6/// template.
4/// A new Denote note, as `denote` makes it: `IDENTIFIER==signature--title__keywords.org` (or
5/// `.md`, `.txt` for those file types) in `denote-directory` or a folder under it, starting
6/// with the front matter and then the template.
77public enum DenoteNote {
88 /// `denote-directories`: the folders of `denote-directory`, separated by `:`, else the
99 /// first sidebar folder.
@@ -76,36 +76,42 @@ public enum DenoteNote {
7676
7777 /// `denote-rename-file` of the file at `path` with `text`: its new path and text, the
7878 /// keywords sorted, the identifier kept (or for a file without one, its modification
79 /// time's, unused under `roots`), the front matter rewritten or, without one, added.
80 /// A nil `date` keeps the front matter's.
79 /// time's, unused under `roots`), the front matter rewritten in the file's type or, without
80 /// one, added; a Markdown file without front matter gets `preferred`'s when that is a
81 /// Markdown type. A nil `date` keeps the front matter's. The text of a file Denote has no
82 /// type for stays as it is.
8183 public static func renaming(
82 _ path: String, text: String, title: String, keywords: [String], signature: String, date: Date?, roots: [String]
84 _ path: String, text: String, title: String, keywords: [String], signature: String, date: Date?, roots: [String], preferred: Denote.FileType = .org
8385 ) -> (path: String, text: String) {
84 let name = Denote.name(ofFile: path), front = Denote.frontMatter(of: text)
86 let name = Denote.name(ofFile: path)
87 let type = name.ext.isEmpty ? .org : Denote.FileType(path: path, text: text, preferred: preferred)
88 let front = Denote.frontMatter(of: text, type: type ?? .org)
8589 let modified = (try? FileManager.default.attributesOfItem(atPath: path)[.modificationDate] as? Date) ?? Date()
8690 let identifier = name.identifier ?? front.identifier ?? unusedIdentifier(date ?? modified, roots: roots)
8791 let keywords = Denote.keywords(keywords), signature = Denote.signature(signature)
8892 let target = ((path as NSString).deletingLastPathComponent as NSString).appendingPathComponent(
8993 Denote.fileName(identifier: identifier, signature: signature, title: title, keywords: keywords, extension: name.ext.isEmpty ? "org" : name.ext))
90 guard name.ext == "org" || name.ext.isEmpty else { return (target, text) }
91 return (target, Denote.rewritingFrontMatter(text, title: title, keywords: keywords, signature: signature, date: date, identifier: identifier, now: date ?? modified))
94 guard let type else { return (target, text) }
95 return (target, Denote.rewritingFrontMatter(text, title: title, keywords: keywords, signature: signature, date: date, identifier: identifier,
96 now: date ?? modified, type: type))
9297 }
9398
94 /// Makes the note's file in `folder`. Its identifier is `now`'s, or as
99 /// Makes the note's file of `type` in `folder`. Its identifier is `now`'s, or as
95100 /// `denote-generate-identifier-as-date` does, the first second after it no file under
96101 /// `roots` (by default `folder`) has; the front matter keeps `now`. Fails rather than
97102 /// replace a file.
98103 public static func create(
99 title: String, keywords: [String], in folder: String, roots: [String] = [], now: Date = Date(), signature: String = "", template: String = ""
104 title: String, keywords: [String], in folder: String, roots: [String] = [], now: Date = Date(), signature: String = "", template: String = "",
105 type: Denote.FileType = .org
100106 ) throws -> (path: String, id: String) {
101107 let id = unusedIdentifier(now, roots: roots.isEmpty ? [folder] : roots)
102108 let keywords = Denote.keywords(keywords)
103109 let signature = Denote.signature(signature)
104 let name = Denote.fileName(identifier: id, signature: signature, title: title, keywords: keywords)
110 let name = Denote.fileName(identifier: id, signature: signature, title: title, keywords: keywords, extension: type.ext)
105111 let path = (folder as NSString).appendingPathComponent(name)
106112 try FileManager.default.createDirectory(atPath: folder, withIntermediateDirectories: true)
107113 guard !FileManager.default.fileExists(atPath: path) else { throw Dailies.Failure("\(name) is already there") }
108 let text = Denote.frontMatter(title: title, date: now, keywords: keywords, identifier: id, signature: signature) + template
114 let text = Denote.frontMatter(title: title, date: now, keywords: keywords, identifier: id, signature: signature, type: type) + template
109115 try Data(text.utf8).write(to: URL(fileURLWithPath: path), options: .withoutOverwriting)
110116 return (path, id)
111117 }
Sources/OrgApp/DenoteSequenceActions.swift +2 −2 · view
@@ -162,7 +162,7 @@ extension RoamActions {
162162 chooseSequenceFile("Link to file with sequence", files) { file in
163163 guard let id = Denote.identifier(ofFile: file.path) else { return }
164164 let text = (try? String(contentsOfFile: file.path, encoding: .utf8)) ?? ""
165 let title = Denote.frontMatter(of: text).title ?? Denote.name(ofFile: file.path).title ?? ""
165 let title = Denote.frontMatter(ofFile: file.path, text: text).title ?? Denote.name(ofFile: file.path).title ?? ""
166166 insertLink("denote:" + id, title.isEmpty ? file.sequence : file.sequence + " " + title)
167167 }
168168 case "hierarchy":
@@ -172,7 +172,7 @@ extension RoamActions {
172172 let labels = ordered.map { file -> String in
173173 let depth = (try? model.depth(file.sequence)) ?? 1
174174 let text = (try? String(contentsOfFile: file.path, encoding: .utf8)) ?? ""
175 let title = Denote.frontMatter(of: text).title ?? Denote.name(ofFile: file.path).title ?? ""
175 let title = Denote.frontMatter(ofFile: file.path, text: text).title ?? Denote.name(ofFile: file.path).title ?? ""
176176 let keywords = Denote.name(ofFile: file.path).keywords.joined(separator: "_")
177177 return String(repeating: " ", count: depth - 1) + file.sequence + (title.trimmingCharacters(in: .whitespaces).isEmpty ? "" : " " + title)
178178 + (keywords.isEmpty ? "" : " _" + keywords)
Sources/OrgApp/EmacsImport.swift +4 · view
@@ -595,6 +595,10 @@ public struct EmacsImport: Sendable {
595595 case "denote-directory", "denote-journal-directory", "denote-journal-keyword":
596596 guard let text = value.string else { return note("not a string") }
597597 add(name, .string(text))
598 case "denote-file-type":
599 // nil is the first of `denote-file-types`, org.
600 guard let type = value.symbol, type == "nil" || Denote.FileType(rawValue: type) != nil else { return note("not org, markdown-yaml, markdown-toml or text") }
601 add(name, .string(type == "nil" ? "org" : type))
598602 case "denote-sequence-scheme":
599603 guard let scheme = value.symbol, DenoteSequence.Scheme(rawValue: scheme) != nil else { return note("not numeric, alphanumeric or alphanumeric-delimited") }
600604 add(name, .string(scheme))
Sources/OrgApp/OrgPreferences.swift +4 · view
@@ -207,6 +207,10 @@ public enum OrgPreferences {
207207 public static func denoteSequenceScheme(_ defaults: UserDefaults = .standard) -> DenoteSequence.Scheme {
208208 DenoteSequence.Scheme(rawValue: string("denoteSequenceScheme", defaults)) ?? .numeric
209209 }
210 /// `denote-file-type`: the file type of new notes.
211 public static func denoteFileType(_ defaults: UserDefaults = .standard) -> Denote.FileType {
212 Denote.FileType(rawValue: string("denoteFileType", defaults)) ?? .org
213 }
210214 /// `denote-prompts`: what a new note asks after its title, in order.
211215 public static func denotePrompts(_ defaults: UserDefaults = .standard) -> [String] {
212216 string("denotePrompts", defaults).split(whereSeparator: \.isWhitespace).map(String.init)
Sources/OrgApp/RoamActions.swift +24 −10 · view
@@ -122,6 +122,8 @@ public struct RoamActions {
122122 }
123123 }
124124 case "app.node.insert":
125 // An `id:` link is org syntax; only Denote's links go in its Markdown and text notes.
126 if !denote, let path = session.path, !DocumentSession.isOrgPath(path) { return show("Not an org file") }
125127 chooseNode("Node: ") { choice in
126128 switch choice {
127129 case .existing(let node, let title): insertLink(linkType + node.id, title)
@@ -319,7 +321,8 @@ public struct RoamActions {
319321 guard reachFolders([answers.folder ?? root]) else { return }
320322 do {
321323 let note = try DenoteNote.create(title: title, keywords: answers.keywords, in: answers.folder ?? root, roots: roots,
322 now: answers.date ?? Date(), signature: answers.signature, template: answers.template)
324 now: answers.date ?? Date(), signature: answers.signature, template: answers.template,
325 type: OrgPreferences.denoteFileType())
323326 refresh()
324327 show("Created \((note.path as NSString).lastPathComponent)")
325328 then(.created(path: note.path, offset: (session.text(of: note.path).map { ($0 as NSString).length }) ?? 0, id: note.id, title: title))
@@ -367,12 +370,14 @@ public struct RoamActions {
367370 }
368371
369372 /// `denote-rename-file-using-front-matter`: the open file renamed from its title,
370 /// keywords and signature, keeping its identifier.
373 /// keywords and signature, keeping its identifier, and its front matter rewritten from them.
371374 func renameFromFrontMatter() {
372375 guard let path = session.path else { return show("No file is open") }
373376 guard let text = session.text(of: path) else { return show("Can't read \((path as NSString).lastPathComponent)") }
374 guard let target = Denote.renamed(path, text: text) else { return show("Not a Denote note: no front matter or identifier") }
375 guard target != path else { return show("Nothing to rename") }
377 guard let (target, rewritten) = Denote.renamed(path, text: text) else { return show("Not a Denote note: no front matter or identifier") }
378 guard target != path || rewritten != text else { return show("Nothing to rename") }
379 if rewritten != text, case .failed(let message) = session.perform(ReplaceText(old: text, new: rewritten), path: path, at: 0, expect: nil) { return show(message) }
380 guard target != path else { return show("Front matter rewritten") }
376381 rename(path, to: target)
377382 }
378383
@@ -405,7 +410,7 @@ public struct RoamActions {
405410 func renameNote() {
406411 guard let path = session.path else { return show("No file is open") }
407412 guard let text = session.text(of: path) else { return show("Can't read \((path as NSString).lastPathComponent)") }
408 let name = Denote.name(ofFile: path), front = Denote.frontMatter(of: text)
413 let name = Denote.name(ofFile: path), type = Denote.FileType(path: path, text: text) ?? .org, front = Denote.frontMatter(of: text, type: type)
409414 var title = front.title ?? name.title?.replacingOccurrences(of: "-", with: " ") ?? ""
410415 var keywords = front.keywords ?? name.keywords
411416 var signature = name.signature ?? front.signature ?? ""
@@ -433,7 +438,7 @@ public struct RoamActions {
433438 ask(prompts.dropFirst())
434439 }
435440 case "date":
436 self.ask(Prompt(key: "date", message: "Rename \(file) with DATE: ", date: Prompt.DateRead(defaultDate: Denote.date(of: text)))) { answer in
441 self.ask(Prompt(key: "date", message: "Rename \(file) with DATE: ", date: Prompt.DateRead(defaultDate: Denote.date(of: text, type: type)))) { answer in
437442 guard let answer else { return }
438443 date = answer.isEmpty ? nil : Self.date(answer)
439444 ask(prompts.dropFirst())
@@ -443,7 +448,7 @@ public struct RoamActions {
443448 }
444449 func finish() {
445450 let (target, rewritten) = DenoteNote.renaming(path, text: text, title: title, keywords: keywords, signature: signature, date: date,
446 roots: DenoteNote.directories(roots: roots()))
451 roots: DenoteNote.directories(roots: roots()), preferred: OrgPreferences.denoteFileType())
447452 guard target != path || rewritten != text else { return show("Nothing to rename") }
448453 if rewritten != text, case .failed(let message) = session.perform(ReplaceText(old: text, new: rewritten), path: path, at: 0, expect: nil) { return show(message) }
449454 guard target != path else { return show("Front matter rewritten") }
@@ -453,7 +458,8 @@ public struct RoamActions {
453458 }
454459
455460 /// `denote-dired-rename-marked-files-using-front-matter`, with every Denote note in a
456 /// folder of `denote-directory` marked: each renamed from its front matter.
461 /// folder of `denote-directory` marked: each renamed from its front matter, which is
462 /// rewritten from the values read.
457463 func renameFolderFromFrontMatter() {
458464 let folders = DenoteNote.folderChoices(DenoteNote.directories(roots: roots()))
459465 guard !folders.isEmpty else { return show("No folder for notes") }
@@ -464,9 +470,17 @@ public struct RoamActions {
464470 for name in ((try? FileManager.default.contentsOfDirectory(atPath: folder)) ?? []).sorted() where Denote.identifier(ofFile: name) != nil {
465471 let path = (folder as NSString).appendingPathComponent(name)
466472 guard let text = session.text(of: path) ?? (try? String(contentsOfFile: path, encoding: .utf8)),
467 let target = Denote.renamed(path, text: text), target != path else { continue }
468 guard !FileManager.default.fileExists(atPath: target) else { problems.append("\((target as NSString).lastPathComponent) is already there"); continue }
473 let (target, rewritten) = Denote.renamed(path, text: text), target != path || rewritten != text else { continue }
474 guard target == path || !FileManager.default.fileExists(atPath: target) else { problems.append("\((target as NSString).lastPathComponent) is already there"); continue }
469475 do {
476 if rewritten != text {
477 if session.openPaths.contains(path) {
478 if case .failed(let message) = session.perform(ReplaceText(old: text, new: rewritten), path: path, at: 0, expect: nil) { throw Dailies.Failure(message) }
479 } else {
480 try rewritten.write(toFile: path, atomically: true, encoding: .utf8)
481 }
482 }
483 guard target != path else { continue }
470484 try move(path, to: target)
471485 renamed += 1
472486 if shown == path { open(target, 0) }
Sources/OrgApp/UserConfig.swift +3 · view
@@ -194,6 +194,9 @@ public enum UserConfig {
194194 comment: "the folder denote-journal entries are in, relative to denote-directory", legacy: ""),
195195 Setting(section: "", key: "denote-journal-keyword", defaultsKey: "denoteJournalKeyword", kind: .string, fallback: .string("journal"),
196196 comment: "the keyword journal entries have", legacy: ""),
197 Setting(section: "", key: "denote-file-type", defaultsKey: "denoteFileType",
198 kind: .choice([("org", "org"), ("markdown-yaml", "markdown-yaml"), ("markdown-toml", "markdown-toml"), ("text", "text")]),
199 fallback: .string("org"), comment: "the file type of new Denote notes: org, markdown-yaml, markdown-toml or text", legacy: ""),
197200 Setting(section: "", key: "denote-prompts", defaultsKey: "denotePrompts", kind: .string, fallback: .string("title keywords"),
198201 comment: "what a new Denote note asks, in order, separated by spaces: title keywords subdirectory date template signature", legacy: ""),
199202 Setting(section: "", key: "denote-sequence-scheme", defaultsKey: "denoteSequenceScheme",
Sources/OrgCore/Commands/OrgOnlyCommands.swift +9 −2 · view
@@ -6,14 +6,21 @@ public enum OrgOnlyCommands {
66 id == "org.cycle" || id == "org.cycle-global" || id.hasPrefix("org.fold.")
77 }
88
9 /// Whether `id` is refused in a file that isn't org; `markdown` lets the fold commands run.
10 public static func refuses(_ id: String, markdown: Bool) -> Bool {
9 /// Whether `id` is refused in a file that isn't org; `markdown` lets the fold commands run,
10 /// and a `path` with a Denote file type lets Denote's link and rename commands run.
11 public static func refuses(_ id: String, markdown: Bool, path: String? = nil) -> Bool {
1112 if markdown, folds(id) { return false }
13 if denoteCommands.contains(id), let path, Denote.FileType(path: path) != nil { return false }
1214 if id.hasPrefix("org.") || id.hasPrefix("app.attach.") { return true }
1315 if id.hasPrefix("app.export.") { return !id.hasPrefix("app.export.icalendar-") }
1416 return appCommands.contains(id)
1517 }
1618
19 /// Commands that follow, insert or rename as Denote does in its Markdown and text notes:
20 /// Open Link on a `denote:` link, Insert Node Link, Rename Note and Rename Note from Front
21 /// Matter.
22 static let denoteCommands: Set<String> = ["org.link.open", "app.node.insert", "app.node.rename", "app.node.rename-from-front-matter"]
23
1724 /// App commands that act on the open file's entries, tables, links or Denote front matter.
1825 static let appCommands: Set<String> = [
1926 "app.refile", "app.refile.copy", "app.archive", "app.clock.in", "app.clock.default", "app.copy-rich-text",
Sources/OrgCore/Links/Backlinks.swift +19 −8 · view
@@ -67,22 +67,33 @@ public enum Backlinks {
6767 return Links.normalizedTitle(wanted) == Links.normalizedTitle(title)
6868 }
6969
70 /// Denote's Markdown link, `[description](denote:ID)`.
71 nonisolated(unsafe) private static let markdownLink = /\[([^\]\n]*)\]\((denote:[^()\[\]\s]+)\)/
72
7073 /// The line of `body` with the link to `link` in it, links shown as they read (their
7174 /// description, else what they link to), and the range of that link in the line. A line
72 /// longer than `width` keeps the part around the link.
75 /// longer than `width` keeps the part around the link. Denote's Markdown links count too.
7376 public static func context(in body: String, link: String, width: Int = 160) -> (text: String, link: Range<Int>)? {
7477 for line in body.split(whereSeparator: \.isNewline) {
75 guard line.contains("[[" + link + "]") else { continue }
78 guard line.contains("[[" + link + "]") || line.contains("](" + link + ")") else { continue }
7679 var text = ""
7780 var found: Range<Int>?
7881 var rest = Substring(line)
79 while let match = rest.firstMatch(of: bracketLink) {
80 text += rest[..<match.range.lowerBound]
81 let shown = match.2.map(String.init) ?? String(match.1)
82 while true {
83 let bracket = rest.firstMatch(of: bracketLink), markdown = rest.firstMatch(of: markdownLink)
84 let next: (range: Range<Substring.Index>, target: Substring, shown: String)
85 if let bracket, markdown.map({ bracket.range.lowerBound <= $0.range.lowerBound }) ?? true {
86 next = (bracket.range, bracket.1, bracket.2.map(String.init) ?? String(bracket.1))
87 } else if let markdown {
88 next = (markdown.range, markdown.2, markdown.1.isEmpty ? String(markdown.2) : String(markdown.1))
89 } else {
90 break
91 }
92 text += rest[..<next.range.lowerBound]
8293 let start = text.utf16.count
83 text += shown
84 if found == nil, match.1 == link { found = start..<text.utf16.count }
85 rest = rest[match.range.upperBound...]
94 text += next.shown
95 if found == nil, next.target == link { found = start..<text.utf16.count }
96 rest = rest[next.range.upperBound...]
8697 }
8798 text += rest
8899 guard var range = found else { continue }
Sources/OrgCore/Links/Denote.swift +247 −66 · view
@@ -98,48 +98,167 @@ public enum Denote {
9898 return name + "." + ext
9999 }
100100
101 /// `denote-org-front-matter`, dated as an inactive Org timestamp. The signature line is
102 /// left out when there's none.
103 public static func frontMatter(title: String, date: Date, keywords: [String], identifier: String, signature: String = "", calendar: Calendar = .current) -> String {
104 lines(title: title, date: date, keywords: keywords, identifier: identifier, signature: signature, calendar: calendar)
105 .compactMap(\.line).map { $0 + "\n" }.joined() + "\n"
106 }
107
108 /// The front matter's lines by key, in its order; nil for a signature line there isn't,
109 /// and for the date when `date` is nil.
110 static func lines(title: String, date: Date?, keywords: [String], identifier: String, signature: String, calendar: Calendar) -> [(key: String, line: String?)] {
111 let stamp = date.map { date in
112 let c = calendar.dateComponents([.year, .month, .day, .weekday, .hour, .minute], from: date)
113 let day = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][c.weekday! - 1]
114 return String(format: "[%04d-%02d-%02d %@ %02d:%02d]", c.year!, c.month!, c.day!, day, c.hour!, c.minute!)
115 }
116 let tags = keywords.isEmpty ? "" : ":" + keywords.joined(separator: ":") + ":"
117 return [("title", "#+title: \(title)"), ("date", stamp.map { "#+date: \($0)" }), ("filetags", "#+filetags: \(tags)"),
118 ("identifier", "#+identifier: \(identifier)"), ("signature", signature.isEmpty ? nil : "#+signature: \(signature)")]
119 }
120
121 /// `denote-rewrite-front-matter`: `text` with its front matter lines set to these values,
122 /// a missing one added after the one before it, an empty signature's removed, other lines
123 /// kept. A nil `date` keeps the date line. Without front matter, `denote-prepend-front-matter`:
124 /// all of it before the text, dated `date` or `now`.
101 // MARK: - File types
102
103 /// `denote-file-types`: the formats Denote writes notes in.
104 public enum FileType: String, Sendable, CaseIterable {
105 case org
106 /// Markdown with YAML front matter between `---` lines.
107 case markdownYAML = "markdown-yaml"
108 /// Markdown with TOML front matter between `+++` lines.
109 case markdownTOML = "markdown-toml"
110 /// Plain text, the front matter ended by a line of dashes.
111 case text
112
113 /// The extension, without the dot.
114 public var ext: String {
115 switch self {
116 case .org: "org"
117 case .markdownYAML, .markdownTOML: "md"
118 case .text: "txt"
119 }
120 }
121
122 public var isMarkdown: Bool { self == .markdownYAML || self == .markdownTOML }
123
124 /// `denote-file-type` of a file: by its extension, `.md` by whether `text` starts with
125 /// `---` or `+++`, else `preferred` when that is a Markdown type, else YAML. Nil for a
126 /// file Denote has no type for.
127 public init?(path: String, text: String? = nil, preferred: FileType = .org) {
128 switch (path as NSString).pathExtension {
129 case "org": self = .org
130 case "txt": self = .text
131 case "md":
132 if text?.hasPrefix("---") == true { self = .markdownYAML }
133 else if text?.hasPrefix("+++") == true { self = .markdownTOML }
134 else { self = preferred.isMarkdown ? preferred : .markdownYAML }
135 default: return nil
136 }
137 }
138 }
139
140 /// A front matter line, in the template's order.
141 enum Component: CaseIterable { case title, date, keywords, identifier, signature }
142
143 /// The key a component's line starts with, as `denote-file-types`'s key regexps match it.
144 static func key(_ component: Component, _ type: FileType) -> String {
145 let name = switch component {
146 case .title: "title"
147 case .date: "date"
148 case .keywords: type == .org ? "filetags" : "tags"
149 case .identifier: "identifier"
150 case .signature: "signature"
151 }
152 return type == .org ? "#+" + name : name
153 }
154
155 /// The key as the template writes it, separator and padding included.
156 static func written(_ component: Component, _ type: FileType) -> String {
157 let key = key(component, type)
158 let padding = String(repeating: " ", count: max(0, (type == .org ? 12 : 10) - key.count))
159 return type == .markdownTOML ? key + padding + " = " : key + ":" + padding + " "
160 }
161
162 /// Where the value starts on `line` when it is `component`'s line: after the key, the
163 /// spaces before the separator, the separator and the spaces after it. Keys match without
164 /// case; an Org key may be indented.
165 static func valueStart(_ line: Substring, _ component: Component, _ type: FileType) -> String.Index? {
166 var rest = type == .org ? line.drop { $0 == " " || $0 == "\t" } : line
167 let key = key(component, type)
168 guard rest.prefix(key.count).lowercased() == key else { return nil }
169 rest = rest.dropFirst(key.count).drop { $0 == " " || $0 == "\t" }
170 guard rest.first == (type == .markdownTOML ? "=" : ":") else { return nil }
171 return rest.dropFirst().drop { $0 == " " || $0 == "\t" }.startIndex
172 }
173
174 /// `%S` of a string: quoted, with `"` and `\` escaped.
175 static func quoted(_ s: String) -> String {
176 "\"" + s.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\"") + "\""
177 }
178
179 /// A date as the type's `:date-value-function` writes it: an inactive Org timestamp,
180 /// RFC 3339 for Markdown, ISO 8601 for text.
181 static func stamp(_ date: Date, _ type: FileType, calendar: Calendar) -> String {
182 let c = calendar.dateComponents([.year, .month, .day, .weekday, .hour, .minute, .second], from: date)
183 let day = String(format: "%04d-%02d-%02d", c.year!, c.month!, c.day!)
184 switch type {
185 case .org:
186 return String(format: "[%@ %@ %02d:%02d]", day, ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][c.weekday! - 1], c.hour!, c.minute!)
187 case .markdownYAML, .markdownTOML:
188 let offset = calendar.timeZone.secondsFromGMT(for: date) / 60
189 return String(format: "%@T%02d:%02d:%02d%@%02d:%02d", day, c.hour!, c.minute!, c.second!, offset < 0 ? "-" : "+", abs(offset) / 60, abs(offset) % 60)
190 case .text:
191 return day
192 }
193 }
194
195 /// Each component's value as the type writes it; nil for the date when `date` is nil.
196 static func values(title: String, date: Date?, keywords: [String], identifier: String, signature: String, type: FileType, calendar: Calendar) -> [Component: String] {
197 let md = type.isMarkdown
198 let tags = switch type {
199 case .org: keywords.isEmpty ? "" : ":" + keywords.joined(separator: ":") + ":"
200 case .markdownYAML, .markdownTOML: "[" + keywords.map(quoted).joined(separator: ", ") + "]"
201 case .text: keywords.joined(separator: " ")
202 }
203 var values: [Component: String] = [.title: md ? quoted(title) : title, .keywords: tags, .identifier: md ? quoted(identifier) : identifier,
204 .signature: md ? quoted(signature) : signature]
205 values[.date] = date.map { stamp($0, type, calendar: calendar) }
206 return values
207 }
208
209 /// The front matter of a new note, as `denote--format-front-matter` writes the type's
210 /// template (`denote-org-front-matter` and the others): every line, except the signature's
211 /// when there is none, then a blank line.
212 public static func frontMatter(
213 title: String, date: Date, keywords: [String], identifier: String, signature: String = "", type: FileType = .org, calendar: Calendar = .current
214 ) -> String {
215 let values = values(title: title, date: date, keywords: keywords, identifier: identifier, signature: signature, type: type, calendar: calendar)
216 let lines = Component.allCases.filter { $0 != .signature || !signature.isEmpty }.map { written($0, type) + values[$0]! }
217 let (open, close): ([String], [String]) = switch type {
218 case .org: ([], [])
219 case .markdownYAML: (["---"], ["---"])
220 case .markdownTOML: (["+++"], ["+++"])
221 case .text: ([], ["---------------------------"])
222 }
223 return (open + lines + close).map { $0 + "\n" }.joined() + "\n"
224 }
225
226 /// `denote-rewrite-front-matter`: `text` with its front matter set to these values. A line
227 /// that is there keeps its key and spacing and gets the new value; an empty signature's
228 /// line goes; a missing line with a value is added after the line before it in the
229 /// template, else before the one after it. A nil `date` keeps the date line. Without front
230 /// matter, `denote-prepend-front-matter`: all of it before the text, dated `date` or `now`.
125231 public static func rewritingFrontMatter(
126 _ text: String, title: String, keywords: [String], signature: String, date: Date?, identifier: String, now: Date = Date(), calendar: Calendar = .current
232 _ text: String, title: String, keywords: [String], signature: String, date: Date?, identifier: String, now: Date = Date(),
233 type: FileType = .org, calendar: Calendar = .current
127234 ) -> String {
128235 var lines = text.components(separatedBy: "\n")
129 let wanted = Self.lines(title: title, date: date, keywords: keywords, identifier: identifier, signature: signature, calendar: calendar)
130 func index(_ key: String) -> Int? {
131 lines.prefix(40).firstIndex { $0.trimmingCharacters(in: .whitespaces).lowercased().hasPrefix("#+" + key + ":") }
132 }
133 guard wanted.contains(where: { index($0.key) != nil }) else {
134 return frontMatter(title: title, date: date ?? now, keywords: keywords, identifier: identifier, signature: signature, calendar: calendar) + text
135 }
136 for (position, item) in wanted.enumerated() {
137 if let at = index(item.key) {
138 if let line = item.line { lines[at] = line } else if item.key == "signature" { lines.remove(at: at) }
139 } else if let line = item.line {
140 let before = wanted[..<position].reversed().compactMap { index($0.key) }.first
141 let after = wanted[(position + 1)...].compactMap { index($0.key) }.first
142 lines.insert(line, at: before.map { $0 + 1 } ?? after ?? 0)
236 let values = values(title: title, date: date, keywords: keywords, identifier: identifier, signature: signature, type: type, calendar: calendar)
237 func index(_ component: Component) -> Int? {
238 lines.prefix(40).firstIndex { valueStart($0[...], component, type) != nil }
239 }
240 guard Component.allCases.contains(where: { index($0) != nil }) else {
241 return frontMatter(title: title, date: date ?? now, keywords: keywords, identifier: identifier, signature: signature, type: type, calendar: calendar) + text
242 }
243 let all = Component.allCases
244 for (position, component) in all.enumerated() {
245 let hasValue = switch component {
246 case .title: !title.isEmpty
247 case .date: date != nil
248 case .keywords: !keywords.isEmpty
249 case .identifier: !identifier.isEmpty
250 case .signature: !signature.isEmpty
251 }
252 if let at = index(component) {
253 if component == .signature, !hasValue {
254 lines.remove(at: at)
255 } else if let value = values[component], let start = valueStart(lines[at][...], component, type) {
256 lines[at] = String(lines[at][..<start]) + value
257 }
258 } else if hasValue, let value = values[component] {
259 let before = all[..<position].reversed().compactMap { index($0) }.first
260 let after = all[(position + 1)...].compactMap { index($0) }.first
261 lines.insert(written(component, type) + value, at: before.map { $0 + 1 } ?? after ?? 0)
143262 }
144263 }
145264 return lines.joined(separator: "\n")
@@ -172,41 +291,103 @@ public enum Denote {
172291 return name
173292 }
174293
175 /// The `#+title`, `#+filetags`, `#+identifier` and `#+signature` of a file's front matter.
176 public static func frontMatter(of text: String) -> (title: String?, keywords: [String]?, identifier: String?, signature: String?) {
177 func value(_ key: String) -> String? {
178 for line in text.split(separator: "\n", omittingEmptySubsequences: false).prefix(40) {
179 let trimmed = line.trimmingCharacters(in: .whitespaces)
180 guard trimmed.lowercased().hasPrefix("#+" + key + ":") else { continue }
181 return trimmed.dropFirst(key.count + 3).trimmingCharacters(in: .whitespaces)
182 }
183 return nil
294
295 /// A component's value on its first line among the first 40, untrimmed.
296 static func rawValue(_ component: Component, in text: String, type: FileType) -> Substring? {
297 for line in text.split(separator: "\n", omittingEmptySubsequences: false).prefix(40) {
298 if let start = valueStart(line, component, type) { return line[start...] }
299 }
300 return nil
301 }
302
303 /// The title, keywords, identifier and signature of a file's front matter, read as the
304 /// type's `:…-value-reverse-function`s read them: Markdown values without the whitespace
305 /// and quotes around them, keywords split at colons, commas and spaces.
306 public static func frontMatter(of text: String, type: FileType = .org) -> (title: String?, keywords: [String]?, identifier: String?, signature: String?) {
307 func value(_ component: Component) -> String? {
308 guard let raw = rawValue(component, in: text, type: type) else { return nil }
309 let trimmed = raw.trimmingCharacters(in: .whitespaces)
310 return type.isMarkdown ? trimmed.trimmingCharacters(in: CharacterSet(charactersIn: "\"'")) : trimmed
184311 }
185 let keywords = value("filetags").map { $0.split(separator: ":").map(String.init).filter { !$0.isEmpty } }
186 return (value("title"), keywords, value("identifier")?.nonEmptyOrNil, value("signature"))
312 let keywords = rawValue(.keywords, in: text, type: type).map { raw in
313 type == .org ? raw.split(separator: ":").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty }
314 : raw.split { $0 == ":" || $0 == "," || $0.isWhitespace }.map { $0.trimmingCharacters(in: CharacterSet(charactersIn: "[] \"'")) }.filter { !$0.isEmpty }
315 }
316 return (value(.title), keywords, value(.identifier)?.nonEmptyOrNil, value(.signature))
187317 }
188318
189 /// The front matter's `#+date:`, an Org timestamp, in `calendar`'s time zone.
190 public static func date(of text: String, calendar: Calendar = .current) -> Date? {
191 guard let match = text.firstMatch(of: /(?im)^[ \t]*#\+date:[ \t]*[\[<](\d{4})-(\d{2})-(\d{2})(?:[^\]>\d]*(\d{1,2}):(\d{2}))?/) else { return nil }
192 return calendar.date(from: DateComponents(year: Int(match.1), month: Int(match.2), day: Int(match.3),
193 hour: match.4.flatMap { Int($0) } ?? 0, minute: match.5.flatMap { Int($0) } ?? 0))
319 /// The front matter of the file at `path`, read in its type; Org's for a file Denote has
320 /// no type for.
321 public static func frontMatter(ofFile path: String, text: String) -> (title: String?, keywords: [String]?, identifier: String?, signature: String?) {
322 frontMatter(of: text, type: FileType(path: path, text: text) ?? .org)
194323 }
195324
196 /// `denote-rename-file-using-front-matter`: the name the file at `path` takes from its
197 /// front matter's title, keywords and signature, each empty when its line is missing. Nil
198 /// when the file has no front matter, or no identifier in it or its name.
199 public static func renamed(_ path: String, text: String) -> String? {
325 /// The front matter's date in `calendar`'s time zone: an Org timestamp, or for the other
326 /// types `YYYY-MM-DD`, optionally with a time and a UTC offset.
327 public static func date(of text: String, type: FileType = .org, calendar: Calendar = .current) -> Date? {
328 if type == .org {
329 guard let match = text.firstMatch(of: /(?im)^[ \t]*#\+date:[ \t]*[\[<](\d{4})-(\d{2})-(\d{2})(?:[^\]>\d]*(\d{1,2}):(\d{2}))?/) else { return nil }
330 return calendar.date(from: DateComponents(year: Int(match.1), month: Int(match.2), day: Int(match.3),
331 hour: match.4.flatMap { Int($0) } ?? 0, minute: match.5.flatMap { Int($0) } ?? 0))
332 }
333 guard let raw = rawValue(.date, in: text, type: type),
334 let match = raw.firstMatch(of: /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?[ \t]*(Z|[+-]\d{2}:?\d{2})?/) else { return nil }
335 var components = DateComponents(year: Int(match.1), month: Int(match.2), day: Int(match.3),
336 hour: match.4.flatMap { Int($0) } ?? 0, minute: match.5.flatMap { Int($0) } ?? 0, second: match.6.flatMap { Int($0) } ?? 0)
337 if let zone = match.7 {
338 let digits = zone.filter(\.isNumber)
339 let minutes = zone == "Z" ? 0 : (Int(digits.prefix(2))! * 60 + Int(digits.suffix(2))!) * (zone.hasPrefix("-") ? -1 : 1)
340 components.timeZone = TimeZone(secondsFromGMT: minutes * 60)
341 }
342 return calendar.date(from: components)
343 }
344
345 /// `denote-rename-file-using-front-matter`: the path the file at `path` takes from its
346 /// front matter's title, keywords and signature, each empty when its line is missing, and
347 /// its text with the front matter rewritten from those values, keywords sorted. Nil for a
348 /// file Denote has no type for, one without front matter, or one without an identifier in
349 /// it or its name.
350 public static func renamed(_ path: String, text: String) -> (path: String, text: String)? {
351 guard let type = FileType(path: path, text: text) else { return nil }
200352 let current = name(ofFile: path)
201 let front = frontMatter(of: text)
353 let front = frontMatter(of: text, type: type)
202354 guard front.title != nil || front.keywords != nil || front.identifier != nil || front.signature != nil,
203355 let identifier = front.identifier ?? current.identifier else { return nil }
204 // In the front matter's order: Denote sorts keywords only as it prompts for them.
205 var seen = Set<String>()
206 let keywords = (front.keywords ?? []).map(keyword).filter { !$0.isEmpty && seen.insert($0).inserted }
207 let file = fileName(identifier: identifier, signature: front.signature.map(signature), title: front.title ?? "", keywords: keywords,
208 extension: current.ext.isEmpty ? "org" : current.ext)
209 return ((path as NSString).deletingLastPathComponent as NSString).appendingPathComponent(file)
356 let keywords = Self.keywords(front.keywords ?? []), signature = signature(front.signature ?? ""), title = front.title ?? ""
357 let date = rawValue(.date, in: text, type: type) == nil ? nil : date(of: text, type: type)
358 let file = fileName(identifier: identifier, signature: signature, title: title, keywords: keywords, extension: current.ext)
359 return (((path as NSString).deletingLastPathComponent as NSString).appendingPathComponent(file),
360 rewritingFrontMatter(text, title: title, keywords: keywords, signature: signature, date: date, identifier: identifier, type: type))
361 }
362
363 // MARK: - Links in Markdown and text notes
364
365 /// A link to `link` described by `description`, as `denote-format-link` writes it in the
366 /// file at `path`: `[description](denote:ID)` in Markdown (`denote-md-link-format`), Org's
367 /// bracket link elsewhere, and `[[denote:ID]]` without a description.
368 public static func linkText(_ link: String, description: String, inFile path: String?) -> String {
369 let description = description.trimmingCharacters(in: .whitespacesAndNewlines)
370 guard link.hasPrefix("denote:"), let path, FileType(path: path)?.isMarkdown == true else { return Links.makeString(link, description) }
371 return description.isEmpty ? "[[" + link + "]]" : "[" + description + "](" + link + ")"
372 }
373
374 static let orgLink = try! NSRegularExpression(pattern: #"\[\[(denote:[^\[\]\n]+)\](?:\[[^\]\n]*\])?\]"#)
375 static let markdownLink = try! NSRegularExpression(pattern: #"\[[^\]\n]*\]\((denote:[^()\[\]\s]+)\)"#)
376
377 /// The `denote:` links in a Markdown or text note, as UTF-16 ranges and what they link to:
378 /// `[[denote:ID]]` and `[[denote:ID][description]]` in both, as Denote's link regexps find
379 /// them, and `[description](denote:ID)` in Markdown.
380 public static func links(in text: String, markdown: Bool) -> [(range: Range<Int>, target: String)] {
381 guard text.contains("denote:") else { return [] }
382 let ns = text as NSString, whole = NSRange(location: 0, length: ns.length)
383 return ((markdown ? [orgLink, markdownLink] : [orgLink]).flatMap { $0.matches(in: text, range: whole) })
384 .sorted { $0.range.location < $1.range.location }
385 .map { (Range($0.range)!, ns.substring(with: $0.range(at: 1))) }
386 }
387
388 /// The `denote:` link at `offset` in a Markdown or text note.
389 public static func link(at offset: Int, in text: String, markdown: Bool) -> OrgLink? {
390 links(in: text, markdown: markdown).first { $0.range.contains(offset) || $0.range.upperBound == offset }.map { Links.parse(plain: $0.target) }
210391 }
211392}
212393
Sources/OrgCore/Links/Links.swift +13 −1 · view
@@ -263,11 +263,16 @@ public struct OpenLinkAtPoint: OrgCommand {
263263 public var id: String { "org.link.open" }
264264 public var title: String { "Open Link" }
265265 public func applies(in context: EditContext) -> Bool {
266 Links.link(at: context.caret, text: context.text, tree: context.tree) != nil
266 if let markdown = Self.denoteText(context) { return Denote.link(at: context.caret, in: context.text, markdown: markdown) != nil }
267 return Links.link(at: context.caret, text: context.text, tree: context.tree) != nil
267268 || Citations.keys(at: context.caret, text: context.text, tree: context.tree) != nil
268269 || Links.timestampDays(at: context.caret, text: context.text) != nil
269270 }
270271 public func run(in context: EditContext) -> CommandStep {
272 if let markdown = Self.denoteText(context) {
273 guard let link = Denote.link(at: context.caret, in: context.text, markdown: markdown) else { return .failed("No link to follow here") }
274 return .external(.openLink(link))
275 }
271276 if let found = Links.link(at: context.caret, text: context.text, tree: context.tree) {
272277 return .external(.openLink(found.link))
273278 }
@@ -279,6 +284,13 @@ public struct OpenLinkAtPoint: OrgCommand {
279284 }
280285 return .failed("No link to follow here")
281286 }
287
288 /// In a Markdown or text file Denote has a type for, whether it is Markdown: only its
289 /// `denote:` links are followed there. Nil in other files.
290 static func denoteText(_ context: EditContext) -> Bool? {
291 guard let path = context.options.filePath, let type = Denote.FileType(path: path), type != .org else { return nil }
292 return type.isMarkdown
293 }
282294}
283295
284296extension Links {
Sources/OrgEditorAppKit/OrgEditor.swift +10 −4 · view
@@ -173,9 +173,15 @@ public final class OrgEditor: NSObject {
173173 self.redrawShaded([view.selectedRange()])
174174 }
175175 view.onCommandClick = { [weak self, unowned view] offset in
176 guard let self, Links.link(at: offset, text: self.document.text, tree: self.document.tree) != nil
177 || Links.citation(at: offset, text: self.document.text, tree: self.document.tree) != nil
178 || Links.timestampDays(at: offset, text: self.document.text) != nil else { return false }
176 guard let self else { return false }
177 if !self.isOrg {
178 // Only Denote's links are followed outside org.
179 guard Denote.link(at: offset, in: self.document.text, markdown: self.isMarkdown) != nil else { return false }
180 } else {
181 guard Links.link(at: offset, text: self.document.text, tree: self.document.tree) != nil
182 || Links.citation(at: offset, text: self.document.text, tree: self.document.tree) != nil
183 || Links.timestampDays(at: offset, text: self.document.text) != nil else { return false }
184 }
179185 self.active = view
180186 self.setCaret(offset)
181187 self.run("org.link.open")
@@ -617,7 +623,7 @@ public final class OrgEditor: NSObject {
617623 /// Whether `id` is refused because the file isn't org: in Markdown only the fold commands
618624 /// of org's run, so none writes org into the file.
619625 func refuses(_ id: String) -> Bool {
620 !isOrg && OrgOnlyCommands.refuses(id, markdown: isMarkdown)
626 !isOrg && OrgOnlyCommands.refuses(id, markdown: isMarkdown, path: options.filePath)
621627 }
622628
623629 /// The file's structure for folding: the org tree, or for Markdown a tree of its headings.
Sources/OrgIndex/FileRecord.swift +21 −10 · view
@@ -7,8 +7,8 @@ public enum FileKind: String, Sendable {
77 case archive
88 /// A Syncthing conflict copy: listed, never indexed for search, agenda or IDs.
99 case conflict
10 /// Markdown or plain text: searched, titled by its front matter or first heading;
11 /// never read for the agenda, IDs or links.
10 /// Markdown or plain text: searched, titled by its front matter or first heading, read
11 /// for Denote's links; never read for the agenda or IDs.
1212 case text
1313 /// Any other file: listed and openable, never read by the index.
1414 case other
@@ -138,11 +138,10 @@ public struct FileRecord: Sendable, Equatable {
138138 let source = SourceText(bytes: bytes)
139139 if kind == .text {
140140 settingsVersion = settings.version
141 links = []
142141 fileID = nil
143142 fileTags = []
144143 fileRoam = RoamProperties()
145 (headings, title, preamble) = Self.textRows(source.text, path: path)
144 (headings, links, title, preamble) = Self.textRows(source.text, path: path)
146145 return
147146 }
148147 var resolved = settings
@@ -152,10 +151,20 @@ public struct FileRecord: Sendable, Equatable {
152151 ? ([], [], nil, nil, "", [], RoamProperties()) : Self.rows(source.text, settings: resolved)
153152 }
154153
155 /// A Markdown file's headings, with their own text as bodies, its title and the text
156 /// before its first heading; a plain text file's text, untitled.
157 static func textRows(_ text: String, path: String) -> (headings: [HeadingRecord], title: String?, preamble: String) {
158 guard Markdown.isPath(path) else { return ([], nil, text) }
154 /// A Markdown file's headings, with their own text as bodies and the Denote links in them,
155 /// the links before its first heading, its title and the text before its first heading; a
156 /// plain text file's links and text, titled by its Denote front matter when its name has a
157 /// Denote identifier.
158 static func textRows(_ text: String, path: String) -> (headings: [HeadingRecord], links: [LinkRow], title: String?, preamble: String) {
159 let markdown = Markdown.isPath(path)
160 let denoteLinks = Denote.links(in: text, markdown: markdown)
161 func links(_ range: Range<Int>) -> [LinkRow] {
162 denoteLinks.filter { range.contains($0.range.lowerBound) }.map { LinkRow(type: "denote", target: $0.target) }
163 }
164 guard markdown else {
165 let title = Denote.identifier(ofFile: path) == nil ? nil : Denote.frontMatter(of: text, type: .text).title
166 return ([], links(0..<Int.max), title?.isEmpty == false ? title : nil, text)
167 }
159168 let u = Array(text.utf16)
160169 let structure = Markdown.structure(u)
161170 let headings = structure.headings
@@ -170,11 +179,13 @@ public struct FileRecord: Sendable, Equatable {
170179 ordinal: index, parent: open.last, start: heading.start, end: end, level: heading.level,
171180 todo: nil, isDone: false, priority: nil, title: heading.title,
172181 outlinePath: open.map { headings[$0].title } + [heading.title], orgID: nil, archived: false,
173 body: slice(heading.lineEnd..<max(heading.lineEnd, bodyEnd)), tags: [], properties: [], timestamps: [], clocks: [], links: []
182 body: slice(heading.lineEnd..<max(heading.lineEnd, bodyEnd)), tags: [], properties: [], timestamps: [], clocks: [],
183 links: links(heading.start..<max(heading.start, bodyEnd))
174184 ))
175185 open.append(index)
176186 }
177 return (records, Markdown.title(u, structure), slice(0..<(headings.first?.start ?? u.count)))
187 let first = headings.first?.start ?? u.count
188 return (records, links(0..<first), Markdown.title(u, structure), slice(0..<first))
178189 }
179190
180191 /// The settings version a file's rows are built under: the index's, with the keywords of
Sources/OrgIndex/IndexStore.swift +13 −7 · view
@@ -197,6 +197,10 @@ public final class IndexStore: Sendable {
197197 UPDATE files SET settings_version = -1;
198198 """)
199199 }
200 migrator.registerMigration("v6") { db in
201 // Denote's links in Markdown and text files, and Denote titles of text files; they are read again.
202 try db.execute(sql: "UPDATE files SET settings_version = -1 WHERE kind = 'text'")
203 }
200204 return migrator
201205 }
202206
@@ -477,15 +481,17 @@ public final class IndexStore: Sendable {
477481 return indexed.filter { overlay[$0.location.path] == nil } + live
478482 }
479483
480 /// Every Org file with a Denote identifier in its name, as a node with that identifier,
481 /// titled by its `#+TITLE`, else its name; unsaved buffers' titles in place of their files'.
484 /// Every Org, Markdown (`.md`) and text file with a Denote identifier in its name, as a
485 /// node with that identifier, titled by its front matter (an Org file's `#+TITLE`, a
486 /// Markdown file's first heading without one), else its name; unsaved buffers' titles in
487 /// place of their files'.
482488 public func denoteNodes(overlay: [String: FileRecord] = [:]) throws -> [Node] {
483489 func node(_ path: String, _ title: String?, _ hash: String) -> Node? {
484 guard let id = Denote.identifier(ofFile: path) else { return nil }
490 guard Denote.FileType(path: path) != nil, let id = Denote.identifier(ofFile: path) else { return nil }
485491 return Node(id: id, title: title ?? ((path as NSString).lastPathComponent as NSString).deletingPathExtension, location: .file(path, contentHash: hash))
486492 }
487493 let indexed = try database.read { db in
488 try Row.fetchAll(db, sql: "SELECT path, hash, title FROM files WHERE kind = 'org' ORDER BY path").compactMap { node($0["path"], $0["title"], $0["hash"]) }
494 try Row.fetchAll(db, sql: "SELECT path, hash, title FROM files WHERE kind IN ('org', 'text') ORDER BY path").compactMap { node($0["path"], $0["title"], $0["hash"]) }
489495 }
490496 let live = overlay.values.sorted { $0.path < $1.path }.compactMap { node($0.path, $0.title, $0.hash) }
491497 return indexed.filter { overlay[$0.location.path] == nil } + live
@@ -515,18 +521,18 @@ public final class IndexStore: Sendable {
515521 }
516522
517523 /// Every link and the heading it's in, or the file for links before its first heading,
518 /// unsaved buffers' in place of their files'.
524 /// unsaved buffers' in place of their files'. Of Markdown and text files, Denote's links.
519525 public func links(overlay: [String: FileRecord] = [:]) throws -> [(source: HeadingLocation, target: String)] {
520526 let indexed = try database.read { db in
521527 try Row.fetchAll(
522528 db,
523529 sql: """
524530 SELECT f.path, f.hash, -1 AS ordinal, '' AS title, 0 AS start_offset, l.target
525 FROM file_links l JOIN files f ON f.id = l.file_id WHERE f.kind = 'org'
531 FROM file_links l JOIN files f ON f.id = l.file_id WHERE f.kind IN ('org', 'text')
526532 UNION ALL
527533 SELECT f.path, f.hash, h.ordinal, h.title, h.start_offset, l.target
528534 FROM links l JOIN headings h ON h.id = l.heading_id JOIN files f ON f.id = h.file_id
529 WHERE f.kind = 'org' ORDER BY 1, 3
535 WHERE f.kind IN ('org', 'text') ORDER BY 1, 3
530536 """
531537 ).map { row in
532538 let location = location(row)
Sources/Orgstar/ContentView.swift +3 −3 · view
@@ -302,7 +302,7 @@ struct ContentView: View {
302302 if query.isEmpty {
303303 VStack(spacing: 0) {
304304 OutlineColumn(session: session)
305 if backlinksShown, session.isOrg {
305 if backlinksShown, session.isOrg || session.path.flatMap({ Denote.FileType(path: $0) }) != nil {
306306 Divider()
307307 BacklinksPane(workspace: workspace, session: session, commands: commands) { location in
308308 selectedFile = location.path
@@ -987,7 +987,7 @@ struct ContentView: View {
987987 let context = editor.context()
988988 let range = context.selection.first ?? context.caret..<context.caret
989989 let selected = (context.text as NSString).substring(with: NSRange(range))
990 let text = Links.makeString(link, selected.isEmpty ? title : selected)
990 let text = Denote.linkText(link, description: selected.isEmpty ? title : selected, inFile: context.options.filePath)
991991 let end = range.lowerBound + (text as NSString).length
992992 editor.perform(PrecomputedEdit(EditResult(baseRevision: context.revision, edits: [TextEdit(range: range, replacement: text)], selection: [end..<end])))
993993 },
@@ -1390,7 +1390,7 @@ struct ContentView: View {
13901390 return commands.show(Self.unavailable(EditorCommands.all.first { $0.id == id }?.title ?? id))
13911391 }
13921392 if let feature = ProFeature.required(byCommand: id), !ProAccess.shared.allows(feature) { return }
1393 if !session.isOrg, Printing.commands.contains(id) || OrgOnlyCommands.refuses(id, markdown: session.isMarkdown) {
1393 if !session.isOrg, Printing.commands.contains(id) || OrgOnlyCommands.refuses(id, markdown: session.isMarkdown, path: session.path) {
13941394 commands.show(String(localized: "Not an org file"))
13951395 return
13961396 }
Sources/OrgstarMobile/EditorScreen.swift +4 −3 · view
@@ -597,9 +597,10 @@ struct EditorScreen: View {
597597}
598598
599599extension EditorScreen {
600 /// Follows a link; files the editor doesn't open show in Quick Look.
600 /// Follows a link; Markdown and text files open in the editor, other files it doesn't open
601 /// show in Quick Look.
601602 private func follow(_ link: OrgLink) {
602 switch session.follow(link, workspace: workspace, isText: { _ in false }) {
603 switch session.follow(link, workspace: workspace, isText: { Markdown.isPath($0) || Markdown.isPlainTextPath($0) }) {
603604 case .shown:
604605 // A link to another file shows it on its own screen; this pane keeps its file.
605606 guard let pane, let target = pane.path, target != path else { message = nil; return }
@@ -647,7 +648,7 @@ extension EditorScreen {
647648 let context = editor.editContext()
648649 let range = context.selection.first ?? context.caret..<context.caret
649650 let selected = (context.text as NSString).substring(with: NSRange(range))
650 let text = Links.makeString(link, selected.isEmpty ? title : selected)
651 let text = Denote.linkText(link, description: selected.isEmpty ? title : selected, inFile: context.options.filePath)
651652 let end = range.lowerBound + (text as NSString).length
652653 _ = editor.perform(PrecomputedEdit(EditResult(baseRevision: context.revision, edits: [TextEdit(range: range, replacement: text)], selection: [end..<end])))
653654 },
Sources/OrgstarMobile/MobileEditor.swift +5 −2 · view
@@ -112,7 +112,7 @@ final class MobileEditor: NSObject, DocumentBuffer {
112112 /// Whether `id` is refused because the file isn't org: in Markdown only the fold commands
113113 /// of org's run, so none writes org into the file.
114114 func refuses(_ id: String) -> Bool {
115 !isOrg && OrgOnlyCommands.refuses(id, markdown: isMarkdown)
115 !isOrg && OrgOnlyCommands.refuses(id, markdown: isMarkdown, path: options.filePath)
116116 }
117117 var onChange: (() -> Void)?
118118 var onMessage: ((String) -> Void)?
@@ -647,7 +647,10 @@ final class MobileEditor: NSObject, DocumentBuffer {
647647
648648 private func openLinkAtCaret() {
649649 let caret = textView.selectedRange.location
650 if let link = Links.link(at: caret, text: document.text, tree: document.tree)?.link ?? Links.citation(at: caret, text: document.text, tree: document.tree) {
650 if !isOrg {
651 // Only Denote's links are followed outside org.
652 if let link = Denote.link(at: caret, in: document.text, markdown: isMarkdown) { onLink?(link) } else { onMessage?("No link here") }
653 } else if let link = Links.link(at: caret, text: document.text, tree: document.tree)?.link ?? Links.citation(at: caret, text: document.text, tree: document.tree) {
651654 onLink?(link)
652655 } else if let days = Links.timestampDays(at: caret, text: document.text) {
653656 onAgenda?(days.start, days.count)
Tests/OrgAppTests/DailiesTests.swift +65 −1 · view
@@ -153,6 +153,47 @@ struct DailiesTests {
153153 #expect(try String(contentsOfFile: new, encoding: .utf8) == "#+title: New Name\n#+date: [2026-10-11 Sun 12:00]\n#+filetags: :a:b:\n#+identifier: 20261011T120000\n\nBody\n")
154154 }
155155
156 /// Markdown and text notes: made in `denote-file-type`, renamed with their front matter in
157 /// their own format, linked to by Insert Node Link, which only Denote may do outside org.
158 @MainActor
159 @Test func textTypeNotes() throws {
160 let h = try Harness()
161 let defaults = UserDefaults.standard
162 defaults.set("denote", forKey: "notesPackage")
163 defaults.set("markdown-toml", forKey: "denoteFileType")
164 defer { defaults.removeObject(forKey: "notesPackage"); defaults.removeObject(forKey: "denoteFileType") }
165 h.answers = ["node": "Field Notes", "keywords": "work"]
166 h.actions.run("app.node.find")
167 let note = try #require(h.opened.first)
168 #expect(note.hasSuffix("--field-notes__work.md"), "\(h.shown)")
169 #expect(try String(contentsOfFile: note, encoding: .utf8).hasPrefix("+++\ntitle = \"Field Notes\"\ndate = "))
170
171 let path = try h.write("20261011T120000--old__x.txt", "title: Old\ndate: 2026-10-11\ntags: x\nidentifier: 20261011T120000\n---------------------------\n\nBody\n")
172 h.session.open(path)
173 h.opened = []
174 h.answers = ["title": "New Name", "keywords": "b, a"]
175 h.actions.run("app.node.rename")
176 #expect(h.asked.suffix(2).map(\.initial) == ["Old", "x"])
177 let renamed = h.folder.appendingPathComponent("20261011T120000--new-name__a_b.txt").path
178 #expect(h.opened == [renamed], "\(h.shown)")
179 #expect(try String(contentsOfFile: renamed, encoding: .utf8)
180 == "title: New Name\ndate: 2026-10-11\ntags: a b\nidentifier: 20261011T120000\n---------------------------\n\nBody\n")
181
182 let md = try h.write("20261011T130000--edited__x.md", "---\ntitle: \"Edited Title\"\ntags: [\"y\"]\nidentifier: \"20261011T130000\"\n---\n")
183 h.session.open(md)
184 h.opened = []
185 h.actions.run("app.node.rename-from-front-matter")
186 #expect(h.opened == [h.folder.appendingPathComponent("20261011T130000--edited-title__y.md").path], "\(h.shown)")
187
188 h.answers = ["node": "Linked Note", "keywords": ""]
189 h.actions.run("app.node.insert")
190 #expect(h.links.last?.1 == "Linked Note" && h.links.last?.0.hasPrefix("denote:") == true)
191 defaults.removeObject(forKey: "notesPackage")
192 let count = h.links.count
193 h.actions.run("app.node.insert")
194 #expect(h.links.count == count && h.shown.last == "Not an org file")
195 }
196
156197 @MainActor
157198 @Test func renamesFolderFromFrontMatter() throws {
158199 let h = try Harness()
@@ -275,7 +316,7 @@ struct DailiesTests {
275316 actions.renameFromFrontMatter()
276317 let new = folder.appendingPathComponent("20261011T120000--new-name__x_y.org").path
277318 #expect(opened == new && !FileManager.default.fileExists(atPath: old), "\(shown)")
278 #expect(try String(contentsOfFile: new, encoding: .utf8) == "#+title: New Name\n#+filetags: :x:y:\n")
319 #expect(try String(contentsOfFile: new, encoding: .utf8) == "#+title: New Name\n#+filetags: :x:y:\n#+identifier: 20261011T120000\n")
279320 }
280321
281322 @MainActor
@@ -325,6 +366,29 @@ struct NodeIndexTests {
325366 #expect(nodes.map(\.title) == ["A note", "20261012T120000--untitled"])
326367 }
327368
369 /// Markdown and text notes are nodes too, titled by their front matter; their Denote links
370 /// are backlinks.
371 @Test func denoteTextNotesAreNodesAndLink() throws {
372 let store = try IndexStore()
373 let settings = IndexSettings()
374 try store.write(FileRecord(path: "/n/20261011T120000--a__x.org", root: "/n", kind: .org, bytes: Array("#+title: A note\n".utf8), mtime: 1, settings: settings))
375 try store.write(FileRecord(path: "/n/20261013T120000--m.md", root: "/n", kind: .text,
376 bytes: Array("---\ntitle: \"Markdown\"\n---\nSee [A](denote:20261011T120000).\n# Part\nAnd [[denote:20261014T120000][T]].\n".utf8), mtime: 1, settings: settings))
377 try store.write(FileRecord(path: "/n/20261014T120000--t.txt", root: "/n", kind: .text,
378 bytes: Array("title: Text note\nidentifier: 20261014T120000\n---------------------------\n\n[[denote:20261011T120000]]\n".utf8), mtime: 1, settings: settings))
379 try store.write(FileRecord(path: "/n/20261015T120000--other.markdown", root: "/n", kind: .text, bytes: Array("# Other\n".utf8), mtime: 1, settings: settings))
380 let nodes = try store.denoteNodes()
381 #expect(nodes.map(\.id) == ["20261011T120000", "20261013T120000", "20261014T120000"])
382 #expect(nodes.map(\.title) == ["A note", "Markdown", "Text note"])
383 let links = try store.links()
384 #expect(links.map(\.target).sorted() == ["denote:20261011T120000", "denote:20261011T120000", "denote:20261014T120000"])
385 #expect(links.first { $0.target == "denote:20261014T120000" }?.source.title == "Part")
386 let target = Backlinks.Target(path: "/n/20261011T120000--a__x.org")
387 #expect(links.filter { Backlinks.links($0.target, from: $0.source.path, to: target) }.map(\.source.path).sorted()
388 == ["/n/20261013T120000--m.md", "/n/20261014T120000--t.txt"])
389 #expect(Backlinks.context(in: "See [A](denote:20261011T120000) and [[denote:x][X]].", link: "denote:20261011T120000")?.text == "See A and X.")
390 }
391
328392 @Test func filesAndHeadingsWithIDsAreNodes() throws {
329393 let store = try IndexStore()
330394 let settings = IndexSettings()
Tests/OrgAppTests/DenoteOracleTests.swift +87 −3 · view
@@ -73,7 +73,7 @@ struct DenoteOracleTests {
7373 @Test(.enabled(if: enabled)) func filesMatchDenote() throws {
7474 let theirs = try Self.folder(), ours = try Self.folder()
7575 defer { try? FileManager.default.removeItem(at: theirs); try? FileManager.default.removeItem(at: ours) }
76 let front = "#+title: New Title\n#+signature: Two Words\n#+filetags: :Zeta:alpha:\n#+identifier: 20261011T080000\n\nBody\n"
76 let front = "#+title: New Title\n#+signature: Two Words\n#+filetags: :zeta:alpha:\n#+identifier: 20261011T080000\n\nBody\n"
7777 let old = "20261011T080000==1a--old__x.org"
7878 for dir in [theirs, ours] { try front.write(to: dir.appendingPathComponent(old), atomically: true, encoding: .utf8) }
7979 try Self.denote(theirs, """
@@ -81,12 +81,14 @@ struct DenoteOracleTests {
8181 (denote "Field Notes" (denote-keywords-sort (list "work" "ideas")) 'org nil "2026-10-11 12:00:05")
8282 (save-buffer)
8383 (let ((denote-journal-directory nil)) (denote-journal-new-entry "2026-10-11 12:00:00") (save-buffer))
84 (denote-rename-file-using-front-matter \(theirs.appendingPathComponent(old).path.debugDescription)))
84 (denote-rename-file-using-front-matter \(theirs.appendingPathComponent(old).path.debugDescription))
85 (save-some-buffers t))
8586 """)
8687 _ = try DenoteNote.create(title: "Field Notes", keywords: ["work", "ideas"], in: ours.path, now: DailiesTests.day.addingTimeInterval(5))
8788 _ = try Dailies(directory: ours.path, journal: Dailies.Journal()).ensure(DailiesTests.day)
8889 let renamed = Denote.renamed(ours.appendingPathComponent(old).path, text: front)!
89 try FileManager.default.moveItem(atPath: ours.appendingPathComponent(old).path, toPath: renamed)
90 try renamed.text.write(to: ours.appendingPathComponent(old), atomically: true, encoding: .utf8)
91 try FileManager.default.moveItem(atPath: ours.appendingPathComponent(old).path, toPath: renamed.path)
9092
9193 let names = try FileManager.default.contentsOfDirectory(atPath: theirs.path).sorted()
9294 #expect(names.count == 3)
@@ -97,6 +99,88 @@ struct DenoteOracleTests {
9799 }
98100 }
99101
102 /// New notes in the Markdown and text file types, as files Denote and orgstar each make.
103 @Test(.enabled(if: enabled)) func textTypeNotesMatchDenote() throws {
104 let theirs = try Self.folder(), ours = try Self.folder()
105 defer { try? FileManager.default.removeItem(at: theirs); try? FileManager.default.removeItem(at: ours) }
106 let notes: [(type: Denote.FileType, title: String, keywords: [String], signature: String, minute: Int)] = [
107 (.markdownYAML, "Field \"Notes\": a\\b", ["work", "ideas"], "Part One", 1),
108 (.markdownYAML, "Bare", [], "", 2),
109 (.markdownTOML, "Toml Note", ["zeta", "alpha"], "1a", 3),
110 (.markdownTOML, "", [], "", 4),
111 (.text, "Plain Note", ["work", "ideas"], "x", 5),
112 (.text, "Bare Text", [], "", 6),
113 ]
114 let calls = notes.map { n in
115 "(denote \(n.title.debugDescription) (denote-keywords-sort (list \(n.keywords.map(\.debugDescription).joined(separator: " ")))) '\(n.type.rawValue) nil \(String(format: "\"2026-10-11 12:%02d:05\"", n.minute)) nil \(n.signature.debugDescription)) (save-buffer)"
116 }.joined(separator: "\n")
117 try Self.denote(theirs, "(progn \(calls))")
118 for n in notes {
119 _ = try DenoteNote.create(title: n.title, keywords: n.keywords, in: ours.path, now: DailiesTests.day.addingTimeInterval(Double(n.minute * 60 + 5)),
120 signature: n.signature, type: n.type)
121 }
122 let names = try FileManager.default.contentsOfDirectory(atPath: theirs.path).sorted()
123 #expect(names.count == notes.count)
124 #expect(try FileManager.default.contentsOfDirectory(atPath: ours.path).sorted() == names)
125 for name in names {
126 #expect(try String(contentsOf: ours.appendingPathComponent(name), encoding: .utf8)
127 == String(contentsOf: theirs.appendingPathComponent(name), encoding: .utf8), "\(name)")
128 }
129 }
130
131 /// `denote-rename-file` and `denote-rename-file-using-front-matter` on Markdown and text
132 /// notes: front matter rewritten, a line added and one removed, front matter added to a file
133 /// without any, and names and front matter taken from edited front matter.
134 @Test(.enabled(if: enabled)) func textTypeRenamesMatchDenote() throws {
135 let theirs = try Self.folder(), ours = try Self.folder()
136 defer { try? FileManager.default.removeItem(at: theirs); try? FileManager.default.removeItem(at: ours) }
137 let files = [
138 "20261011T120000--old-yaml__x.md": "---\ntitle: \"Old Yaml\"\ndate: 2026-10-11T12:00:00+02:00\ntags: [\"x\"]\nidentifier: \"20261011T120000\"\n---\n\n# Body\n",
139 "20261011T130000==zz--old-toml.md": "+++\ntitle = \"Old Toml\"\ndate = 2026-10-11T13:00:00-05:00\ntags = []\nidentifier = \"20261011T130000\"\nsignature = \"zz\"\n+++\n\nBody\n",
140 "20261011T140000--old-text__x.txt": "title: Old Text\ntags: x\nidentifier: 20261011T140000\n---------------------------\n\nBody\n",
141 "plain.md": "# Heading\n\nNo front matter\n",
142 "plain.txt": "No front matter\n",
143 "20261011T150000--edited-yaml__x.md": "---\ntitle: \"New \\\"Q\\\" Title\"\ndate: 2026-10-11T15:00:00+00:00\ntags: [\"zeta\", \"alpha\"]\nidentifier: \"20261011T150000\"\nsignature: \"Two Words\"\n---\n\nBody\n",
144 "20261011T160000--edited-toml__x.md": "+++\ntitle = 'Toml Title'\ntags = [\"zeta\", \"alpha\"]\nidentifier = \"20261011T160000\"\n+++\n\nBody\n",
145 "20261011T170000--edited-text__x.txt": "title: Text Title\ndate: 2026-10-11\ntags: zeta alpha\nidentifier: 20261011T170000\n---------------------------\n\nBody\n",
146 ]
147 for dir in [theirs, ours] { for (name, text) in files { try text.write(to: dir.appendingPathComponent(name), atomically: true, encoding: .utf8) } }
148 let renames: [(file: String, title: String, keywords: [String], signature: String)] = [
149 ("20261011T120000--old-yaml__x.md", "New \"Yaml\"", ["zeta", "alpha"], "Part One"),
150 ("20261011T130000==zz--old-toml.md", "New Toml", ["k"], ""),
151 ("20261011T140000--old-text__x.txt", "New Text", ["a", "b"], "s1"),
152 ("plain.md", "Plain Markdown", ["k"], ""),
153 ("plain.txt", "Plain Text", [], ""),
154 ]
155 let fromFrontMatter = ["20261011T150000--edited-yaml__x.md", "20261011T160000--edited-toml__x.md", "20261011T170000--edited-text__x.txt"]
156 let calls = renames.map { r in
157 "(denote-rename-file \(theirs.appendingPathComponent(r.file).path.debugDescription) \(r.title.debugDescription) (list \(r.keywords.map(\.debugDescription).joined(separator: " "))) \(r.signature.debugDescription) \"2026-10-11 12:00:00\" \((Denote.identifier(ofFile: r.file) ?? "").debugDescription))"
158 } + fromFrontMatter.map { "(denote-rename-file-using-front-matter \(theirs.appendingPathComponent($0).path.debugDescription))" }
159 try Self.denote(theirs, "(progn " + calls.joined(separator: "\n") + "\n(save-some-buffers t))")
160 let date = Calendar.current.date(from: DateComponents(year: 2026, month: 10, day: 11, hour: 12))!
161 for r in renames {
162 let path = ours.appendingPathComponent(r.file).path
163 let text = try String(contentsOfFile: path, encoding: .utf8)
164 let (target, rewritten) = DenoteNote.renaming(path, text: text, title: r.title, keywords: r.keywords, signature: r.signature, date: date, roots: [ours.path])
165 try rewritten.write(toFile: path, atomically: true, encoding: .utf8)
166 if target != path { try FileManager.default.moveItem(atPath: path, toPath: target) }
167 }
168 for file in fromFrontMatter {
169 let path = ours.appendingPathComponent(file).path
170 let (target, rewritten) = try #require(Denote.renamed(path, text: String(contentsOfFile: path, encoding: .utf8)))
171 try rewritten.write(toFile: path, atomically: true, encoding: .utf8)
172 if target != path { try FileManager.default.moveItem(atPath: path, toPath: target) }
173 }
174 let names = try FileManager.default.contentsOfDirectory(atPath: theirs.path).sorted()
175 #expect(names.contains("20261011T120000==part=one--new-yaml__alpha_zeta.md") && names.contains("20261011T160000--toml-title__alpha_zeta.md"))
176 #expect(!names.contains("plain.md") && !names.contains("plain.txt"))
177 #expect(try FileManager.default.contentsOfDirectory(atPath: ours.path).sorted() == names)
178 for name in names {
179 #expect(try String(contentsOf: ours.appendingPathComponent(name), encoding: .utf8)
180 == String(contentsOf: theirs.appendingPathComponent(name), encoding: .utf8), "\(name)")
181 }
182 }
183
100184 /// A note in a subfolder with a signature and a template, dated a second some file's
101185 /// identifier already has.
102186 @Test(.enabled(if: enabled)) func optionsMatchDenote() throws {
Tests/OrgAppTests/EmacsImportTests.swift +2 · view
@@ -315,6 +315,7 @@ struct EmacsImportTests {
315315 (setq denote-journal-directory "~/notes/journal/" denote-journal-keyword "diary")
316316 (setq denote-journal-title-format 'day-date-month-year-24h)
317317 (setq denote-journal-interval 'weekly)
318 (setq denote-file-type 'markdown-yaml)
318319 """#.write(to: folder.appendingPathComponent("init.el"), atomically: true, encoding: .utf8)
319320 let s = settings(EmacsImport.scan(EmacsImport.files(in: folder)))
320321 #expect(s["denote-directory"] == .string("~/notes/"))
@@ -322,6 +323,7 @@ struct EmacsImportTests {
322323 #expect(s["denote-journal-keyword"] == .string("diary"))
323324 #expect(s["denote-journal-title-format"] == .string("%A %-e %B %Y %H:%M"))
324325 #expect(s["denote-journal-interval"] == .string("weekly"))
326 #expect(s["denote-file-type"] == .string("markdown-yaml"))
325327 }
326328
327329 @MainActor
Tests/OrgCoreTests/DenoteTests.swift +127 −6 · view
@@ -61,13 +61,134 @@ struct DenoteTests {
6161
6262 @Test func renamesFromFrontMatter() {
6363 let text = "#+title: New Title\n#+filetags: :Zeta:alpha:\n#+identifier: 20261119T090503\n\nBody\n"
64 // The signature, like the title and keywords, comes from the front matter.
65 #expect(Denote.renamed("/n/20261119T090503==1a--old__x.org", text: text) == "/n/20261119T090503--new-title__zeta_alpha.org")
66 #expect(Denote.renamed("/n/20261119T090503==1a--old__x.org", text: "#+signature: Two Words\n" + text)
67 == "/n/20261119T090503==two=words--new-title__zeta_alpha.org")
68 #expect(Denote.renamed("/n/plain.org", text: text) == "/n/20261119T090503--new-title__zeta_alpha.org")
64 // The signature, like the title and keywords, comes from the front matter; the
65 // keywords are sorted, and the front matter is rewritten from what was read.
66 #expect(Denote.renamed("/n/20261119T090503==1a--old__x.org", text: text)?.path == "/n/20261119T090503--new-title__alpha_zeta.org")
67 #expect(Denote.renamed("/n/20261119T090503==1a--old__x.org", text: text)?.text == text.replacingOccurrences(of: ":Zeta:alpha:", with: ":alpha:zeta:"))
68 #expect(Denote.renamed("/n/20261119T090503==1a--old__x.org", text: "#+signature: Two Words\n" + text)?.path
69 == "/n/20261119T090503==two=words--new-title__alpha_zeta.org")
70 #expect(Denote.renamed("/n/plain.org", text: text)?.path == "/n/20261119T090503--new-title__alpha_zeta.org")
6971 #expect(Denote.renamed("/n/plain.org", text: "#+title: x\n") == nil)
7072 #expect(Denote.renamed("/n/20261119T090503--old-name__x.org", text: "No front matter\n") == nil)
71 #expect(Denote.renamed("/n/20261119T090503--old-name__x.org", text: "#+title: Only a title\n") == "/n/20261119T090503--only-a-title.org")
73 #expect(Denote.renamed("/n/20261119T090503--old-name__x.org", text: "#+title: Only a title\n")?.path == "/n/20261119T090503--only-a-title.org")
74 #expect(Denote.renamed("/n/20261119T090503--a.pdf", text: "#+title: Not a type\n") == nil)
75 }
76
77 // MARK: - Markdown and text notes
78
79 @Test func fileTypes() {
80 #expect(Denote.FileType(path: "/n/a.org") == .org)
81 #expect(Denote.FileType(path: "/n/a.txt") == .text)
82 #expect(Denote.FileType(path: "/n/a.md", text: "---\ntitle: x\n---\n") == .markdownYAML)
83 #expect(Denote.FileType(path: "/n/a.md", text: "+++\ntitle = \"x\"\n+++\n") == .markdownTOML)
84 #expect(Denote.FileType(path: "/n/a.md", text: "# x\n") == .markdownYAML)
85 #expect(Denote.FileType(path: "/n/a.md", text: "# x\n", preferred: .markdownTOML) == .markdownTOML)
86 #expect(Denote.FileType(path: "/n/a.md", text: "# x\n", preferred: .text) == .markdownYAML)
87 #expect(Denote.FileType(path: "/n/a.markdown") == nil && Denote.FileType(path: "/n/a.pdf") == nil)
88 }
89
90 @Test func textTypeFrontMatter() {
91 var calendar = Self.calendar
92 #expect(Denote.frontMatter(title: "A \"q\" note", date: Self.date, keywords: ["a", "b"], identifier: "20261119T090503", signature: "1a",
93 type: .markdownYAML, calendar: calendar) == """
94 ---
95 title: "A \\"q\\" note"
96 date: 2026-11-19T09:05:03+00:00
97 tags: ["a", "b"]
98 identifier: "20261119T090503"
99 signature: "1a"
100 ---
101
102
103 """)
104 calendar.timeZone = TimeZone(secondsFromGMT: -5 * 3600 - 1800)!
105 #expect(Denote.frontMatter(title: "A", date: Self.date, keywords: [], identifier: "20261119T090503", type: .markdownTOML, calendar: calendar) == """
106 +++
107 title = "A"
108 date = 2026-11-19T03:35:03-05:30
109 tags = []
110 identifier = "20261119T090503"
111 +++
112
113
114 """)
115 #expect(Denote.frontMatter(title: "A", date: Self.date, keywords: ["a", "b"], identifier: "20261119T090503", type: .text, calendar: Self.calendar)
116 == "title: A\ndate: 2026-11-19\ntags: a b\nidentifier: 20261119T090503\n---------------------------\n\n")
117 #expect(Denote.frontMatter(title: "A", date: Self.date, keywords: [], identifier: "20261119T090503", type: .text, calendar: Self.calendar)
118 .contains("\ntags: \n"))
119 }
120
121 @Test func readsTextTypeFrontMatter() {
122 let yaml = "---\ntitle: \"A \\\"q\\\" note\"\ndate: 2026-11-19T10:05:03+01:00\ntags: [\"a\", \"b\"]\nidentifier: \"20261119T090503\"\nsignature: '1a'\n---\n"
123 let front = Denote.frontMatter(of: yaml, type: .markdownYAML)
124 // As Denote reads it: quotes trimmed, backslashes kept.
125 #expect(front.title == #"A \"q\" note"# && front.keywords == ["a", "b"] && front.identifier == "20261119T090503" && front.signature == "1a")
126 #expect(Denote.date(of: yaml, type: .markdownYAML) == Self.date)
127 let toml = "+++\nTitle = \"T\"\ntags = [\"x\",\"y\"]\nidentifier = \"20261119T090503\"\n+++\n"
128 #expect(Denote.frontMatter(of: toml, type: .markdownTOML).title == "T" && Denote.frontMatter(of: toml, type: .markdownTOML).keywords == ["x", "y"])
129 #expect(Denote.frontMatter(of: toml, type: .markdownYAML).title == nil)
130 let text = "title: Plain\ndate: 2026-11-19\ntags: a b\nidentifier: 20261119T090503\n---------------------------\n"
131 #expect(Denote.frontMatter(of: text, type: .text).title == "Plain" && Denote.frontMatter(of: text, type: .text).keywords == ["a", "b"])
132 #expect(Denote.date(of: text, type: .text, calendar: Self.calendar) == Self.calendar.date(from: DateComponents(year: 2026, month: 11, day: 19)))
133 #expect(Denote.frontMatter(ofFile: "/n/x.txt", text: text).title == "Plain")
134 }
135
136 @Test func rewritesTextTypeFrontMatter() {
137 let yaml = "---\ntitle: \"Old\"\ntags: [\"x\"]\nidentifier: \"20261119T090503\"\nsignature: \"zz\"\n---\n\nBody\n"
138 // The key keeps its spacing; a date is added after the title, the signature removed.
139 #expect(Denote.rewritingFrontMatter(yaml, title: "New", keywords: ["a"], signature: "", date: Self.date, identifier: "20261119T090503",
140 type: .markdownYAML, calendar: Self.calendar)
141 == "---\ntitle: \"New\"\ndate: 2026-11-19T09:05:03+00:00\ntags: [\"a\"]\nidentifier: \"20261119T090503\"\n---\n\nBody\n")
142 // No date given: the date line stays and none is added.
143 #expect(Denote.rewritingFrontMatter("title: Old\nidentifier: 1\n---------------------------\n", title: "New", keywords: [], signature: "s",
144 date: nil, identifier: "1", type: .text, calendar: Self.calendar)
145 == "title: New\nidentifier: 1\nsignature: s\n---------------------------\n")
146 // Without front matter, all of it goes first.
147 #expect(Denote.rewritingFrontMatter("# Heading\n", title: "T", keywords: [], signature: "", date: Self.date, identifier: "1",
148 type: .markdownTOML, calendar: Self.calendar).hasPrefix("+++\ntitle = \"T\"\n"))
149 }
150
151 @Test func renamesTextTypesFromFrontMatter() {
152 let toml = "+++\ntitle = 'Toml Title'\ntags = [\"zeta\", \"alpha\"]\nidentifier = \"20261119T090503\"\n+++\n\nBody\n"
153 let renamed = Denote.renamed("/n/20261119T090503--old.md", text: toml)
154 #expect(renamed?.path == "/n/20261119T090503--toml-title__alpha_zeta.md")
155 #expect(renamed?.text == "+++\ntitle = \"Toml Title\"\ntags = [\"alpha\", \"zeta\"]\nidentifier = \"20261119T090503\"\n+++\n\nBody\n")
156 #expect(Denote.renamed("/n/20261119T090503--old.txt", text: "title: Text\ntags: b a\n")?.path == "/n/20261119T090503--text__a_b.txt")
157 #expect(Denote.renamed("/n/20261119T090503--old.md", text: "# No front matter\n") == nil)
158 }
159
160 @Test func linksInTextNotes() {
161 #expect(Denote.linkText("denote:20261119T090503", description: "A note", inFile: "/n/x.md") == "[A note](denote:20261119T090503)")
162 #expect(Denote.linkText("denote:20261119T090503", description: "", inFile: "/n/x.md") == "[[denote:20261119T090503]]")
163 #expect(Denote.linkText("denote:20261119T090503", description: "A note", inFile: "/n/x.txt") == "[[denote:20261119T090503][A note]]")
164 #expect(Denote.linkText("denote:20261119T090503", description: "A note", inFile: "/n/x.org") == "[[denote:20261119T090503][A note]]")
165 #expect(Denote.linkText("id:abc", description: "A", inFile: "/n/x.md") == "[[id:abc][A]]")
166 let text = "See [one](denote:20261119T090501) and [[denote:20261119T090502][two]], [[denote:20261119T090503::#h]], [web](https://x.org).\n"
167 #expect(Denote.links(in: text, markdown: true).map(\.target) == ["denote:20261119T090501", "denote:20261119T090502", "denote:20261119T090503::#h"])
168 #expect(Denote.links(in: text, markdown: false).map(\.target) == ["denote:20261119T090502", "denote:20261119T090503::#h"])
169 #expect(Denote.link(at: 6, in: text, markdown: true)?.path == "20261119T090501")
170 #expect(Denote.link(at: 6, in: text, markdown: false) == nil)
171 #expect(Denote.link(at: 50, in: text, markdown: true)?.type == "denote")
172 #expect(Denote.link(at: 106, in: text, markdown: true) == nil)
173 }
174
175 @Test func followsAndInsertsOnlyDenoteLinksInTextNotes() {
176 var options = EditingOptions.org
177 options.filePath = "/n/20261119T090500--x.md"
178 let text = "[one](denote:20261119T090501) <https://x.org>\n"
179 func context(_ caret: Int) -> EditContext { EditContext(revision: 0, text: text, tree: OrgParser.parse(text), selection: [caret..<caret], options: options) }
180 #expect(OpenLinkAtPoint().applies(in: context(2)))
181 #expect(!OpenLinkAtPoint().applies(in: context(34)))
182 if case .external(.openLink(let link)) = OpenLinkAtPoint().run(in: context(2)) { #expect(link.raw == "denote:20261119T090501") } else { Issue.record("not followed") }
183 for path in ["/n/x.md", "/n/x.txt"] {
184 #expect(!OrgOnlyCommands.refuses("org.link.open", markdown: path.hasSuffix(".md"), path: path))
185 #expect(!OrgOnlyCommands.refuses("app.node.insert", markdown: false, path: path))
186 #expect(!OrgOnlyCommands.refuses("app.node.rename", markdown: false, path: path))
187 #expect(!OrgOnlyCommands.refuses("app.node.rename-from-front-matter", markdown: false, path: path))
188 #expect(OrgOnlyCommands.refuses("app.node.sequence-link", markdown: false, path: path))
189 #expect(OrgOnlyCommands.refuses("org.link.insert", markdown: false, path: path))
190 }
191 #expect(OrgOnlyCommands.refuses("org.link.open", markdown: false, path: "/n/x.py"))
192 #expect(OrgOnlyCommands.refuses("app.node.insert", markdown: true, path: "/n/x.markdown"))
72193 }
73194}
Tests/OrgIndexTests/TextFileRecordTests.swift +11 · view
@@ -27,6 +27,17 @@ struct TextFileRecordTests {
2727 #expect(file.preamble == "* not a heading\n#+title: not a title\n")
2828 }
2929
30 /// Denote's links are read from Markdown and text files, and a text note is titled by its
31 /// Denote front matter.
32 @Test func denoteLinksAndTitles() {
33 let md = record("/notes/20261011T120000--a.md", "Intro [x](denote:20261011T120001)\n# H\n[[denote:20261011T120002][y]] [z](https://z)\n", kind: .text)
34 #expect(md.links.map(\.target) == ["denote:20261011T120001"])
35 #expect(md.headings[0].links.map(\.target) == ["denote:20261011T120002"])
36 let txt = record("/notes/20261011T120003--b.txt", "title: Plain Note\n---------------------------\n\n[x](denote:1) [[denote:20261011T120001]]\n", kind: .text)
37 #expect(txt.title == "Plain Note" && txt.links.map(\.target) == ["denote:20261011T120001"])
38 #expect(record("/notes/b.txt", "title: Not a note\n", kind: .text).title == nil)
39 }
40
3041 @Test func searchFindsTextFiles() throws {
3142 let store = try IndexStore()
3243 try store.write(record("/notes/a.md", "---\ntitle: Pond\n---\nOtters swim.\n# Herons\nThey wade.\n", kind: .text))
docs/manual/guide/01-files-and-folders.org +2 −2 · view
@@ -95,7 +95,7 @@ show-hidden-files = true
9595ignored-folders = ".git .hg node_modules build"
9696#+END_SRC
9797
98Org files (=.org= and =.org_archive=), Markdown files (=.md=, =.markdown=) and =.txt= files are read by the index. Only org files feed the agenda, IDs and links; Markdown and text files are searched. Other files are listed and can be opened, but their contents are not searched.
98Org files (=.org= and =.org_archive=), Markdown files (=.md=, =.markdown=) and =.txt= files are read by the index. Only org files feed the agenda, IDs and links; Markdown and text files are searched, and their =denote:= links are read for backlinks (see [[file:09-links.org][Links]]). Other files are listed and can be opened, but their contents are not searched.
9999
100100** Creating, renaming and trashing files
101101
@@ -206,7 +206,7 @@ While the field holds text, the outline pane shows the results in place of the o
206206
207207How matching works:
208208
209- orgstar searches heading titles, the text under each heading and the text before a file's first heading, in =.org= and =.org_archive= files, and in Markdown files by their =#= headings. A Markdown file's result for the text before its first heading is titled by the =title= in its front matter, else its first heading. A =.txt= file is searched as a whole and titled by its name. Other files are not searched. Syncthing conflict copies are not searched.
209- orgstar searches heading titles, the text under each heading and the text before a file's first heading, in =.org= and =.org_archive= files, and in Markdown files by their =#= headings. A Markdown file's result for the text before its first heading is titled by the =title= in its front matter, else its first heading. A =.txt= file is searched as a whole and titled by its name, or a Denote note's by the =title:= in its front matter. Other files are not searched. Syncthing conflict copies are not searched.
210210- Each word you type matches words that start with it, ignoring case and accents: =proj= finds =project= and =projection=.
211211- Every word must match within the same heading, or within the text before the first heading.
212212- Up to 50 results show, best matches first.
docs/manual/guide/09-links.org +70 −12 · view
@@ -139,6 +139,10 @@ identifier, such as a PDF. A search after =::=, such as =::#custom-id= or =::*He
139139works as in a =file:= link. Backlinks list =denote:= links to a file, and to a heading when
140140the link searches for it.
141141
142In Denote's Markdown and text notes, Open Link (or a =⌘=-click on the Mac) follows
143=[[denote:ID]]= and =[[denote:ID][Title]]=, and in Markdown also Denote's own
144=[Title](denote:ID)=; other links there aren't followed. Backlinks list these notes too.
145
142146** Emacs Lisp links
143147
144148Following an =elisp:= link whose path starts with =(= asks
@@ -428,9 +432,9 @@ reads one =(file+head NAME HEAD)= template into the three settings, and several
428432With =notes-package = "denote"= in =config.toml=, the same commands follow Denote:
429433
430434- The graph draws the notes with a Denote identifier and their =denote:= links to each other.
431- Find Node… and Insert Node Link… list the Org files whose names have a Denote
432 identifier, titled by their =#+title:=, and Insert Node Link… inserts
433 =[[denote:…][Title]]=.
435- Find Node… and Insert Node Link… list the Org, Markdown (=.md=) and text (=.txt=) files
436 whose names have a Denote identifier, titled by their front matter's title, and Insert
437 Node Link… inserts =[[denote:…][Title]]=, or =[Title](denote:…)= in a Markdown note.
434438- A title no note has makes a note in =denote-directory= (the first folder unless set),
435439 after the questions =denote-prompts= lists, in its order. The default is
436440 ="title keywords"=; the title is always the one typed.
@@ -443,9 +447,10 @@ With =notes-package = "denote"= in =config.toml=, the same commands follow Denot
443447 - =signature=: put in the name after ~==~, in lower case with ~=~ between words, and
444448 in a =#+signature:= line.
445449
446 =file-type= and =identifier= are not asked: notes are Org, and the identifier is the
447 date's, or the first second after it no file under =denote-directory= has. With the
448 default prompts:
450 =file-type= and =identifier= are not asked: a note is in the file type
451 =denote-file-type= sets (Org unless set; see /Markdown and text notes/ below), and the
452 identifier is the date's, or the first second after it no file under
453 =denote-directory= has. With the default prompts:
449454
450455 #+BEGIN_SRC org
451456 ,#+title: Field Notes
@@ -482,13 +487,65 @@ kept unique across them.
482487- Rename Note from Front Matter renames the open file from its =#+title:=,
483488 =#+filetags:= and =#+signature:=, keeping its identifier, as
484489 =denote-rename-file-using-front-matter= does. A missing line leaves that part out of
485 the name, and the keywords keep their order.
490 the name. The keywords are sorted, and the front matter is rewritten from what was
491 read: keywords sorted and in lower case, the signature as it is in the name, and an
492 =#+identifier:= line added when there was none.
486493- Rename Notes in Folder from Front Matter… does that for every Denote note in a
487494 folder of =denote-directory=, as =denote-dired-rename-marked-files-using-front-matter=
488495 does with them all marked.
489496
490497Links keep working after a rename, as they use the identifier.
491498
499*** Markdown and text notes
500
501Denote's =markdown-yaml=, =markdown-toml= and =text= file types are read and written
502with their own front matter. With =denote-file-type = "markdown-yaml"= in =config.toml=, a
503new note is =20261119T120000--field-notes__ideas_work.md= and starts:
504
505#+BEGIN_SRC yaml
506---
507title: "Field Notes"
508date: 2026-11-19T12:00:00+01:00
509tags: ["ideas", "work"]
510identifier: "20261119T120000"
511---
512#+END_SRC
513
514=markdown-toml= writes the same lines between =+++= lines, as =title = "Field Notes"=
515and so on. =text= makes a =.txt= note:
516
517#+BEGIN_SRC text
518title: Field Notes
519date: 2026-11-19
520tags: ideas work
521identifier: 20261119T120000
522---------------------------
523#+END_SRC
524
525A =signature:= line follows the identifier when the note has one. A =.md= file is YAML
526when it starts with =---= and TOML when it starts with =+++=; one with neither takes
527=denote-file-type= when that is a Markdown type, else YAML.
528
529In these notes:
530
531- Find Node…, Insert Node Link…, the graph and backlinks work as for Org notes; on the
532 Mac the backlinks pane shows under the outline for them too. Insert
533 Node Link… writes =[Title](denote:ID)= in Markdown and =[[denote:ID][Title]]= in text, as
534 Denote's =denote-md-link-format= and =denote-org-link-format= do; =[[denote:ID]]= when
535 there is no title.
536- Open Link follows =denote:= links (see /denote links/ above).
537- Rename Note…, Rename Note from Front Matter and Rename Notes in Folder from Front
538 Matter… rename them and rewrite their front matter in its own format: Markdown values
539 in double quotes, keywords as =["a", "b"]= in Markdown and separated by two spaces in
540 text, the date as RFC 3339 (=2026-11-19T12:00:00+01:00=) in Markdown and =2026-11-19= in
541 text. A line that is there keeps its key and spacing. A file without front matter gets
542 it at the top.
543
544Otherwise they are Markdown and text files as described in [[file:01-files-and-folders.org][Files and folders]]: org's
545commands, Store Link, the sequence commands and denote-org's blocks aren't available in
546them. Capture templates with =denote = true= and denote-journal's entries are always Org
547notes, since they file org entries, as Denote's =denote-org-capture= does.
548
492549*** Query links
493550
494551=[[denote:query-contents:REGEXP]]= and =[[denote:query-filenames:REGEXP]]= offer the
@@ -574,11 +631,12 @@ A new sequence note asks for its title and the =denote-prompts= questions other
574631
575632*** Importing and limits
576633
577Import from Emacs reads =denote-directory= (a folder or a list), =denote-prompts=,
578=denote-templates=, =denote-silo-directories=, =denote-sequence-scheme=,
579=denote-journal-directory=, =denote-journal-keyword=, =denote-journal-interval= and
580=denote-journal-title-format=. Templates that are functions, and Denote notes in
581Markdown or plain text, are not supported.
634Import from Emacs reads =denote-directory= (a folder or a list), =denote-file-type=,
635=denote-prompts=, =denote-templates=, =denote-silo-directories=,
636=denote-sequence-scheme=, =denote-journal-directory=, =denote-journal-keyword=,
637=denote-journal-interval= and =denote-journal-title-format=. Templates that are functions,
638file types added to =denote-file-types=, =denote-date-format= and the =file-type= prompt
639are not supported.
582640
583641* Inline images
584642
docs/manual/guide/13-configuration.org +3 −1 · view
@@ -226,7 +226,7 @@ These settings have no control in the Settings window. Some are in the View menu
226226| =org-track-ordered-property-with-tag= | |
227227| =org-timer-format=, =org-timer-default-timer= | |
228228| =org-roam-directory=, =org-roam-dailies-directory=, =org-roam-dailies-file=, =org-roam-dailies-head=, =org-roam-dailies-entry= | |
229| =notes-package=, =denote-directory=, =denote-prompts=, =denote-silo-directories=, =denote-sequence-scheme=, =denote-journal-directory=, =denote-journal-keyword=, =denote-journal-interval=, =denote-journal-title-format= | |
229| =notes-package=, =denote-directory=, =denote-file-type=, =denote-prompts=, =denote-silo-directories=, =denote-sequence-scheme=, =denote-journal-directory=, =denote-journal-keyword=, =denote-journal-interval=, =denote-journal-title-format= | |
230230| =org-attach-id-dir=, =org-attach-use-inheritance= | |
231231| =org-cite-global-bibliography= | |
232232| =org-yank-image-save-method=, =org-yank-dnd-method= | |
@@ -291,6 +291,7 @@ A key you remove from the file goes back to its default. A key that isn't in the
291291| =denote-directory= | string | =""= | The folders of Denote notes, separated by =:=, new notes going in the first; empty for the first sidebar folder. Mirrors =denote-directory=. |
292292| =denote-silo-directories= | string | =""= | The folders New Note in Silo… and Find Note in Silo… choose from, separated by =:=; empty for =denote-directory='s. Mirrors =denote-silo-directories=. |
293293| =denote-sequence-scheme= | string | ="numeric"= | How denote-sequence numbers notes: ="numeric"=, ="alphanumeric"= or ="alphanumeric-delimited"=. Mirrors =denote-sequence-scheme=. |
294| =denote-file-type= | string | ="org"= | The file type of new Denote notes: ="org"=, ="markdown-yaml"=, ="markdown-toml"= or ="text"=. Mirrors =denote-file-type=. |
294295| =denote-prompts= | string | ="title keywords"= | What a new Denote note asks, in order, separated by spaces: =title=, =keywords=, =subdirectory=, =date=, =template=, =signature=. Mirrors =denote-prompts=. |
295296| =denote-journal-directory= | string | ="journal"= | The folder journal entries are in, relative to =denote-directory=. Mirrors =denote-journal-directory=. |
296297| =denote-journal-keyword= | string | ="journal"= | The keyword journal entries have. Mirrors =denote-journal-keyword=. |
@@ -833,6 +834,7 @@ Only variables whose names start with =org-=, =appt-=, =display-line-numbers=, =
833834| =denote-prompts= | The same key, the symbols separated by spaces |
834835| =denote-directory= as a list, =denote-silo-directories= | The same key, the folders separated by =:= |
835836| =denote-sequence-scheme=, =denote-journal-interval= | The same key |
837| =denote-file-type= | The same key; =nil= becomes ="org"= |
836838| =denote-templates= | =[denote-templates]=: entries whose text is a string or =concat= of strings; a function is listed as unsupported |
837839| =denote-journal-title-format= | The same key; the symbols =day-date-month-year=, =-24h= and =-12h= become their formats |
838840| =org-roam-dailies-capture-templates= | =org-roam-dailies-file=, =-head= and =-entry=, from one template with a =(file+head NAME HEAD)= target; several as =[[roam-dailies-template]]= tables in =capture.toml= |
docs/manual/guide/14-ios.org +1 −1 · view
@@ -70,7 +70,7 @@ Messages from commands show at the top of the editor and the column view, and at
7070
7171** Markdown and text files
7272
73Markdown files (=.md=, =.markdown=) open straight in the editor, highlighted as on the Mac: headings, emphasis, code, links, lists, block quotes, fenced code and front matter. Fold and open headings with Cycle Visibility and Cycle Global Visibility in Commands, or =TAB= and =S-TAB= with a hardware keyboard; tap a fold's =…= to open it. =.txt= files open as plain text. In both, org's other commands report =Not an org file= and change nothing, the Format menu, Export and dropped attachments are not offered, and typing doesn't pair brackets or fill paragraphs. There is no outline for them on iOS, since the outline is the reader's. See /Markdown/ in [[file:01-files-and-folders.org][Files and folders]] for what is styled and what isn't supported.
73Markdown files (=.md=, =.markdown=) open straight in the editor, highlighted as on the Mac: headings, emphasis, code, links, lists, block quotes, fenced code and front matter. Fold and open headings with Cycle Visibility and Cycle Global Visibility in Commands, or =TAB= and =S-TAB= with a hardware keyboard; tap a fold's =…= to open it. =.txt= files open as plain text. In both, org's other commands report =Not an org file= and change nothing, the Format menu, Export and dropped attachments are not offered, and typing doesn't pair brackets or fill paragraphs. There is no outline for them on iOS, since the outline is the reader's. In a Denote note, Open Link, Insert Node Link… and the Rename Note commands work as on the Mac; see /Markdown and text notes/ in [[file:09-links.org][Links]]. See /Markdown/ in [[file:01-files-and-folders.org][Files and folders]] for what is styled and what isn't supported.
7474
7575** Panes and windows on iPad
7676
docs/manual/guide/15-alongside-emacs.org +1 · view
@@ -293,6 +293,7 @@ Other:
293293- The agenda's text search (see [[file:07-agenda.org][The agenda]]) covers the agenda files only: =org-agenda-text-search-extra-files= and =org-agenda-search-view-max-outline-level= aren't supported. It runs from the view menu rather than the dispatcher's =s= and =S=, and the search view's =[=, =]=, ={= and =}= keys, which add words and regexps to the search, aren't supported.
294294- In regexps, =\<=, =\>= and =\b= use Org's word syntax but don't find a word boundary where the script changes between two word characters, as Emacs does (for example between an emoji and a letter).
295295- org-roam: nodes come from orgstar's index, not org-roam's database; the graph is orgstar's own (see [[file:09-links.org][Links]]), not org-roam-ui's. Templates are tables in =capture.toml= rather than Lisp: targets other than =file=, =file+head=, =file+olp= and =file+head+olp= (such as =node=), function templates and =${…}= fields other than =title=, =slug=, =id= and a ref's =ref= and =body= aren't supported, and the capture window shows only the template's text, as if every template were narrowed. When an outline path's heading appears twice, the last is used where org-roam reports an error. A template of only =%?= doesn't leave the empty line Emacs leaves. The go-to daily-note commands ask for a template only when the templates name different files. Cancelling a capture makes nothing, so there's no question about deleting the new file. =roam:= links aren't rewritten to =id:= links when followed (=org-roam-link-auto-replace=), and one to a title no node has reports it rather than making the node. =roam-ref= with an existing node opens it rather than capturing into it. Refs aren't listed as backlinks (reflinks), and =org-roam-node-display-template= isn't read: the chooser shows title and tags. The daily date prompt prefers future dates, where org-roam prefers past ones.
296- Denote: a note's front matter is read from its first 40 lines. =denote-date-format=, =denote-front-matter-components-present-even-if-empty-value= and changes to =denote-file-types= aren't read; the defaults are used. Keywords are sorted after they are put in lower case, where Denote sorts them as typed, so =Zeta= and =alpha= sort differently when they aren't already lower case. Denote's quoting of Markdown values is followed exactly, including that a title with =\"= in it gains a backslash each time Rename Note from Front Matter rewrites it. See [[file:09-links.org][Links]].
296297- org-timer: =org-timer-display= is always the mode line. The timer's =C-u= forms are separate commands bound to =C-u C-c C-x 0=, =C-u C-u C-c C-x 0= and =C-u C-c C-x ,=; Set Countdown Timer… has no prefix-argument forms.
297298- Radio lists are Org 9.8's =#+ATTR_ORG: :radio= checkbox lists. The =#+ORGLST= radio lists of Org 9.1 and earlier, removed in Org 9.2, aren't supported, nor is =org-list-checkbox-radio-mode=.
298299- org-attach: =org-attach-method= is always =cp= for Attach File… (the other methods have their own commands), =org-attach-auto-tag= is always =ATTACH=, =org-attach-preferred-new-method= is always =id=, and =org-attach-id-to-path-function-list= is Org's default. The dispatcher's =b=, =O= and =F= keys and =org-attach-archive-delete= aren't supported. Delete All Attachments… asks once and deletes the folder with what's in it.
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form