tl;dr
- GitHub
は Emacs や Vim の modelines に沿ったシンタックスハイライトをしてくれます - .gitattributes でも設定できるはずですが、いまのところ有効ではないようです
(2017-04-08 時点)
背景
「このファイルは実質 YAML なんだし、 GitHub 上でもそう表示してほしいなあ」なんてことありますよね。(たとえば salt-ssh の Saltfile ですとか)
王道は linguist の languages.yml へ Pull Request を出すことかと思いますが、ほかになにか手っ取り早い方法がないかと探したところ、 README にこんな記載がありました。
Using gitattributes
Add a
.gitattributesfile to your project and use standard git-style path matchers for the files you want to override to setlinguist-documentation,linguist-language, andlinguist-vendored..gitattributeswill be used to determine language statistics and will be used to syntax highlight files. You can also manually set syntax highlighting using Vim or Emacs modelines.
検証
実際に検証してみました。
素の状態
- シンタックスハイライトされません
- HTML のクラスは
type-textです
https://github.com/elim/test-gh-linguist-overriding/blob/1ae6834/Saltfile
.gitattributes
下記の内容を用意しました
Saltfile linguist-language=YAML
- シンタックスハイライトされません
- HTML のクラスが
type-yamlになります
https://github.com/elim/test-gh-linguist-overriding/blob/62cf59f/.gitattributes
https://github.com/elim/test-gh-linguist-overriding/blob/62cf59f/Saltfile
Emacs 形式の modeline
- シンタックスハイライトされます
- HTML のクラスが
type-yamlになります
https://github.com/elim/test-gh-linguist-overriding/blob/2be0582/Saltfile
Vim 形式の modeline
https://github.com/elim/test-gh-linguist-overriding/blob/76a9ada/Saltfile
以上です。
まだマイナーな環境や自作言語、自作 DSL に適用すると便利かもですね ![]()






