1
0
mirror of https://github.com/lus/pasty.git synced 2023-08-10 21:13:09 +03:00

Implement line highlighting [SHITCODE]

This commit is contained in:
Lukas SP 2020-09-16 20:06:01 +02:00
parent 1731fb8924
commit bd92974182
4 changed files with 73 additions and 17 deletions

View File

@ -136,20 +136,22 @@ html, body {
padding: 20px 0; padding: 20px 0;
width: 50px; width: 50px;
min-height: calc(100vh - 100px); min-height: calc(100vh - 100px);
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
background-color: #111111; background-color: #111111;
color: #bebebe; color: #bebebe;
} }
.container #linenos span {
display: block;
width: 100%;
text-align: center;
}
.container #linenos span:hover, .container #linenos span.highlight {
background-color: #92b300;
color: #ffffff;
cursor: pointer;
}
.container #content { .container #content {
padding: 20px; padding: 20px;
width: calc(100vw - 50px); width: calc(100vw - 50px);
@ -159,6 +161,12 @@ html, body {
white-space: pre; white-space: pre;
} }
.container #content #code .highlight {
background-color: #92b30071;
display: inline-block;
min-width: 100%;
}
.container #content #input { .container #content #input {
height: 100%; height: 100%;
width: 100%; width: 100%;

View File

@ -1,6 +1,6 @@
{ {
"version": 3, "version": 3,
"mappings": "AAAA,OAAO,CAAC,4EAAI;AAEZ,AAAA,IAAI,EAAE,IAAI,CAAC;EACP,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,gBAAgB,EAAE,OAAO;EACzB,KAAK,EAAE,OAAO;EACd,WAAW,EAAE,4BAA4B;CAC5C;;AACD,AAAA,OAAO,CAAC;EACJ,OAAO,EAAE,IAAI;CAChB;;AAED,kBAAkB,CAAlB,OAAkB;EACd,EAAE;IACE,iBAAiB,EAAE,0BAA0B,CAAC,YAAY;IAClD,SAAS,EAAE,0BAA0B,CAAC,YAAY;;EAE9D,IAAI;IACA,iBAAiB,EAAE,0BAA0B,CAAC,cAAc;IACpD,SAAS,EAAE,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E,SAAS;GAKrB;EATL,AAKQ,WALG,CAGL,OAAO,CAEH,GAAG,CAAC;IACF,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;GACf;EART,AAUI,WAVO,CAUL,KAAK,CAAC,QAAQ,CAAC;IACb,OAAO,EAAE,IAAI;GAChB",
"sources": [ "sources": [
"style.scss" "style.scss"
], ],

View File

@ -104,17 +104,29 @@ html, body {
padding: 20px 0; padding: 20px 0;
width: 50px; width: 50px;
min-height: calc(100vh - 100px); min-height: calc(100vh - 100px);
display: flex;
flex-direction: column;
align-items: center;
background-color: #111111; background-color: #111111;
color: #bebebe; color: #bebebe;
& span {
display: block;
width: 100%;
text-align: center;
&:hover, &.highlight {
background-color: #92b300;
color: #ffffff;
cursor: pointer;
}
}
} }
& #content { & #content {
padding: 20px; padding: 20px;
width: calc(100vw - 50px); width: calc(100vw - 50px);
& #code { & #code {
white-space: pre; white-space: pre;
& .highlight {
background-color: #92b30071;
display: inline-block;
min-width: 100%;
}
} }
& #input { & #input {
height: 100%; height: 100%;

View File

@ -44,13 +44,49 @@ async function loadPaste() {
document.getElementById("btn_copy").removeAttribute("disabled"); document.getElementById("btn_copy").removeAttribute("disabled");
// Set the paste content to the DOM // Set the paste content to the DOM
document.getElementById("code").innerHTML = language const code = document.getElementById("code");
code.innerHTML = language
? hljs.highlight(language, data.content).value ? hljs.highlight(language, data.content).value
: hljs.highlightAuto(data.content).value; : hljs.highlightAuto(data.content).value;
// Display the line numbers // Display the line numbers
document.getElementById("linenos").innerHTML = data.content.split(/\n/).map((_, index) => `<span>${index + 1}</span>`).join(''); const lineNOs = document.getElementById("linenos");
lineNOs.innerHTML = data.content.split(/\n/).map((_, index) => `<span>${index + 1}</span>`).join('');
const sharedLine = parseInt(window.location.hash.toLowerCase().replace("#l", ""), 10);
if (sharedLine) {
lineNOs.innerHTML = data.content.split(/\n/).map((_, index) => {
return index + 1 === sharedLine
? `<span class="highlight">${index + 1}</span>`
: `<span>${index + 1}</span>`;
}).join('');
let html = code.innerHTML.split(/\n/);
html[sharedLine-1] = `<span class="highlight">${html[sharedLine-1]}</span>`;
code.innerHTML = html.join("\n");
}
// TODO: Update this shitty construct
lineNOs.childNodes.forEach(node => {
node.addEventListener("click", function(_) {
const address = location.protocol + "//" + location.host + location.pathname + "#L" + node.innerText;
location.replace(address);
location.reload();
});
node.addEventListener("mouseover", function(_) {
let html = code.innerHTML.split(/\n/);
const index = parseInt(node.innerText, 10) - 1;
html[index] = `<span class="highlight">${html[index]}</span>`;
code.innerHTML = html.join("\n");
});
node.addEventListener("mouseout", function(_) {
let html = code.innerHTML.split(/\n/);
const index = parseInt(node.innerText, 10) - 1;
html[index] = html[index].substring(24, html[index].length - 7);
code.innerHTML = html.join("\n");
});
});
// Set the PASTE_ID variable // Set the PASTE_ID variable
PASTE_ID = pasteID; PASTE_ID = pasteID;
} else { } else {