From ed61a84553a7e51d2b2e2adf2ec5f8471bd40dcf Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Thu, 20 Feb 2025 13:24:53 -0300 Subject: [PATCH] fix: when the internal crystal highlighter fails, fallback to ruby. Fixes #13 --- src/lexer.cr | 8 ++++++++ 1 file changed, 8 insertions(+) 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