mirror of https://github.com/zulip/zulip.git
markdown: Extract get_topic_links.
This commit is contained in:
parent
326dbfb934
commit
2bfdbbe7dc
|
@ -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",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue