-
-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Linguist lexers #153
Use Linguist lexers #153
Conversation
@pchaigno thanks for the pull! @mislav had opened a PR (#28 (comment)) in the past that tried to use linguist instead of pygments for detecting languages, but linguist does not recognize all the languages that pygments does. I'm not sure if that's still the case, but it would be good to have a test around this to prevent regressions. |
Zut! Completely forgot to search in the closed PRs first... Pygments still recognize some languages that Linguist doesn't. |
👍 as long as it falls back to pygments |
@jch I just added a commit to fall back to Pygments. Is that better? |
lexer = Pygments::Lexer[lang] | ||
end | ||
lexer | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
def get_lexer(lang)
(Linguist::Language[lang] && Linguist::Language[lang].lexer) || Pygments::Lexer[lang]
end
😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a more rubyish name?
def lexer_for(lang)
(Linguist::Language[lang] && Linguist::Language[lang].lexer) || Pygments::Lexer[lang]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I was going to suggest something similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback.
I changed that in my last commit.
👍 |
This pull request uses Linguist instead of Pygments to determine which the correct lexer.
This would be more accurate since Linguist sometimes defines languages that Pygments doesn't know (and uses the lexer of another language, see M).
If this pull request is merged and the Linguist gem updated, it would solve the issue at github-linguist/linguist#1468.
/cc @bkeepers