Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

markdown: Eliminate setup() call.

Steve Howell214ec099bb14
diff --git a/frontend_tests/node_tests/markdown_parse.js b/frontend_tests/node_tests/markdown_parse.js
index 4de2c4eda5d..1e585409289 100644
--- a/frontend_tests/node_tests/markdown_parse.js
+++ b/frontend_tests/node_tests/markdown_parse.js
@@ -152,17 +152,12 @@ function assert_parse(raw_content, expected_content) {
assert.equal(content, expected_content);
}
-function test(label, f) {
- markdown.setup();
- run_test(label, f);
-}
-
-test("basics", () => {
+run_test("basics", () => {
assert_parse("boring", "<p>boring</p>");
assert_parse("**bold**", "<p><strong>bold</strong></p>");
});
-test("user mentions", () => {
+run_test("user mentions", () => {
assert_parse("@**greg**", '<p><span class="user-mention" data-user-id="105">@greg</span></p>');
assert_parse("@**|105**", '<p><span class="user-mention" data-user-id="105">@greg</span></p>');
@@ -178,14 +173,14 @@ test("user mentions", () => {
);
});
-test("user group mentions", () => {
+run_test("user group mentions", () => {
assert_parse(
"@*Staff*",
'<p><span class="user-group-mention" data-user-group-id="201">@Staff</span></p>',
);
});
-test("stream links", () => {
+run_test("stream links", () => {
assert_parse(
"#**social**",
'<p><a class="stream" data-stream-id="301" href="/stream-301">#social</a></p>',
@@ -197,7 +192,7 @@ test("stream links", () => {
);
});
-test("emojis", () => {
+run_test("emojis", () => {
assert_parse(
"yup :)",
'<p>yup <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>',
@@ -212,14 +207,14 @@ test("emojis", () => {
);
});
-test("linkifiers", () => {
+run_test("linkifiers", () => {
assert_parse(
"see #foo12345 for details",
'<p>see <a href="http://foo.com/12345" title="http://foo.com/12345">#foo12345</a> for details</p>',
);
});
-test("topic links", () => {
+run_test("topic links", () => {
const topic = "progress on #foo101 and #foo102";
const topic_links = markdown.get_topic_links({topic, get_linkifier_map});
assert.deepEqual(topic_links, [
diff --git a/static/js/markdown.js b/static/js/markdown.js
index f390282da4f..e2de62d9c06 100644
--- a/static/js/markdown.js
+++ b/static/js/markdown.js
@@ -453,10 +453,7 @@ export function get_linkifier_regexes() {
return Array.from(helpers.get_linkifier_map().keys());
}
-export function setup() {
- // Once we focus on supporting other platforms such as mobile,
- // we will export this function.
-
+export function parse({raw_content, helper_config}) {
function disable_markdown_regex(rules, name) {
rules[name] = {
exec() {
@@ -486,7 +483,7 @@ export function setup() {
}
function preprocess_translate_emoticons(src) {
- if (!helpers.should_translate_emoticons()) {
+ if (!helper_config.should_translate_emoticons()) {
return src;
}
@@ -517,21 +514,6 @@ export function setup() {
// HTML into the output. This generated HTML is safe to not escape
fenced_code.set_stash_func((html) => marked.stashHtml(html, true));
- marked.setOptions({
- gfm: true,
- tables: true,
- breaks: true,
- pedantic: false,
- sanitize: true,
- smartLists: true,
- smartypants: false,
- zulip: true,
- renderer: r,
- preprocessors: [preprocess_code_blocks, preprocess_translate_emoticons],
- });
-}
-
-export function parse({raw_content, helper_config}) {
function streamHandler(stream_name) {
return handleStream({
stream_name,
@@ -581,6 +563,16 @@ export function parse({raw_content, helper_config}) {
streamTopicHandler,
texHandler: handleTex,
timestampHandler: handleTimestamp,
+ gfm: true,
+ tables: true,
+ breaks: true,
+ pedantic: false,
+ sanitize: true,
+ smartLists: true,
+ smartypants: false,
+ zulip: true,
+ renderer: r,
+ preprocessors: [preprocess_code_blocks, preprocess_translate_emoticons],
};
return parse_with_options({raw_content, helper_config, options});
@@ -598,7 +590,6 @@ export function initialize(helper_config) {
// other platforms should call setup().
webapp_helpers = helper_config;
helpers = helper_config;
- setup();
}
export function apply_markdown(message) {