mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
Revert "markdown: Add support to shorten GitHub links."
This reverts commit 9c6d8d9d81 (#16916).
This feature has known bugs, and also wants some design changes to
make it customizable like linkifiers, so we’re retargeting this to
post-4.x.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
4f6fc728cd
commit
ceb7e2d2bd
@@ -561,58 +561,6 @@ inline.zulip = merge({}, inline.breaks, {
|
||||
()
|
||||
});
|
||||
|
||||
function shorten_links(href) {
|
||||
// This value must match what is used in the backend.
|
||||
const COMMIT_ID_PREFIX_LENGTH = 12;
|
||||
const url = new URL(href);
|
||||
if (url.protocol === 'https:' && ['github.com'].includes(url.hostname)) {
|
||||
// The following part of the code was necessary because unlike Python, str.split
|
||||
// method in javascript does not return the remaining part of the string.
|
||||
var parts = url.pathname.split('/').slice(1);
|
||||
parts = parts.slice(0, 4)
|
||||
.concat(parts.slice(4).join('/'))
|
||||
.concat(Array(5).fill(''))
|
||||
.slice(0, 5);
|
||||
|
||||
const organisation = parts[0]
|
||||
, repository = parts[1]
|
||||
, artifact = parts[2]
|
||||
, value = parts[3]
|
||||
, remaining_path = parts[4];
|
||||
|
||||
if (!organisation || !repository || !artifact || !value) {
|
||||
return href;
|
||||
}
|
||||
|
||||
const repo_short_text = organisation + '/' + repository;
|
||||
|
||||
if (remaining_path || url.hash) {
|
||||
return href;
|
||||
}
|
||||
|
||||
if (url.hostname === 'github.com') {
|
||||
return shorten_github_links(href, artifact, repo_short_text,
|
||||
value, COMMIT_ID_PREFIX_LENGTH);
|
||||
}
|
||||
}
|
||||
return href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten GitHub Links
|
||||
*/
|
||||
|
||||
function shorten_github_links(href, artifact, repo_short_text,
|
||||
value, commit_id_prefix_length) {
|
||||
if (['pull', 'issues'].includes(artifact)) {
|
||||
return repo_short_text + '#' + value;
|
||||
}
|
||||
if (artifact == 'commit') {
|
||||
return repo_short_text + '@' + value.slice(0, commit_id_prefix_length);
|
||||
}
|
||||
return href;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inline Lexer & Compiler
|
||||
*/
|
||||
@@ -734,8 +682,8 @@ InlineLexer.prototype.output = function(src) {
|
||||
// url (gfm)
|
||||
if (!this.inLink && (cap = this.rules.url.exec(src))) {
|
||||
src = src.substring(cap[0].length);
|
||||
href = escape(cap[1]);
|
||||
text = shorten_links(href)
|
||||
text = escape(cap[1]);
|
||||
href = text;
|
||||
out += this.renderer.link(href, null, text);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user