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: Extract get_topic_links.

Steve Howell2bfdbbe7dc73
diff --git a/frontend_tests/node_tests/markdown_parse.js b/frontend_tests/node_tests/markdown_parse.js
index 9fa6e200efc..4de2c4eda5d 100644
--- a/frontend_tests/node_tests/markdown_parse.js
+++ b/frontend_tests/node_tests/markdown_parse.js
@@ -218,3 +218,18 @@ test("linkifiers", () => {
'<p>see <a href="http://foo.com/12345" title="http://foo.com/12345">#foo12345</a> for details</p>',
);
});
+
+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, [
+ {
+ text: "#foo101",
+ url: "http://foo.com/101",
+ },
+ {
+ text: "#foo102",
+ url: "http://foo.com/102",
+ },
+ ]);
+});
diff --git a/static/js/markdown.js b/static/js/markdown.js
index dd188c8ce7d..f390282da4f 100644
--- a/static/js/markdown.js
+++ b/static/js/markdown.js
@@ -283,12 +283,9 @@ function parse_with_options({raw_content, helper_config, options}) {
return {content, flags};
}
-function do_add_topic_links({message, get_linkifier_map}) {
- if (message.type !== "stream") {
- message.topic_links = [];
- return;
- }
- const topic = message.topic;
+export function get_topic_links({topic, get_linkifier_map}) {
+ // We export this for testing purposes, and mobile may want to
+ // use this as well in the future.
const links = [];
for (const [pattern, url] of get_linkifier_map().entries()) {
@@ -322,7 +319,8 @@ function do_add_topic_links({message, get_linkifier_map}) {
for (const match of links) {
delete match.index;
}
- message.topic_links = links;
+
+ return links;
}
export function is_status_message(raw_content) {
@@ -614,7 +612,14 @@ export function apply_markdown(message) {
}
export function add_topic_links(message) {
- return do_add_topic_links({message, get_linkifier_map: webapp_helpers.get_linkifier_map});
+ if (message.type !== "stream") {
+ message.topic_links = [];
+ return;
+ }
+ message.topic_links = get_topic_links({
+ topic: message.topic,
+ get_linkifier_map: webapp_helpers.get_linkifier_map,
+ });
}
export function parse_non_message(raw_content) {