From cf7d1ea23c27efb9643e1a7c07f269fa28bd663d Mon Sep 17 00:00:00 2001 From: MrOtherGuy Date: Sun, 6 Dec 2020 15:55:51 +0200 Subject: [PATCH] make highlighter generate links to .css files mentioned in comments --- html_resources/main.css | 1 + html_resources/selector.js | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/html_resources/main.css b/html_resources/main.css index 5fb9b68..8a961ef 100644 --- a/html_resources/main.css +++ b/html_resources/main.css @@ -31,6 +31,7 @@ body{background-color: rgb(60,50,70); color: silver; margin: 0px } } a{ color: rgb(100,150,200); margin-inline-start: 1ch } +pre a{ margin: 0 } a:visited{ color: rgb(150,100,200) } a:hover{ color: rgb(200,150,100) } pre:empty{ display: none } diff --git a/html_resources/selector.js b/html_resources/selector.js index 8838cf1..57903e3 100644 --- a/html_resources/selector.js +++ b/html_resources/selector.js @@ -294,7 +294,28 @@ const Highlighter = new(function(){ } - }else{ + } else if(type === "comment"){ + let linksToFile = token.match(/[\w-\.]+\.css/g); + if(linksToFile && linksToFile.length){ + let linkIdx = 0; + let fromIdx = 0; + while(linkIdx < linksToFile.length){ + let part = linksToFile[linkIdx++]; + let idx = token.indexOf(part); + n.append(token.substring(fromIdx,idx)); + let link = document.createElement("a"); + link.textContent = part; + link.href = `https://github.com/MrOtherGuy/firefox-csshacks/tree/master/chrome/${part}`; + link.target = "_blank"; + n.appendChild(link); + fromIdx = idx + part.length; + } + n.append(token.substring(fromIdx)); + }else{ + n.textContent = c || token + } + } + else{ n.textContent = c || token; }