markdown: Show link href if title is empty.

Fixes #6221.
This commit is contained in:
Rohitt Vashishtha 2019-08-11 11:34:24 +00:00 committed by Tim Abbott
parent abe2dab88c
commit 8b443a25b8
3 changed files with 22 additions and 0 deletions

View File

@ -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 = '<a href="' + href + '"' + ' target="_blank" title="' +
title + '"' + '>' + text + '</a>';
return out;

View File

@ -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):

View File

@ -373,6 +373,21 @@
"input": "https://github.com",
"expected_output": "<p><a href=\"https://github.com\" target=\"_blank\" title=\"https://github.com\">https://github.com</a></p>"
},
{
"name": "link_with_text",
"input": "[hello](https://github.com)",
"expected_output": "<p><a href=\"https://github.com\" target=\"_blank\" title=\"https://github.com\">hello</a></p>"
},
{
"name": "link_without_text",
"input": "[](https://github.com)",
"expected_output": "<p><a href=\"https://github.com\" target=\"_blank\" title=\"https://github.com\">https://github.com</a></p>"
},
{
"name": "link_with_empty_text",
"input": "[ ](https://github.com)",
"expected_output": "<p><a href=\"https://github.com\" target=\"_blank\" title=\"https://github.com\">https://github.com</a></p>"
},
{
"name": "nl2br",
"input": "test\nbar",