spike(textkit2): proper reading mode — per-block render hides markup (#53 follow-up)
CI / ci (push) Canceled after 0s

Blank-line split + inline markdown parse per paragraph; headings fonted by
level (bold serif). Single-Text .full parse flattened blocks and left
presentation intents unstyled; earlier 'breaks window creation' claim was an
AX misread — retracted. --check now asserts markup stays hidden.
This commit is contained in:
AlexKucera committed 2026-09-30 13:40:12 +02:00
1 parent dd3542a720
commit d836083aec
2 files changed
+29 -8

No files matched your search

@@ -32,6 +32,10 @@ struct SpikeApp: App {
assert(ProsePresenter.anchorRange(of: squished, in: text) != nil, "FAIL: whitespace-tolerant match")
// stale anchor: deleted text
assert(ProsePresenter.anchorRange(of: "this quote was deleted years ago", in: text) == nil, "FAIL: stale should be nil")
// reading blocks: heading detected, markup hidden
let blocks = SpikeApp.readingBlocks(text)
assert(String(blocks[0].text.characters).hasPrefix("The expected value"), "FAIL: H1 block")
assert(blocks.allSatisfy { !String($0.text.characters).contains("#") }, "FAIL: markup leaked into reading view")
// perf smoke: PERF-3k anchor timing
let perf = (try? String(contentsOfFile: "spike/prose/PERF-3k.md", encoding: .utf8)) ?? text
let t0 = DispatchTime.now()
@@ -39,6 +43,20 @@ struct SpikeApp: App {
let ms = Double(DispatchTime.now().uptimeNanoseconds - t0.uptimeNanoseconds) / 1e6
print("PASS: anchor found @ \(r.location), len \(r.length); PERF-3k anchor search \(String(format: "%.1f", ms)) ms")
}
// ponytail: blank-line split + inline parse per block; no AST. Setext/list blocks not handled — corpus has none.
static func readingBlocks(_ md: String) -> [(level: Int, text: AttributedString)] {
md.components(separatedBy: "\n\n").map { para in
var level = 0, p = para.trimmingCharacters(in: .whitespacesAndNewlines)
if p.hasPrefix("#") {
let hashes = p.prefix { $0 == "#" }.count
p = String(p.dropFirst(hashes)).trimmingCharacters(in: .whitespaces)
level = hashes
}
let attr = (try? AttributedString(markdown: p)) ?? AttributedString(p)
return (level, attr)
}
}
}
struct ContentView: View {
@@ -66,14 +84,17 @@ struct ContentView: View {
Divider()
if reading {
ScrollView([.vertical]) {
Text((try? AttributedString(
markdown: text,
options: .init(interpretedSyntax: .inlineOnlyPreservingWhitespace)
)) ?? AttributedString(text))
.font(.system(size: 17))
.padding(.horizontal, 40)
.frame(maxWidth: 720, alignment: .leading)
.padding(.vertical, 24)
VStack(alignment: .leading, spacing: 14) {
ForEach(Array(SpikeApp.readingBlocks(text).enumerated()), id: \.offset) { _, block in
Text(block.text)
.font(block.level > 0
? .system(size: CGFloat(32 - block.level * 3), weight: .bold, design: .serif)
: .system(size: 17))
}
}
.frame(maxWidth: 720, alignment: .leading)
.padding(.horizontal, 40)
.padding(.vertical, 24)
}
} else {
EditorPane(attributed: doc, onEdit: { newText in
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB