pygments / pygments.rb

💎 Ruby wrapper for Pygments syntax highlighter
MIT License
572 stars 141 forks source link

`guess()` from Ruby #260

Closed verhovsky closed 6 months ago

verhovsky commented 6 months ago

I wanted to print what Pygments guesses a language would be, but these bindings don't include that function.

ChatGPT hallucinated this

      guessed_lexer = Pygments.lexers.guess(code: code)

and I think that makes sense.

slonopotamus commented 6 months ago

You can use Pygments.lexer_names_for for this. See examples: https://github.com/pygments/pygments.rb/blob/v2.4.1/test/test_pygments.rb#L132-L138