Skip to content

Commit

Permalink
Fix outline title sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Dec 14, 2024
1 parent 6555c86 commit 6fb6a83
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Packages/EditorCore/Sources/Syntax/OutlineExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public struct OutlineExtractor: Sendable {
let title = (self.template.isEmpty
? (string as NSString).substring(with: result.range)
: self.regex.replacementString(for: result, in: string, offset: 0, template: self.template))
.replacing(/(?!^)\s+/, with: " ")
.replacing(/(\S)\s+/) { "\($0.1) " }

guard !title.isEmpty else { return nil }

Expand Down
2 changes: 1 addition & 1 deletion Tests/Resources/sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>

<body>
<h2>πŸ•πŸ„</h2>
<h2>πŸ• πŸ„</h2>
<p>Dogcow is awesome animal!</p>

<h2>Lorem Ipsum</h2>
Expand Down
4 changes: 2 additions & 2 deletions Tests/Sources/Models/SyntaxTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ actor SyntaxTests {
#expect(outlineItems.count == 3)

let item = outlineItems[1]
#expect(item.title == " h2: πŸ•πŸ„")
#expect(item.title == " h2: πŸ• πŸ„")
#expect(item.range.location == 354)
#expect(item.range.length == 13)
#expect(item.range.length == 15)
#expect(item.style.isEmpty)
}

Expand Down

0 comments on commit 6fb6a83

Please sign in to comment.