pygments_data: Replace JS module with JSON module.

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-02-05 22:44:36 -08:00
committed by Tim Abbott
parent e257253e64
commit d7d8632525
11 changed files with 14 additions and 29 deletions

View File

@@ -118,7 +118,6 @@
"pointer": false,
"popovers": false,
"presence": false,
"pygments_data": false,
"reactions": false,
"realm_icon": false,
"realm_logo": false,

View File

@@ -320,7 +320,7 @@ implementation of that tool.
The list of languages supported by our markdown syntax highlighting
comes from the [pygments][] package. `tools/setup/build_pygments_data` is
responsible for generating `static/generated/pygments_data.js` so that
responsible for generating `static/generated/pygments_data.json` so that
our JavaScript markdown processor has access to the supported list.
### Authors data

View File

@@ -178,9 +178,7 @@ emoji.active_realm_emojis = new Map();
emoji.emojis_by_name = emojis_by_name;
emoji.emojis = emoji_list;
set_global('pygments_data', {langs:
{python: 0, javscript: 1, html: 2, css: 3},
});
const pygments_data = zrequire("pygments_data", "generated/pygments_data.json");
const alice = {
email: 'alice@zulip.com',

View File

@@ -14,7 +14,8 @@ zrequire('stream_data');
zrequire('narrow');
zrequire('hash_util');
zrequire('marked', 'third/marked/lib/marked');
const actual_pygments_data = zrequire('actual_pygments_data', 'generated/pygments_data');
const pygments_data = zrequire('pygments_data', 'generated/pygments_data.json');
const actual_pygments_data = Object.assign({}, pygments_data);
zrequire('settings_org');
const ct = zrequire('composebox_typeahead');
const th = zrequire('typeahead_helper');
@@ -96,7 +97,7 @@ run_test('sort_streams', () => {
});
run_test('sort_languages', () => {
set_global('pygments_data', {langs:
Object.assign(pygments_data, {langs:
{python: 40, javscript: 50, php: 38, pascal: 29, perl: 22, css: 0},
});
@@ -107,7 +108,7 @@ run_test('sort_languages', () => {
assert.deepEqual(test_langs, ["python", "php", "pascal", "perl", "javascript"]);
// Test if popularity between two languages are the same
global.pygments_data.langs.php = 40;
pygments_data.langs.php = 40;
test_langs = ["pascal", "perl", "php", "python", "javascript"];
test_langs = th.sort_languages(test_langs, "p");
@@ -118,7 +119,7 @@ run_test('sort_languages', () => {
// We may eventually want to use human-readable names like
// "JavaScript" with several machine-readable aliases for what the
// user typed, which might help provide a better user experience.
global.pygments_data = actual_pygments_data;
Object.assign(pygments_data, actual_pygments_data);
test_langs = ["j", "java", "javascript", "js"];
// Sort acccording to priority only.

2
static/.gitignore vendored
View File

@@ -8,7 +8,7 @@
# From emoji
/generated/emoji
# From passing pygments data to the frontend
/generated/pygments_data.js
/generated/pygments_data.json
# From `tools/update-authors-json`
/generated/github-contributors.json

View File

@@ -17,7 +17,6 @@ import "handlebars/dist/cjs/handlebars.runtime.js";
import "flatpickr/dist/flatpickr.js";
import "flatpickr/dist/plugins/confirmDate/confirmDate.js";
import "sortablejs/Sortable.js";
import "../../generated/pygments_data.js";
// Import App JS
import "../translations.js";

View File

@@ -1,3 +1,4 @@
const pygments_data = require("../generated/pygments_data.json");
const typeahead = require("../shared/js/typeahead");
const autosize = require('autosize');

View File

@@ -1,3 +1,4 @@
const pygments_data = require("../generated/pygments_data.json");
const typeahead = require("../shared/js/typeahead");
const render_typeahead_list_item = require('../templates/typeahead_list_item.hbs');
const IntDict = require('./int_dict').IntDict;

View File

@@ -6,7 +6,7 @@ import os
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
DATA_PATH = os.path.join(ZULIP_PATH, 'tools', 'setup', 'lang.json')
JS_PATH = os.path.join(ZULIP_PATH, 'static', 'generated', 'pygments_data.js')
OUT_PATH = os.path.join(ZULIP_PATH, 'static', 'generated', 'pygments_data.json')
with open(DATA_PATH) as f:
langs = json.load(f)
@@ -17,18 +17,5 @@ for lexer in lexers:
if name not in langs:
langs[name] = 0
template = '''var pygments_data = (function () {
var exports = {};
exports.langs = %s;
return exports;
}());
if (typeof module !== 'undefined') {
module.exports = pygments_data;
}''' % (json.dumps(langs),)
with open(JS_PATH, 'w') as f:
f.write(template)
with open(OUT_PATH, 'w') as f:
json.dump({"langs": langs}, f)

View File

@@ -221,7 +221,6 @@ export default (env?: string): webpack.Configuration[] => {
{ path: "clipboard/dist/clipboard.js", name: "ClipboardJS" },
{ path: "xdate/src/xdate.js", name: "XDate" },
{ path: "../static/third/marked/lib/marked.js" },
{ path: "../static/generated/pygments_data.js" },
{ path: "../static/js/debug.js" },
{ path: "../static/js/blueslip.js" },
{ path: "../static/js/common.js" },

View File

@@ -26,4 +26,4 @@ LATEST_RELEASE_ANNOUNCEMENT = "https://blog.zulip.org/2019/12/13/zulip-2-1-relea
# historical commits sharing the same major version, in which case a
# minor version bump suffices.
PROVISION_VERSION = '71.0'
PROVISION_VERSION = '72.0'