Skip to content

Commit e71c1e8

Browse files
authored
Adding support for placeholders (#28)
1 parent 5089354 commit e71c1e8

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

assets/style.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ code {
6969
border-radius: 0.25em;
7070
color: $accent;
7171
background: $lighter;
72+
73+
.path {
74+
color: #777;
75+
border-bottom: 1px dashed $accent;
76+
}
7277
}
7378

7479
pre {

assets/url_helper.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function shorten_url(url_input) {
22
var url_parsed = new URL(url_input);
3-
if(['github.com', 'www.github.com'].includes(url_parsed.hostname) && url_parsed.pathname.includes('/blob/')){
3+
if (['github.com', 'www.github.com'].includes(url_parsed.hostname) && url_parsed.pathname.includes('/blob/')) {
44
let parts = url_parsed.pathname.split('/')
55
return parts.slice(-1);
66
// return "github.com/" + parts.slice(1,3).join('/') + "/(...)/" + parts.slice(-1)
@@ -17,4 +17,24 @@ window.addEventListener('load', function () {
1717
document.querySelectorAll('*[data-file-path]').forEach((element) => {
1818
element.innerHTML = highlight_path(element.innerHTML);
1919
});
20+
21+
this.document.querySelectorAll("pre>code").forEach(x => {
22+
let value = x.innerText;
23+
24+
const path_or_folder = y => y == 'folder' ? 'folder' : `file with a${y ? (' ' + y) : 'n arbitrary'} extension`
25+
const path_folder = y => y == 'folder' ? 'folder' : `file${y || '.ext'}`
26+
27+
28+
value = value.replace(/\{PATH(?::(folder|\.[a-zA-Z0-9.]+?))?\}/g, (_, y) => `<span class="path" title="A relative or absolute path to a ${path_or_folder(y)}.">${path_folder(y)}</span>`)
29+
.replace(/\{PATH_ABSOLUTE(?::(folder|\.[a-zA-Z0-9.]+?))?\}/g, (_, y) => `<span class="path" title="An absolute path to a ${path_or_folder(y)}.">C:\\Windows\\Temp\\${path_folder(y)}</span>`)
30+
.replace(/\{PATH_SMB(?::(folder|\.[a-zA-Z0-9.]+?))?\}/g, (_, y) => `<span class="path" title="An SMB path to a ${path_or_folder(y)}.">\\\\servername\\C$\\Windows\\Temp\\${path_folder(y)}</span>`)
31+
32+
.replace(/\{REMOTEURL(?::(folder|\.[a-zA-Z0-9.]+?))?\}/g, (_, y) => `<span class="path" title="A URL for ${path_or_folder(y)}.">https://www.example.org/${path_folder(y)}</span>`)
33+
34+
.replace(/\{CMD\}/g, `<span class="path" title="A command line.">cmd /c c:\\windows\\system32\\calc.exe</span>`)
35+
.replace(/\{CMD:args\}/g, `<span class="path" title="Command-line arguments.">/arg1 /arg2</span>`)
36+
37+
.replace(/\{PID\}/g, `<span class="path" title="A process ID.">1234</span>`)
38+
x.innerHTML = value;
39+
});
2040
});

0 commit comments

Comments
 (0)