diff --git a/src/lexer.cr b/src/lexer.cr index e47cdeb..0fd92ae 100644 --- a/src/lexer.cr +++ b/src/lexer.cr @@ -350,6 +350,14 @@ module Tartrazine class CustomCrystalHighlighter < Crystal::SyntaxHighlighter @tokens = [] of Token + def highlight(text) + super + rescue ex : Crystal::SyntaxException + # Fallback to Ruby highlighting + Log.warn { "Highlighting as Ruby, Crystal syntax highlighting failed: #{ex.message}" } + @tokens = Tartrazine.lexer("ruby").tokenizer(text).to_a + end + def render_delimiter(&block) @tokens << {type: "LiteralString", value: block.call.to_s} end