fix: scale note headings by level

This commit is contained in:
2026-10-19 20:18:14 +02:00
parent 090c9045a4
commit 6f37910797
3 changed files with 38 additions and 2 deletions
@@ -26,3 +26,28 @@ import Testing
#expect(unfinished.attribute(.foregroundColor, at: 10, effectiveRange: nil) as? NSColor == keyword)
}
}
@Test @MainActor func noteHeadingsShrinkByLevelWithoutChangingMarkdownOrCode() throws {
_ = NSApplication.shared
let editor = NSTextView()
let text = "# One\n## Two\n### Three\n#### Four\n##### Five\n###### Six\nBody\n## **Bold** and *italic*\n```text\n# Literal\n```\n####### Not a heading"
editor.string = text
MarkdownHighlighting.apply(to: editor)
let storage = try #require(editor.textStorage)
func font(_ token: String) throws -> NSFont {
try #require(storage.attribute(.font, at: (editor.string as NSString).range(of: token).location,
effectiveRange: nil) as? NSFont)
}
let sizes = try ["One", "Two", "Three", "Four", "Five", "Six"].map { try font($0).pointSize }
for (larger, smaller) in zip(sizes, sizes.dropFirst()) { #expect(larger > smaller) }
#expect(try font("Six").pointSize >= font("Body").pointSize)
#expect(try font("**Bold**").pointSize == font("Two").pointSize)
#expect(try font("*italic*").pointSize == font("Two").pointSize)
#expect(try font("Literal").pointSize == font("Body").pointSize)
#expect(try font("Not a heading").pointSize == font("Body").pointSize)
#expect(try font("Three").isFixedPitch)
#expect(editor.string == text)
storage.replaceCharacters(in: (editor.string as NSString).range(of: "### Three"), with: "Three")
MarkdownHighlighting.apply(to: editor)
#expect(try font("Three").pointSize == font("Body").pointSize)
}