mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
We now organize the pygment language codes into meaningful categories - default, custom and aliases. Further the `lang.json` list now contains a dataset extracted from the "language" section of https://insights.stackoverflow.com/survey/2020 and is prioritized based on current language trends.
37 lines
1.0 KiB
Python
Executable File
37 lines
1.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
import os
|
|
|
|
from pygments.lexers import get_all_lexers
|
|
|
|
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../")
|
|
# The current priorities data set is based on StackOverflow's 2020 survey.
|
|
DATA_PATH = os.path.join(ZULIP_PATH, "tools", "setup", "lang.json")
|
|
OUT_PATH = os.path.join(ZULIP_PATH, "static", "generated", "pygments_data.json")
|
|
|
|
with open(DATA_PATH) as f:
|
|
pygments_data = json.load(f)
|
|
priorities = dict(
|
|
**pygments_data["default"], **pygments_data["custom"], **pygments_data["aliases"]
|
|
)
|
|
|
|
lexers = get_all_lexers()
|
|
langs = {
|
|
alias: {
|
|
"priority": priorities.get(alias, 0),
|
|
"pretty_name": longname,
|
|
}
|
|
for longname, aliases, filename_patterns, mimetypes in lexers
|
|
for alias in aliases
|
|
}
|
|
|
|
for name in priorities:
|
|
if langs.get(name) is None:
|
|
langs[name] = {
|
|
"priority": priorities[name],
|
|
"pretty_name": name,
|
|
}
|
|
|
|
with open(OUT_PATH, "w") as f:
|
|
json.dump({"langs": langs}, f)
|