pygments_data: Move data to typescript.

This commit is contained in:
evykassirer 2024-01-13 12:01:07 -08:00 committed by Tim Abbott
parent bd6471f0e3
commit d7b02a699c
9 changed files with 24 additions and 15 deletions

6
web/src/pygments_data.ts Normal file
View File

@ -0,0 +1,6 @@
import generated_pygments_data from "../generated/pygments_data.json";
type PygmentsLanguage = {priority: number; pretty_name: string};
const langs: Record<string, PygmentsLanguage | undefined> = generated_pygments_data.langs;
export {langs};

View File

@ -1,7 +1,9 @@
import generated_pygments_data from "../generated/pygments_data.json";
import assert from "minimalistic-assert";
import * as typeahead from "../shared/src/typeahead";
import {$t} from "./i18n";
import * as pygments_data from "./pygments_data";
type RealmPlayground = {
id: number;
@ -42,10 +44,12 @@ export function get_playground_info_for_languages(
function sort_pygments_pretty_names_by_priority(
comparator_func: (a: string, b: string) => number,
): void {
const priority_sorted_pygments_data = Object.entries(generated_pygments_data.langs).sort(
([a], [b]) => comparator_func(a, b),
const priority_sorted_pygments_data = Object.entries(pygments_data.langs).sort(([a], [b]) =>
comparator_func(a, b),
);
for (const [alias, {pretty_name}] of priority_sorted_pygments_data) {
for (const [alias, data] of priority_sorted_pygments_data) {
assert(data !== undefined);
const pretty_name = data.pretty_name;
// JS Map remembers the original order of insertion of keys.
if (map_pygments_pretty_name_to_aliases.has(pretty_name)) {
map_pygments_pretty_name_to_aliases.get(pretty_name)!.push(alias);
@ -64,9 +68,9 @@ function sort_pygments_pretty_names_by_priority(
// deduplicate them.
export function get_pygments_typeahead_list_for_composebox(): string[] {
const playground_pygment_langs = [...map_language_to_playground_info.keys()];
const generated_pygment_langs = Object.keys(generated_pygments_data.langs);
const pygment_langs = Object.keys(pygments_data.langs);
return [...playground_pygment_langs, ...generated_pygment_langs];
return [...playground_pygment_langs, ...pygment_langs];
}
// This gets the candidate list for showing autocomplete in settings when

View File

@ -1,6 +1,5 @@
import $ from "jquery";
import pygments_data from "../generated/pygments_data.json";
import render_settings_deactivate_realm_modal from "../templates/confirm_dialog/confirm_deactivate_realm.hbs";
import render_settings_admin_auth_methods_list from "../templates/settings/admin_auth_methods_list.hbs";
@ -14,6 +13,7 @@ import {$t, $t_html, get_language_name} from "./i18n";
import * as keydown_util from "./keydown_util";
import * as loading from "./loading";
import {page_params} from "./page_params";
import * as pygments_data from "./pygments_data";
import * as realm_icon from "./realm_icon";
import * as realm_logo from "./realm_logo";
import {realm_user_settings_defaults} from "./realm_user_settings_defaults";

View File

@ -1,7 +1,6 @@
import Handlebars from "handlebars/runtime";
import _ from "lodash";
import pygments_data from "../generated/pygments_data.json";
import * as typeahead from "../shared/src/typeahead";
import render_typeahead_list_item from "../templates/typeahead_list_item.hbs";
@ -10,6 +9,7 @@ import * as compose_state from "./compose_state";
import {page_params} from "./page_params";
import * as people from "./people";
import * as pm_conversations from "./pm_conversations";
import * as pygments_data from "./pygments_data";
import * as recent_senders from "./recent_senders";
import * as stream_data from "./stream_data";
import * as stream_list_sort from "./stream_list_sort";

View File

@ -2,7 +2,6 @@ import $ from "jquery";
import _ from "lodash";
import generated_emoji_codes from "../../static/generated/emoji/emoji_codes.json";
import generated_pygments_data from "../generated/pygments_data.json";
import * as fenced_code from "../shared/src/fenced_code";
import render_compose from "../templates/compose.hbs";
import render_message_feed_bottom_whitespace from "../templates/message_feed_bottom_whitespace.hbs";
@ -87,6 +86,7 @@ import * as pm_list from "./pm_list";
import * as popover_menus from "./popover_menus";
import * as popovers from "./popovers";
import * as presence from "./presence";
import * as pygments_data from "./pygments_data";
import * as realm_logo from "./realm_logo";
import * as realm_playground from "./realm_playground";
import * as realm_user_settings_defaults from "./realm_user_settings_defaults";
@ -699,7 +699,7 @@ export function initialize_everything() {
typing.initialize();
starred_messages_ui.initialize();
user_status_ui.initialize();
fenced_code.initialize(generated_pygments_data);
fenced_code.initialize(pygments_data);
message_edit_history.initialize();
hotkey.initialize();
desktop_integration.initialize();

View File

@ -51,7 +51,7 @@ const compose_pm_pill = zrequire("compose_pm_pill");
const compose_recipient = zrequire("compose_recipient");
const composebox_typeahead = zrequire("composebox_typeahead");
const settings_config = zrequire("settings_config");
const pygments_data = zrequire("../generated/pygments_data.json");
const pygments_data = zrequire("pygments_data");
const ct = composebox_typeahead;

View File

@ -49,11 +49,11 @@ mock_esm("../src/settings_data", {
const emoji = zrequire("emoji");
const emoji_codes = zrequire("../../static/generated/emoji/emoji_codes.json");
const linkifiers = zrequire("linkifiers");
const pygments_data = zrequire("../generated/pygments_data.json");
const fenced_code = zrequire("../shared/src/fenced_code");
const markdown_config = zrequire("markdown_config");
const markdown = zrequire("markdown");
const people = zrequire("people");
const pygments_data = zrequire("pygments_data");
const stream_data = zrequire("stream_data");
const user_groups = zrequire("user_groups");

View File

@ -5,9 +5,8 @@ const {strict: assert} = require("assert");
const {zrequire} = require("./lib/namespace");
const {run_test} = require("./lib/test");
const pygments_data = zrequire("../generated/pygments_data.json");
const {$t} = zrequire("i18n");
const pygments_data = zrequire("pygments_data");
const realm_playground = zrequire("realm_playground");
const typeahead_helper = zrequire("typeahead_helper");

View File

@ -18,7 +18,7 @@ const stream_data = zrequire("stream_data");
const stream_list_sort = zrequire("stream_list_sort");
const compose_state = zrequire("compose_state");
const emoji = zrequire("emoji");
const pygments_data = zrequire("../generated/pygments_data.json");
const pygments_data = zrequire("pygments_data");
const util = zrequire("util");
const actual_pygments_data = {...pygments_data};
const ct = zrequire("composebox_typeahead");