Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ final class HighlightrThemeAdapter {
/// Creates an adapter when Highlightr can initialize its JavaScript engine.
init?() {
guard let highlightr = Highlightr() else { return nil }
// File Preview handles source files that embed another language (for
// example dbt SQL with Jinja delimiters). Keep valid tokens around
// grammar-illegal characters instead of aborting the whole document.
highlightr.ignoreIllegals = true
self.highlightr = highlightr
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import Foundation
import Testing

#if canImport(AppKit)
import AppKit
#endif

@Suite("Highlightr syntax engine")
struct HighlightrSyntaxEngineTests {
@Test("Policy rejection returns nil without coloring")
Expand All @@ -15,4 +19,30 @@ struct HighlightrSyntaxEngineTests {
#expect(highlighted == nil)
}

#if canImport(AppKit)
@Test("SQL containing Jinja delimiters still highlights SQL tokens")
func sqlContainingJinjaDelimitersStillHighlightsTokens() async throws {
let engine = HighlightrSyntaxEngine()
let source = """
select id, name
from {{ ref('users') }}
where active = true
"""

let highlighted = try #require(
await engine.highlight(text: source, language: "sql", theme: .dark)
)
let selectRange = (highlighted.value.string as NSString).range(of: "select")
#expect(selectRange.location != NSNotFound)
let color = highlighted.value.attribute(
.foregroundColor,
at: selectRange.location,
effectiveRange: nil
)
#expect(
HighlightColorRemapper(theme: .dark).hexKey(from: color as Any) == "0091FF"
)
}
#endif

}
Loading