mirror of https://github.com/zulip/zulip.git
copy_and_paste: Paste fallback md link if syntax link will be broken.
If we paste a stream-topic URL that can be formatted as per #29302, we now generate a normal markdown link if the stream topic syntax could result in a broken link. Fixes #31904
This commit is contained in:
parent
da4443f392
commit
327647f4f8
|
@ -666,18 +666,21 @@ export function try_stream_topic_syntax_text(text: string): string | null {
|
|||
return null;
|
||||
}
|
||||
|
||||
// Now we're sure that the URL is a valid stream topic URL.
|
||||
// But the produced #**stream>topic** syntax could be broken.
|
||||
|
||||
const stream = stream_data.get_sub_by_id(stream_topic.stream_id);
|
||||
assert(stream !== undefined);
|
||||
const stream_name = stream.name;
|
||||
if (topic_link_util.will_produce_broken_stream_topic_link(stream_name)) {
|
||||
return null;
|
||||
return topic_link_util.get_fallback_markdown_link(stream_name, stream_topic.topic_name);
|
||||
}
|
||||
|
||||
if (
|
||||
stream_topic.topic_name !== undefined &&
|
||||
topic_link_util.will_produce_broken_stream_topic_link(stream_topic.topic_name)
|
||||
) {
|
||||
return null;
|
||||
return topic_link_util.get_fallback_markdown_link(stream_name, stream_topic.topic_name);
|
||||
}
|
||||
|
||||
let syntax_text = "#**" + stream_name;
|
||||
|
|
|
@ -12,6 +12,10 @@ stream_data.add_sub({
|
|||
stream_id: 4,
|
||||
name: "Rome",
|
||||
});
|
||||
stream_data.add_sub({
|
||||
stream_id: 5,
|
||||
name: "Romeo`s lair",
|
||||
});
|
||||
|
||||
run_test("try_stream_topic_syntax_text", () => {
|
||||
const test_cases = [
|
||||
|
@ -41,11 +45,28 @@ run_test("try_stream_topic_syntax_text", () => {
|
|||
["http://zulip.zulipdev.com/#narrow/topic/cheese"],
|
||||
["http://zulip.zulipdev.com/#narrow/topic/pizza/stream/Rome"],
|
||||
|
||||
// characters which are known to produce broken #**stream>topic** urls.
|
||||
["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/100.25.20profits.60"],
|
||||
["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/100.25.20*profits"],
|
||||
["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/.24.24 100.25.20profits"],
|
||||
["http://zulip.zulipdev.com/#narrow/channel/4-Rome/topic/>100.25.20profits"],
|
||||
// When a url containing characters which are known to produce broken
|
||||
// #**stream>topic** urls is pasted, a normal markdown link syntax is produced.
|
||||
[
|
||||
"http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/100.25.20profits.60",
|
||||
"[#Rome>100% profits`](#narrow/channel/4-Rome/topic/100.25.20profits.60)",
|
||||
],
|
||||
[
|
||||
"http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/100.25.20*profits",
|
||||
"[#Rome>100% *profits](#narrow/channel/4-Rome/topic/100.25.20*profits)",
|
||||
],
|
||||
[
|
||||
"http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/.24.24 100.25.20profits",
|
||||
"[#Rome>$$ 100% profits](#narrow/channel/4-Rome/topic/.24.24.20100.25.20profits)",
|
||||
],
|
||||
[
|
||||
"http://zulip.zulipdev.com/#narrow/stream/4-Rome/topic/>100.25.20profits",
|
||||
"[#Rome>>100% profits](#narrow/channel/4-Rome/topic/.3E100.25.20profits)",
|
||||
],
|
||||
[
|
||||
"http://zulip.zulipdev.com/#narrow/stream/5-Romeo.60s-lair/topic/normal",
|
||||
"[#Romeo`s lair>normal](#narrow/channel/5-Romeo.60s-lair/topic/normal)",
|
||||
],
|
||||
];
|
||||
|
||||
for (const test_case of test_cases) {
|
||||
|
|
Loading…
Reference in New Issue