mirror of https://github.com/zulip/zulip.git
markdown: Fix marked generation of unnecessarily absolute URLs.
The new versions should exactly match the HTML we generate in the backend unit test suite.
This commit is contained in:
parent
e68f90db9c
commit
e8e420bbd9
|
@ -299,15 +299,15 @@ run_test('marked', () => {
|
|||
{input: 'These #* #*** are also not mentions',
|
||||
expected: '<p>These #* #*** are also not mentions</p>'},
|
||||
{input: 'This is a #**Denmark** stream link',
|
||||
expected: '<p>This is a <a class="stream" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark">#Denmark</a> stream link</p>'},
|
||||
expected: '<p>This is a <a class="stream" data-stream-id="1" href="/#narrow/stream/1-Denmark">#Denmark</a> stream link</p>'},
|
||||
{input: 'This is #**Denmark** and #**social** stream links',
|
||||
expected: '<p>This is <a class="stream" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark">#Denmark</a> and <a class="stream" data-stream-id="2" href="http://zulip.zulipdev.com/#narrow/stream/2-social">#social</a> stream links</p>'},
|
||||
expected: '<p>This is <a class="stream" data-stream-id="1" href="/#narrow/stream/1-Denmark">#Denmark</a> and <a class="stream" data-stream-id="2" href="/#narrow/stream/2-social">#social</a> stream links</p>'},
|
||||
{input: 'And this is a #**wrong** stream link',
|
||||
expected: '<p>And this is a #**wrong** stream link</p>'},
|
||||
{input: 'This is a #**Denmark>some topic** stream_topic link',
|
||||
expected: '<p>This is a <a class="stream-topic" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark/topic/some.20topic">#Denmark > some topic</a> stream_topic link</p>'},
|
||||
expected: '<p>This is a <a class="stream-topic" data-stream-id="1" href="/#narrow/stream/1-Denmark/topic/some.20topic">#Denmark > some topic</a> stream_topic link</p>'},
|
||||
{input: 'This has two links: #**Denmark>some topic** and #**social>other topic**.',
|
||||
expected: '<p>This has two links: <a class="stream-topic" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark/topic/some.20topic">#Denmark > some topic</a> and <a class="stream-topic" data-stream-id="2" href="http://zulip.zulipdev.com/#narrow/stream/2-social/topic/other.20topic">#social > other topic</a>.</p>'},
|
||||
expected: '<p>This has two links: <a class="stream-topic" data-stream-id="1" href="/#narrow/stream/1-Denmark/topic/some.20topic">#Denmark > some topic</a> and <a class="stream-topic" data-stream-id="2" href="/#narrow/stream/2-social/topic/other.20topic">#social > other topic</a>.</p>'},
|
||||
{input: 'This is not a #**Denmark>** stream_topic link',
|
||||
expected: '<p>This is not a #**Denmark>** stream_topic link</p>'},
|
||||
{input: 'mmm...:burrito:s',
|
||||
|
@ -340,7 +340,7 @@ run_test('marked', () => {
|
|||
{input: 'Test *italic*',
|
||||
expected: '<p>Test <em>italic</em></p>'},
|
||||
{input: 'T\n#**Denmark**',
|
||||
expected: '<p>T<br>\n<a class="stream" data-stream-id="1" href="http://zulip.zulipdev.com/#narrow/stream/1-Denmark">#Denmark</a></p>'},
|
||||
expected: '<p>T<br>\n<a class="stream" data-stream-id="1" href="/#narrow/stream/1-Denmark">#Denmark</a></p>'},
|
||||
{input: 'T\n@**Cordelia Lear**',
|
||||
expected: '<p>T<br>\n<span class="user-mention" data-user-id="101">@Cordelia Lear</span></p>'},
|
||||
{input: '@**Mark Twin|104** and @**Mark Twin|105** are out to confuse you.',
|
||||
|
@ -387,7 +387,7 @@ run_test('marked', () => {
|
|||
{input: '@**Bobby <h1>Tables</h1>**',
|
||||
expected: '<p><span class="user-mention" data-user-id="103">@Bobby <h1>Tables</h1></span></p>'},
|
||||
{input: '#**Bobby <h1>Tables</h1>**',
|
||||
expected: '<p><a class="stream-topic" data-stream-id="4" href="http://zulip.zulipdev.com/#narrow/stream/4-Bobby-.3Ch1/topic/Tables.3C.2Fh1.3E">#Bobby <h1 > Tables</h1></a></p>'},
|
||||
expected: '<p><a class="stream-topic" data-stream-id="4" href="/#narrow/stream/4-Bobby-.3Ch1/topic/Tables.3C.2Fh1.3E">#Bobby <h1 > Tables</h1></a></p>'},
|
||||
];
|
||||
|
||||
// We remove one of the unicode emoji we put as input in one of the test
|
||||
|
|
|
@ -221,9 +221,9 @@ function handleStream(streamName) {
|
|||
if (stream === undefined) {
|
||||
return;
|
||||
}
|
||||
var href = window.location.origin + '/#narrow/stream/' + hash_util.encode_stream_name(stream.name);
|
||||
var href = hash_util.by_stream_uri(stream.stream_id);
|
||||
return '<a class="stream" data-stream-id="' + stream.stream_id + '" ' +
|
||||
'href="' + href + '"' +
|
||||
'href="/' + href + '"' +
|
||||
'>' + '#' + escape(stream.name) + '</a>';
|
||||
}
|
||||
|
||||
|
@ -232,11 +232,10 @@ function handleStreamTopic(streamName, topic) {
|
|||
if (stream === undefined || !topic) {
|
||||
return;
|
||||
}
|
||||
var href = window.location.origin + '/#narrow/stream/' + hash_util.encode_stream_name(stream.name);
|
||||
href += '/topic/' + hash_util.encodeHashComponent(topic);
|
||||
var href = hash_util.by_stream_topic_uri(stream.stream_id, topic);
|
||||
var text = '#' + escape(stream.name) + ' > ' + escape(topic);
|
||||
return '<a class="stream-topic" data-stream-id="' + stream.stream_id + '" ' +
|
||||
'href="' + href + '"' + '>' + text + '</a>';
|
||||
'href="/' + href + '"' + '>' + text + '</a>';
|
||||
}
|
||||
|
||||
function handleRealmFilter(pattern, matches) {
|
||||
|
|
Loading…
Reference in New Issue