我如何使用语言 YAML 文件来确定哪些关键字适用于任何给定语言?

How can I use the languages YAML file to determine which keywords work for any given language?

有一篇page on GitHub Help描述了如何使用语法高亮代码块。在该页面上有描述如何为此目的将语言与其关键字匹配的说明:

We use Linguist to perform language detection and syntax highlighting. You can find out which keywords are valid in the languages YAML file.

但是,该 YAML 中有很多数据,我发现它不是很清楚如何使用它来确定哪些关键字适用于任何给定语言。

我写了一个简单的 Boot script to attempt to parse this YAML to a more readable JSON 文件,将每种语言映射到其有效关键字列表:

curl https://raw.githubusercontent.com/github/linguist/f75c5707a62a3d66501993116826f4e64c3ca4dd/lib/linguist/languages.yml | ./languages.boot > languages.json

但我完全不相信这是正确的。例如,我的脚本生成的许多关键字都包含空格,我的印象是 those would not work:

The content of a code fence is treated as literal text, not parsed as inlines. The first word of the info string is typically used to specify the language of the code sample, and rendered in the class attribute of the code tag.

我正在寻找的是对该 YAML 文件的“模式”的理解,因为它与 GitHub Markdown 中的语法高亮相关。理想情况下,我希望能够使用这种理解来编写一个程序,该程序接受一种语言的 YAML 文件并生成类似 list of language codes for Stack Exchange syntax highlighting 的内容,但对于 GitHub 上的 Markdown。 如何编写这样的程序?

What I'm looking for is an understanding of the "schema" of this YAML file.

对于 languages.yml file 中的每种语言,您可以使用 说明符:

  1. 语言名称;
  2. 任何语言 aliases;
  3. 任何语言 interpreters;
  4. 任何文件扩展名,带或不带前导 .

空格必须替换为破折号(例如,emacs-lispEmacs Lisp 的一个说明符)。具有 tm_scope: none 条目的语言没有定义语法,不会在 github.com 上突出显示。

How can I write such a program?

实际上,已经有人编写了这样的程序。在 github/linguist#2278, jmm details the results of his investigation and received confirmation from one of GitHub's engineers (same thread). He also gives the link to his own program to compute identifiers and a wiki page with the results 中(可能不是最新的)。