github-linguist / linguist

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!
MIT License
12.36k stars 4.27k forks source link

Bibtex syntax highlighting #3679

Closed blegat closed 6 years ago

blegat commented 7 years ago

If I am not mistaken, currently .bib files are reported as latex and are not highlighted. I understand that reporting it as LaTeX allows to correctly highlight any LaTeX present in the fields as in the example below with $math$. However, it would be nice to have a separate language that also adds color highlighting to @book, ...

@book{knuth1998art,
  title={The art of computer programming: sorting and searching $math$},
  author={Knuth, Donald Ervin},
  volume={3},
  year={1998},
  publisher={Pearson Education}
}
pchaigno commented 6 years ago

We'd welcome a pull request to make Bibtex a separate language with its own syntax highlighting.

ruffsl commented 5 years ago

As of now, there are a few projects I see syntax highlighting for bibtex:

I don't know much javascript, but how would one move this upstream?

pchaigno commented 5 years ago

Unfortunately, we only support TextMate, Sublime Text, and Atom grammars.

ruffsl commented 5 years ago

From reading contributing.md and linguist/vendor/README.md, it looks like textmate/latex.tmbundle is the current official TextMate support for LaTeX and BibTex. Looking at that repo, it also seems to have plenty of code/tests on BibTex syntax; commits dating back from 2015. Is there a particular reason syntax highlighting is not being rendered with linguist now?

https://github.com/textmate/latex.tmbundle/blob/404e0049b67d54c2733b5a16eb600740c4ec2e19/Syntaxes/Bibtex.plist#L5-L16

e.g.:

@incollection{dijkstra1982role,
  title={On the role of scientific thought},
  author={Dijkstra, Edsger W},
  booktitle={Selected writings on computing: a personal perspective},
  pages={60--66},
  year={1982},
  publisher={Springer}}
~~~markdown ``` latex @incollection{dijkstra1982role, title={On the role of scientific thought}, author={Dijkstra, Edsger W}, booktitle={Selected writings on computing: a personal perspective}, pages={60--66}, year={1982}, publisher={Springer} } ``` ~~~
Alhadis commented 5 years ago

Is there a particular reason syntax highlighting is not being rendered with linguist now?

Yup, it's because we need a separate language entry for BibTeX. The file you linked to (Bibtex.plist) isn't the one being used for *.bib files, because *.bib is listed as a TeX extension, and TeX highlighting is handled using a different grammar.

If we use the Bibtex.plist file specifically, the output is verrry different:

figure-1

Alhadis commented 5 years ago

I've submitted a pull-request that will fix this. See #4584.