mirror of https://github.com/zulip/zulip.git
tools/build_pygments_data: Map pygments language aliases to lexer name.
We need this information in the frontend to: * Display the 'view in playground' option for locally echoed messages. * When we add a UI settings for realm admins to configure their playground choices, we'll need to use these canonicalized aliases for displaying the option. Hence, this tweaks the tool which generates pygments_data.json to contain the data we need. Bumping major PROVISION_VERSION since folks need to provision in both directions. Tests amended.
This commit is contained in:
parent
564b199fe6
commit
4a2791e2a3
|
@ -99,7 +99,14 @@ run_test("sort_streams", () => {
|
|||
|
||||
run_test("sort_languages", () => {
|
||||
Object.assign(pygments_data, {
|
||||
langs: {python: 40, javscript: 50, php: 38, pascal: 29, perl: 22, css: 0},
|
||||
langs: {
|
||||
python: {priority: 40},
|
||||
javscript: {priority: 50},
|
||||
php: {priority: 38},
|
||||
pascal: {priority: 29},
|
||||
perl: {priority: 22},
|
||||
css: {priority: 0},
|
||||
},
|
||||
});
|
||||
|
||||
let test_langs = ["pascal", "perl", "php", "python", "javascript"];
|
||||
|
@ -109,7 +116,7 @@ run_test("sort_languages", () => {
|
|||
assert.deepEqual(test_langs, ["python", "php", "pascal", "perl", "javascript"]);
|
||||
|
||||
// Test if popularity between two languages are the same
|
||||
pygments_data.langs.php = 40;
|
||||
pygments_data.langs.php = {priority: 40};
|
||||
test_langs = ["pascal", "perl", "php", "python", "javascript"];
|
||||
test_langs = th.sort_languages(test_langs, "p");
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ exports.sort_people_for_relevance = function (objs, current_stream_name, current
|
|||
};
|
||||
|
||||
exports.compare_by_popularity = function (lang_a, lang_b) {
|
||||
const diff = pygments_data.langs[lang_b] - pygments_data.langs[lang_a];
|
||||
const diff = pygments_data.langs[lang_b].priority - pygments_data.langs[lang_a].priority;
|
||||
if (diff !== 0) {
|
||||
return diff;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
from pygments.lexers import get_all_lexers
|
||||
from pygments.lexers import get_all_lexers, get_lexer_by_name
|
||||
|
||||
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
|
||||
DATA_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'lang.json')
|
||||
|
@ -14,8 +14,10 @@ with open(DATA_PATH) as f:
|
|||
lexers = get_all_lexers()
|
||||
for lexer in lexers:
|
||||
for name in lexer[1]:
|
||||
if name not in langs:
|
||||
langs[name] = 0
|
||||
langs[name] = {
|
||||
'priority': langs.get(name, 0),
|
||||
'pretty_name': get_lexer_by_name(name).name
|
||||
}
|
||||
|
||||
with open(OUT_PATH, 'w') as f:
|
||||
json.dump({"langs": langs}, f)
|
||||
|
|
|
@ -44,4 +44,4 @@ API_FEATURE_LEVEL = 32
|
|||
# historical commits sharing the same major version, in which case a
|
||||
# minor version bump suffices.
|
||||
|
||||
PROVISION_VERSION = '106.1'
|
||||
PROVISION_VERSION = '107.1'
|
||||
|
|
Loading…
Reference in New Issue