diff --git a/pkg/packagekit/updates.jsx b/pkg/packagekit/updates.jsx index b4389020ad5..baebff922c0 100644 --- a/pkg/packagekit/updates.jsx +++ b/pkg/packagekit/updates.jsx @@ -240,8 +240,29 @@ function getSeverityURL(urls) { return highestURL; } -function updateItem(info, pkgNames, key) { +// Overrides the link_open function to apply our required HTML attributes +function customRemarkable() { const remarkable = new Remarkable(); + + const orig_link_open = remarkable.renderer.rules.link_open; + remarkable.renderer.rules.link_open = function() { + let result = orig_link_open.apply(null, arguments); + + const parser = new DOMParser(); + const htmlDocument = parser.parseFromString(result, "text/html"); + const links = htmlDocument.getElementsByTagName("a"); + if (links.length === 1) { + const href = links[0].getAttribute("href"); + result = ``; + } + return result; + }; + return remarkable; +} + +function updateItem(info, pkgNames, key) { + const remarkable = customRemarkable(); + let bugs = null; if (info.bug_urls && info.bug_urls.length) { // we assume a bug URL ends with a number; if not, show the complete URL diff --git a/test/verify/check-packagekit b/test/verify/check-packagekit index 89372e8a639..ce1950757ad 100755 --- a/test/verify/check-packagekit +++ b/test/verify/check-packagekit @@ -766,9 +766,11 @@ ExecStart=/usr/local/bin/{packageName} # verify Markdown formatting in table cell self.assertEqual(b.text(sel + " td.changelog em"), "more") # *more* self.assertEqual(b.attr(sel + " td.changelog a", "href"), "http://unicorn.example.com") + self.assertEqual(b.attr(sel + " td.changelog a", "target"), "_blank") # verify Markdown formatting in details self.assertEqual(b.text(sel + " .pf-m-expanded em"), "more") # *more* self.assertEqual(b.attr(sel + " .pf-m-expanded a:first-of-type", "href"), "http://unicorn.example.com") + self.assertEqual(b.attr(sel + " .pf-m-expanded a:first-of-type", "target"), "_blank") # verify that changelog is absent in mobile b.set_layout("mobile")