Skip to content

Commit

Permalink
Fixed regex, added class name for hovercard and removed a line that w…
Browse files Browse the repository at this point in the history
…ould get rid of the class name.
  • Loading branch information
PopPaolo committed Jul 10, 2023
1 parent 7d38ebc commit a5daa04
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/global/vhpMarkdown.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import showdown from "showdown";
import sanitizeHtml from "sanitize-html";
import setHovercard from "./Hovercard";

export function vhpMarkdownAll() {
for (let e of document.querySelectorAll(".vhp-markdown")) {
e.innerHTML = vhpMarkdown(e.textContent.trim());
}
setHovercard('.cve_link')
}

// VHP-Flavored Markdown
Expand All @@ -21,16 +23,15 @@ export function vhpMarkdown(str) {
simplifiedAutoLink: true, // find any URLs and link em
});
str = converter.makeHtml(str);
str = cleanHtml(str);
return str;
}

// Autolink all vulnerabilities following the format CVE-####-#### (case insensitive).
// The rightmost number can be 4+ digits long according to
// https://cve.mitre.org/about/faqs.html#cve_id_syntax_change
function linkifyCVE(str) {
const regexp = /(CVE-\d{4}\-\d{4,})/gi;
const linkText = "[:vulnerability:$1](/cves/$1)";
const regexp = /(CVE-\d{4}-\d{4,})/gi;
const linkText = "<a class='cve_link' href='/vulnerabilities/$1'>:vulnerability:$1</a>";

This comment has been minimized.

Copy link
@PopPaolo

PopPaolo Jul 10, 2023

Author Contributor

Also updated link to the correct endpoint.

return str.replace(regexp, linkText);
}

Expand Down

0 comments on commit a5daa04

Please sign in to comment.