diff --git a/static/js/markdown.js b/static/js/markdown.js index 1e210b924d..0b15e5e445 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -439,6 +439,9 @@ exports.initialize = function () { // Our links have title= and target=_blank r.link = function (href, title, text) { title = title || href; + if (!text.trim()) { + text = href; + } var out = '' + text + ''; return out; diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index d4d851351d..40569f6723 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -1802,6 +1802,10 @@ class LinkInlineProcessor(markdown.inlinepatterns.LinkInlineProcessor): el.set("href", href) fixup_link(el, target_blank=(href[:1] != '#')) + # Show link href if title is empty + if not el.text.strip(): + el.text = href + # Prevent realm_filters from running on the content of a Markdown link, breaking up the link. # This is a monkey-patch, but it might be worth sending a version of this change upstream. if not isinstance(el, str): diff --git a/zerver/tests/fixtures/markdown_test_cases.json b/zerver/tests/fixtures/markdown_test_cases.json index bbe7032b3d..cc53eda7f2 100644 --- a/zerver/tests/fixtures/markdown_test_cases.json +++ b/zerver/tests/fixtures/markdown_test_cases.json @@ -373,6 +373,21 @@ "input": "https://github.com", "expected_output": "
" }, + { + "name": "link_with_text", + "input": "[hello](https://github.com)", + "expected_output": "" + }, + { + "name": "link_without_text", + "input": "[](https://github.com)", + "expected_output": "" + }, + { + "name": "link_with_empty_text", + "input": "[ ](https://github.com)", + "expected_output": "" + }, { "name": "nl2br", "input": "test\nbar",