mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
markdown: Extract get_topic_links.
This commit is contained in:
@@ -218,3 +218,18 @@ test("linkifiers", () => {
|
|||||||
'<p>see <a href="http://foo.com/12345" title="http://foo.com/12345">#foo12345</a> for details</p>',
|
'<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",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|||||||
@@ -283,12 +283,9 @@ function parse_with_options({raw_content, helper_config, options}) {
|
|||||||
return {content, flags};
|
return {content, flags};
|
||||||
}
|
}
|
||||||
|
|
||||||
function do_add_topic_links({message, get_linkifier_map}) {
|
export function get_topic_links({topic, get_linkifier_map}) {
|
||||||
if (message.type !== "stream") {
|
// We export this for testing purposes, and mobile may want to
|
||||||
message.topic_links = [];
|
// use this as well in the future.
|
||||||
return;
|
|
||||||
}
|
|
||||||
const topic = message.topic;
|
|
||||||
const links = [];
|
const links = [];
|
||||||
|
|
||||||
for (const [pattern, url] of get_linkifier_map().entries()) {
|
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) {
|
for (const match of links) {
|
||||||
delete match.index;
|
delete match.index;
|
||||||
}
|
}
|
||||||
message.topic_links = links;
|
|
||||||
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function is_status_message(raw_content) {
|
export function is_status_message(raw_content) {
|
||||||
@@ -614,7 +612,14 @@ export function apply_markdown(message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function add_topic_links(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) {
|
export function parse_non_message(raw_content) {
|
||||||
|
|||||||
Reference in New Issue
Block a user