Crystal highlight heredoc issue
Closed this issue · 5 comments
mamantoha commented
Sample code with heredoc:
lexer = Tartrazine.lexer(name: "crystal")
theme = Tartrazine.theme("github-dark")
source = %Q[
xml = <<-XML
<person id="1">
<firstName preferredName="Jane">Jehanne</firstname>
<lastName>Doe</lastname>
</person>
XML
]
formatter = Tartrazine::Html.new(theme)
formatter.standalone = true
puts formatter.format(source, lexer)
GitHub format it correctly as is:
xml = <<-XML
<person id="1">
<firstName preferredName="Jane">Jehanne</firstname>
<lastName>Doe</lastname>
</person>
XML
crystal test.cr > index.html
Result from Tatranize:
ralsina commented
A quick look seems to indicate the crystal lexer from chroma has no support
for heredocs. I will try to add it.
…On Mon, Sep 9, 2024 at 7:36 AM Anton Maminov ***@***.***> wrote:
Sample code with heredoc:
lexer = Tartrazine.lexer(name: "crystal")
theme = Tartrazine.theme("github-dark")
source = %Q[xml = <<-XML <person id="1"> <firstName preferredName="Jane">Jehanne</firstname> <lastName>Doe</lastname> </person>XML]
formatter = Tartrazine::Html.new(theme)
formatter.standalone = true
puts formatter.format(source, lexer)
GitHub format it correctly as is:
xml = <<-XML <person id="1"> <firstName preferredName="Jane">Jehanne</firstname> <lastName>Doe</lastname> </person>XML
crystal test.cr > index.html
Result from Tatranize:
image.png (view on web)
<https://github.com/user-attachments/assets/45a1bad8-8a0e-44a5-90c0-d9a92d4959bc>
—
Reply to this email directly, view it on GitHub
<#2>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAAMKZCPYSLUO2SP37D733ZVV22VAVCNFSM6AAAAABN4HVICGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGUYTGNJYGE2DQMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
ralsina commented
Hmmm actually it does. Will do some testing.
<rule pattern="(?<!\w)(<<-?)(["`\'
]?)([a-zA-Z_]\w*)(\2)(.*?\n)">
<token type="LiteralStringHeredoc"/>
</rule>
<rule pattern="(<<-?)("|\')()(\2)(.*?\n)">
<token type="LiteralStringHeredoc"/>
</rule>
On Mon, Sep 9, 2024 at 10:18 AM Roberto Alsina ***@***.***>
wrote:
… A quick look seems to indicate the crystal lexer from chroma has no
support for heredocs. I will try to add it.
On Mon, Sep 9, 2024 at 7:36 AM Anton Maminov ***@***.***>
wrote:
> Sample code with heredoc:
>
> lexer = Tartrazine.lexer(name: "crystal")
> theme = Tartrazine.theme("github-dark")
>
> source = %Q[xml = <<-XML <person id="1"> <firstName preferredName="Jane">Jehanne</firstname> <lastName>Doe</lastname> </person>XML]
>
> formatter = Tartrazine::Html.new(theme)
> formatter.standalone = true
> puts formatter.format(source, lexer)
>
> GitHub format it correctly as is:
>
> xml = <<-XML <person id="1"> <firstName preferredName="Jane">Jehanne</firstname> <lastName>Doe</lastname> </person>XML
>
> crystal test.cr > index.html
>
> Result from Tatranize:
>
> image.png (view on web)
> <https://github.com/user-attachments/assets/45a1bad8-8a0e-44a5-90c0-d9a92d4959bc>
>
> —
> Reply to this email directly, view it on GitHub
> <#2>, or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAAAMKZCPYSLUO2SP37D733ZVV22VAVCNFSM6AAAAABN4HVICGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGUYTGNJYGE2DQMQ>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>
ralsina commented
Seems something got lost in the pygments -> chroma translation
![image](https://github.com/user-attachments/assets/8ca81f5a-7c62-4e50-bb6e-b4800d7f807c)
In pygments, heredocs have a callback, so the support in chroma seems to not be great and tartrazine inherited that.
I had a vague plan to special-case crystal to use the compiler's built-in highlighter, I guess it's needed :-)
ralsina commented
I just pushed a PR to try using the native crystal highlighter. It's not a great match for the model tartrazine uses but it seems to work :-)