mirror of https://github.com/zulip/zulip.git
js: Convert static/js/markdown.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
ea01e6da5e
commit
10a4d2bcbd
|
@ -167,7 +167,6 @@
|
|||
"localStorage": false,
|
||||
"local_message": false,
|
||||
"location": false,
|
||||
"markdown": false,
|
||||
"message_edit": false,
|
||||
"message_events": false,
|
||||
"message_fetch": false,
|
||||
|
|
|
@ -63,7 +63,8 @@ const transmit = set_global("transmit", {});
|
|||
const channel = {__esModule: true};
|
||||
rewiremock("../../static/js/channel").with(channel);
|
||||
const stream_edit = set_global("stream_edit", {});
|
||||
const markdown = set_global("markdown", {});
|
||||
const markdown = {__esModule: true};
|
||||
rewiremock("../../static/js/markdown").with(markdown);
|
||||
const loading = {__esModule: true};
|
||||
rewiremock("../../static/js/loading").with(loading);
|
||||
const page_params = set_global("page_params", {});
|
||||
|
|
|
@ -30,7 +30,8 @@ set_global("current_msg_list", {});
|
|||
const emoji_picker = set_global("emoji_picker", {});
|
||||
set_global("home_msg_list", {});
|
||||
const hotspots = set_global("hotspots", {});
|
||||
const markdown = set_global("markdown", {});
|
||||
const markdown = {__esModule: true};
|
||||
rewiremock("../../static/js/markdown").with(markdown);
|
||||
const message_edit = set_global("message_edit", {});
|
||||
const message_events = set_global("message_events", {});
|
||||
const message_list = set_global("message_list", {});
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
const {strict: assert} = require("assert");
|
||||
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {stub_templates} = require("../zjsunit/handlebars");
|
||||
const {set_global, zrequire, with_overrides} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
@ -31,13 +33,15 @@ set_global("stream_data", {
|
|||
return "#FFFFFF";
|
||||
},
|
||||
});
|
||||
set_global("markdown", {
|
||||
rewiremock("../../static/js/markdown").with({
|
||||
apply_markdown: noop,
|
||||
});
|
||||
set_global("page_params", {
|
||||
twenty_four_hour_time: false,
|
||||
});
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
const {localstorage} = zrequire("localstorage");
|
||||
const drafts = zrequire("drafts");
|
||||
const timerender = zrequire("timerender");
|
||||
|
@ -301,3 +305,4 @@ run_test("format_drafts", (override) => {
|
|||
drafts.launch();
|
||||
timerender.render_now = stub_render_now;
|
||||
});
|
||||
rewiremock.disable();
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
const {strict: assert} = require("assert");
|
||||
|
||||
const MockDate = require("mockdate");
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
const local_message = set_global("local_message", {});
|
||||
const markdown = set_global("markdown", {});
|
||||
const markdown = {__esModule: true};
|
||||
rewiremock("../../static/js/markdown").with(markdown);
|
||||
const page_params = set_global("page_params", {});
|
||||
|
||||
const fake_now = 555;
|
||||
|
@ -44,6 +46,8 @@ set_global("message_list", {});
|
|||
|
||||
set_global("current_msg_list", "");
|
||||
|
||||
rewiremock.enable();
|
||||
|
||||
const echo = zrequire("echo");
|
||||
const people = zrequire("people");
|
||||
|
||||
|
@ -259,3 +263,4 @@ run_test("insert_local_message PM", (override) => {
|
|||
});
|
||||
|
||||
MockDate.reset();
|
||||
rewiremock.disable();
|
||||
|
|
|
@ -120,7 +120,6 @@ zrequire("presence");
|
|||
zrequire("search_pill_widget");
|
||||
zrequire("unread");
|
||||
zrequire("bot_data");
|
||||
zrequire("markdown");
|
||||
const upload = zrequire("upload");
|
||||
const compose = zrequire("compose");
|
||||
zrequire("composebox_typeahead");
|
||||
|
|
|
@ -24,7 +24,6 @@ import "../widgetize";
|
|||
import "../message_list";
|
||||
import "../narrow";
|
||||
import "../reload";
|
||||
import "../markdown";
|
||||
import "../local_message";
|
||||
import "../sent_messages";
|
||||
import "../compose_state";
|
||||
|
|
|
@ -16,6 +16,7 @@ const compose_pm_pill = require("./compose_pm_pill");
|
|||
const drafts = require("./drafts");
|
||||
const echo = require("./echo");
|
||||
const loading = require("./loading");
|
||||
const markdown = require("./markdown");
|
||||
const peer_data = require("./peer_data");
|
||||
const people = require("./people");
|
||||
const rendered_markdown = require("./rendered_markdown");
|
||||
|
|
|
@ -5,6 +5,7 @@ import render_draft_table_body from "../templates/draft_table_body.hbs";
|
|||
|
||||
import * as compose_fade from "./compose_fade";
|
||||
import {localstorage} from "./localstorage";
|
||||
import * as markdown from "./markdown";
|
||||
import * as people from "./people";
|
||||
import * as util from "./util";
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as alert_words from "./alert_words";
|
||||
import * as markdown from "./markdown";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as people from "./people";
|
||||
import * as pm_list from "./pm_list";
|
||||
|
|
|
@ -41,7 +41,6 @@ declare let lightbox: any;
|
|||
declare let list_util: any;
|
||||
declare let list_widget: any;
|
||||
declare let local_message: any;
|
||||
declare let markdown: any;
|
||||
declare let message_edit: any;
|
||||
declare let message_events: any;
|
||||
declare let message_fetch: any;
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
"use strict";
|
||||
import {isValid} from "date-fns";
|
||||
import katex from "katex";
|
||||
import _ from "lodash";
|
||||
|
||||
const {isValid} = require("date-fns");
|
||||
const katex = require("katex");
|
||||
const _ = require("lodash");
|
||||
|
||||
const emoji = require("../shared/js/emoji");
|
||||
const fenced_code = require("../shared/js/fenced_code");
|
||||
const marked = require("../third/marked/lib/marked");
|
||||
import * as emoji from "../shared/js/emoji";
|
||||
import * as fenced_code from "../shared/js/fenced_code";
|
||||
import marked from "../third/marked/lib/marked";
|
||||
|
||||
// This contains zulip's frontend Markdown implementation; see
|
||||
// docs/subsystems/markdown.md for docs on our Markdown syntax. The other
|
||||
|
@ -38,7 +36,7 @@ const backend_only_markdown_re = [
|
|||
/\S*(?:twitter|youtube).com\/\S*/,
|
||||
];
|
||||
|
||||
exports.translate_emoticons_to_names = (text) => {
|
||||
export function translate_emoticons_to_names(text) {
|
||||
// Translates emoticons in a string to their colon syntax.
|
||||
let translated = text;
|
||||
let replacement_text;
|
||||
|
@ -76,9 +74,9 @@ exports.translate_emoticons_to_names = (text) => {
|
|||
}
|
||||
|
||||
return translated;
|
||||
};
|
||||
}
|
||||
|
||||
exports.contains_backend_only_syntax = function (content) {
|
||||
export function contains_backend_only_syntax(content) {
|
||||
// Try to guess whether or not a message contains syntax that only the
|
||||
// backend Markdown processor can correctly handle.
|
||||
// If it doesn't, we can immediately render it client-side for local echo.
|
||||
|
@ -93,9 +91,9 @@ exports.contains_backend_only_syntax = function (content) {
|
|||
return regex.test(content);
|
||||
});
|
||||
return markedup !== undefined || false_filter_match !== undefined;
|
||||
};
|
||||
}
|
||||
|
||||
exports.apply_markdown = function (message) {
|
||||
export function apply_markdown(message) {
|
||||
message_store.init_booleans(message);
|
||||
|
||||
const options = {
|
||||
|
@ -201,10 +199,10 @@ exports.apply_markdown = function (message) {
|
|||
};
|
||||
// Our python-markdown processor appends two \n\n to input
|
||||
message.content = marked(message.raw_content + "\n\n", options).trim();
|
||||
message.is_me_message = exports.is_status_message(message.raw_content);
|
||||
};
|
||||
message.is_me_message = is_status_message(message.raw_content);
|
||||
}
|
||||
|
||||
exports.add_topic_links = function (message) {
|
||||
export function add_topic_links(message) {
|
||||
if (message.type !== "stream") {
|
||||
message.topic_links = [];
|
||||
return;
|
||||
|
@ -239,11 +237,11 @@ exports.add_topic_links = function (message) {
|
|||
}
|
||||
|
||||
message.topic_links = links;
|
||||
};
|
||||
}
|
||||
|
||||
exports.is_status_message = function (raw_content) {
|
||||
export function is_status_message(raw_content) {
|
||||
return raw_content.startsWith("/me ");
|
||||
};
|
||||
}
|
||||
|
||||
function make_emoji_span(codepoint, title, alt_text) {
|
||||
return `<span aria-label="${_.escape(title)}" class="emoji emoji-${_.escape(
|
||||
|
@ -425,7 +423,7 @@ function python_to_js_filter(pattern, url) {
|
|||
return [final_regex, url];
|
||||
}
|
||||
|
||||
exports.update_realm_filter_rules = function (realm_filters) {
|
||||
export function update_realm_filter_rules(realm_filters) {
|
||||
// Update the marked parser with our particular set of realm filters
|
||||
realm_filter_map.clear();
|
||||
realm_filter_list = [];
|
||||
|
@ -445,9 +443,9 @@ exports.update_realm_filter_rules = function (realm_filters) {
|
|||
}
|
||||
|
||||
marked.InlineLexer.rules.zulip.realm_filters = marked_rules;
|
||||
};
|
||||
}
|
||||
|
||||
exports.initialize = function (realm_filters, helper_config) {
|
||||
export function initialize(realm_filters, helper_config) {
|
||||
helpers = helper_config;
|
||||
|
||||
function disable_markdown_regex(rules, name) {
|
||||
|
@ -485,7 +483,7 @@ exports.initialize = function (realm_filters, helper_config) {
|
|||
|
||||
// In this scenario, the message has to be from the user, so the only
|
||||
// requirement should be that they have the setting on.
|
||||
return exports.translate_emoticons_to_names(src);
|
||||
return translate_emoticons_to_names(src);
|
||||
}
|
||||
|
||||
// Disable lheadings
|
||||
|
@ -506,7 +504,7 @@ exports.initialize = function (realm_filters, helper_config) {
|
|||
// Disable autolink as (a) it is not used in our backend and (b) it interferes with @mentions
|
||||
disable_markdown_regex(marked.InlineLexer.rules.zulip, "autolink");
|
||||
|
||||
exports.update_realm_filter_rules(realm_filters);
|
||||
update_realm_filter_rules(realm_filters);
|
||||
|
||||
// Tell our fenced code preprocessor how to insert arbitrary
|
||||
// HTML into the output. This generated HTML is safe to not escape
|
||||
|
@ -531,6 +529,4 @@ exports.initialize = function (realm_filters, helper_config) {
|
|||
renderer: r,
|
||||
preprocessors: [preprocess_code_blocks, preprocess_translate_emoticons],
|
||||
});
|
||||
};
|
||||
|
||||
window.markdown = exports;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ const render_topic_edit_form = require("../templates/topic_edit_form.hbs");
|
|||
const channel = require("./channel");
|
||||
const echo = require("./echo");
|
||||
const loading = require("./loading");
|
||||
const markdown = require("./markdown");
|
||||
const message_viewport = require("./message_viewport");
|
||||
const rows = require("./rows");
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import * as emoji from "../shared/js/emoji";
|
|||
|
||||
import * as alert_words from "./alert_words";
|
||||
import * as compose_fade from "./compose_fade";
|
||||
import * as markdown from "./markdown";
|
||||
import * as muting_ui from "./muting_ui";
|
||||
import * as narrow_state from "./narrow_state";
|
||||
import * as peer_data from "./peer_data";
|
||||
|
|
|
@ -15,6 +15,7 @@ const drafts = require("./drafts");
|
|||
const echo = require("./echo");
|
||||
const emojisets = require("./emojisets");
|
||||
const invite = require("./invite");
|
||||
const markdown = require("./markdown");
|
||||
const markdown_config = require("./markdown_config");
|
||||
const message_viewport = require("./message_viewport");
|
||||
const muting = require("./muting");
|
||||
|
|
Loading…
Reference in New Issue