templ icon indicating copy to clipboard operation
templ copied to clipboard

misc: Write a lexer for Pygments

Open joerdav opened this issue 1 year ago • 5 comments

This isn't really a code change to this repo, but thought it would be worth tracking here.

What

Write a lexer for the Pygmens syntax highlighting tool.

There's a guide here on how: https://pygments.org/docs/lexerdevelopment/

And it may be useful to reference both the Go and HTML lexers:

https://github.com/pygments/pygments/blob/master/pygments/lexers/go.py

https://github.com/pygments/pygments/blob/master/pygments/lexers/html.py

Why

Pygmens is the syntax highligher that Github uses, so completing this would make for some colourful code in the github web app.

joerdav avatar Oct 30 '23 11:10 joerdav

This would also enable templ support in https://github.com/alecthomas/chroma, which would be nice for server side syntax highlighting in Go.

cugu avatar Nov 02 '23 08:11 cugu

Side chat - the number of syntax highlighting formats to support is currently at 4 - Treesitter (Neovim), Pygments (Github), TextMate (VS Code), and the JetBrains one (can't remember what that is).

I was wondering if there was a meta tool that can write syntax highlighting for all the targets. Ideally, some sort of programming language based thing that is testable.

Having that might make the problem worse due to the abstraction, I was just wondering!

Looking at https://github.com/github-linguist/linguist/pull/6435/files it looks like Github uses Textmate, as per VS Code?

a-h avatar Nov 06 '23 10:11 a-h

Agreed... it's becoming a bit of a risk for changing the language design, having to go and update all the parsers!

Textmate rings a bell, I believe that may also work with jetbrains for https://github.com/templ-go/templ-jetbrains

joerdav avatar Nov 06 '23 10:11 joerdav

There is also the prism.js syntax highlighter for the docs.

cugu avatar Nov 06 '23 10:11 cugu

Ah yes, thanks! I think it could be possible to swap out the docs to use https://shiki.matsu.io which also uses TextMate.

There's a Docusaurus plugin, but I took a look at your templ documentation site, and it's started to look amazing, so maybe we won't need it. ;)

a-h avatar Nov 06 '23 10:11 a-h

Github uses Linguist, so I will close this as we have a PR in for linguist.

joerdav avatar May 31 '24 09:05 joerdav