rendered_markdown: Fix stream-topic parser.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-04-29 11:11:03 -07:00 committed by Tim Abbott
parent 65c400e06d
commit eae05ba0ae
2 changed files with 5 additions and 6 deletions

View File

@ -148,19 +148,19 @@ run_test("stream-links", () => {
const $stream_topic = $.create("a.stream-topic"); const $stream_topic = $.create("a.stream-topic");
$stream_topic.set_find_results(".highlight", false); $stream_topic.set_find_results(".highlight", false);
$stream_topic.attr("data-stream-id", stream.stream_id); $stream_topic.attr("data-stream-id", stream.stream_id);
$stream_topic.text("#random>topic name"); $stream_topic.text("#random > topic name > still the topic name");
$content.set_find_results("a.stream", $array([$stream])); $content.set_find_results("a.stream", $array([$stream]));
$content.set_find_results("a.stream-topic", $array([$stream_topic])); $content.set_find_results("a.stream-topic", $array([$stream_topic]));
// Initial asserts // Initial asserts
assert.equal($stream.text(), "never-been-set"); assert.equal($stream.text(), "never-been-set");
assert.equal($stream_topic.text(), "#random>topic name"); assert.equal($stream_topic.text(), "#random > topic name > still the topic name");
rm.update_elements($content); rm.update_elements($content);
// Final asserts // Final asserts
assert.equal($stream.text(), `#${stream.name}`); assert.equal($stream.text(), `#${stream.name}`);
assert.equal($stream_topic.text(), `#${stream.name} > topic name`); assert.equal($stream_topic.text(), `#${stream.name} > topic name > still the topic name`);
}); });
run_test("timestamp", () => { run_test("timestamp", () => {

View File

@ -142,14 +142,13 @@ export const update_elements = (content) => {
if (stream_id && !$(this).find(".highlight").length) { if (stream_id && !$(this).find(".highlight").length) {
// Display the current name for stream if it is not // Display the current name for stream if it is not
// being displayed in search highlight. // being displayed in search highlight.
const text = $(this).text();
const topic = text.split(">", 2)[1];
const stream_name = stream_data.maybe_get_stream_name(stream_id); const stream_name = stream_data.maybe_get_stream_name(stream_id);
if (stream_name !== undefined) { if (stream_name !== undefined) {
// If the stream has been deleted, // If the stream has been deleted,
// stream_data.maybe_get_stream_name might return // stream_data.maybe_get_stream_name might return
// undefined. Otherwise, display the current stream name. // undefined. Otherwise, display the current stream name.
$(this).text("#" + stream_name + " > " + topic); const text = $(this).text();
$(this).text("#" + stream_name + text.slice(text.indexOf(" > ")));
} }
} }
}); });