Use window.$ to make VSCode syntax highlighting play nice

This commit is contained in:
Francis Lavoie 2023-09-07 14:18:30 -04:00
parent 2639f28a27
commit f10b1e85f1
No known key found for this signature in database
GPG key ID: 0F66EE1687682239
8 changed files with 24 additions and 24 deletions

View file

@ -3,7 +3,7 @@ title: encode (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links to all the subdirectives if a matching anchor tag is found on the page. // We'll add links to all the subdirectives if a matching anchor tag is found on the page.
addLinksToSubdirectives(); addLinksToSubdirectives();
}); });

View file

@ -3,9 +3,9 @@ title: file_server (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// Fix inline browse arg // Fix inline browse arg
$('pre.chroma .s:contains("browse")').first() window.$('pre.chroma .s:contains("browse")').first()
.wrapAll('<span class="k">').parent() .wrapAll('<span class="k">').parent()
.html('<a href="#browse" style="color: inherit;" title="browse">browse</a>') .html('<a href="#browse" style="color: inherit;" title="browse">browse</a>')

View file

@ -3,7 +3,7 @@ title: log (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links to all the subdirectives if a matching anchor tag is found on the page. // We'll add links to all the subdirectives if a matching anchor tag is found on the page.
addLinksToSubdirectives(); addLinksToSubdirectives();
}); });

View file

@ -3,7 +3,7 @@ title: php_fastcgi (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links to all the subdirectives if a matching anchor tag is found on the page. // We'll add links to all the subdirectives if a matching anchor tag is found on the page.
addLinksToSubdirectives(); addLinksToSubdirectives();
}); });

View file

@ -3,19 +3,19 @@ title: reverse_proxy (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// Fix response matchers to render with the right color, // Fix response matchers to render with the right color,
// and link to response matchers section // and link to response matchers section
$('pre.chroma .k:contains("@")') window.$('pre.chroma .k:contains("@")')
.map(function(k, item) { .map(function(k, item) {
let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;'); let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;');
let url = '#' + item.innerText.replace(/_/g, "-"); let url = '#' + item.innerText.replace(/_/g, "-");
$(item).addClass('nd').removeClass('k') window.$(item).addClass('nd').removeClass('k')
$(item).html('<a href="#response-matcher" style="color: inherit;" title="Response matcher">' + text + '</a>'); window.$(item).html(`<a href="#response-matcher" style="color: inherit;" title="Response matcher">${text}</a>`);
}); });
// Fix matcher placeholder // Fix matcher placeholder
$('pre.chroma .k:contains("handle_response")').first().nextAll().slice(0, 3) window.$('pre.chroma .k:contains("handle_response")').first().nextAll().slice(0, 3)
.wrapAll('<span class="nd">').parent() .wrapAll('<span class="nd">').parent()
.html('<a href="#response-matcher" style="color: inherit;" title="Response matcher">[&lt;matcher&gt;]</a>') .html('<a href="#response-matcher" style="color: inherit;" title="Response matcher">[&lt;matcher&gt;]</a>')

View file

@ -3,7 +3,7 @@ title: tls (Caddyfile directive)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links to all the subdirectives if a matching anchor tag is found on the page. // We'll add links to all the subdirectives if a matching anchor tag is found on the page.
addLinksToSubdirectives(); addLinksToSubdirectives();
}); });

View file

@ -3,26 +3,26 @@ title: Request matchers (Caddyfile)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links on the matchers in the code blocks // We'll add links on the matchers in the code blocks
// to their associated anchor tags. // to their associated anchor tags.
let headers = $('article h3').map((i, el) => el.id.replace(/-/g, "_")).toArray(); let headers = $('article h3').map((i, el) => el.id.replace(/-/g, "_")).toArray();
$('pre.chroma .k') window.$('pre.chroma .k')
.filter((k, item) => headers.includes(item.innerText)) .filter((k, item) => headers.includes(item.innerText))
.map(function(k, item) { .map(function(k, item) {
let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;'); let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;');
let url = '#' + item.innerText.replace(/_/g, "-"); let url = '#' + item.innerText.replace(/_/g, "-");
$(item).html('<a href="' + url + '" style="color: inherit;" title="' + text + '">' + text + '</a>'); window.$(item).html(`<a href="${url}" style="color: inherit;" title="${text}">${text}</a>`);
}); });
// Link matcher tokens based on their contents to the syntax section // Link matcher tokens based on their contents to the syntax section
$('pre.chroma .nd') window.$('pre.chroma .nd')
.map(function(k, item) { .map(function(k, item) {
let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;'); let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;');
let anchor = "named-matchers" let anchor = "named-matchers"
if (text == "*") anchor = "wildcard-matchers" if (text == "*") anchor = "wildcard-matchers"
if (text.startsWith('/')) anchor = "path-matchers" if (text.startsWith('/')) anchor = "path-matchers"
$(item).html('<a href="#' + anchor + '" style="color: inherit;" title="Matcher token">' + text + '</a>'); window.$(item).html(`<a href="#${anchor}" style="color: inherit;" title="Matcher token">${text}</a>`);
}); });
}); });
</script> </script>

View file

@ -3,30 +3,30 @@ title: Global options (Caddyfile)
--- ---
<script> <script>
$(function() { window.$(function() {
// We'll add links on the options in the code block at the top // We'll add links on the options in the code block at the top
// to their associated anchor tags. // to their associated anchor tags.
let headers = $('article h5').map((i, el) => el.id.replace(/-/g, "_")).toArray(); let headers = $('article h5').map((i, el) => el.id.replace(/-/g, "_")).toArray();
$('pre.chroma .k') window.$('pre.chroma .k')
.filter((k, item) => headers.includes(item.innerText)) .filter((k, item) => headers.includes(item.innerText))
.map(function(k, item) { .map(function(k, item) {
let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;'); let text = item.innerText.replace(/</g,'&lt;').replace(/>/g,'&gt;');
let url = '#' + item.innerText.replace(/_/g, "-"); let url = '#' + item.innerText.replace(/_/g, "-");
$(item).html('<a href="' + url + '" style="color: inherit;" title="' + text + '">' + text + '</a>'); window.$(item).html(`<a href="${url}" style="color: inherit;" title="${text}">${text}</a>`);
}); });
// Add links on comments to their respective sections // Add links on comments to their respective sections
$('pre.chroma .c1') window.$('pre.chroma .c1')
.filter((k, item) => item.innerText.includes('#')) .filter((k, item) => item.innerText.includes('#'))
.map(function(k, item) { .map(function(k, item) {
let text = item.innerText; let text = item.innerText;
let before = text.slice(0, text.indexOf('#')); let before = text.slice(0, text.indexOf('#')); // the leading whitespace
text = text.slice(text.indexOf('#')); text = text.slice(text.indexOf('#')); // only the comment part
let url = '#' + text.replace(/#/g, '').trim().toLowerCase().replace(/ /g, "-"); let url = '#' + text.replace(/#/g, '').trim().toLowerCase().replace(/ /g, "-");
$(item).html(before + '<a href="' + url + '" style="color: inherit;" title="' + text + '">' + text + '</a>'); window.$(item).html(`${before}<a href="${url}" style="color: inherit;" title="${text}">${text}</a>`);
}); });
// Surgically fix a duplicate link; 'name' appears twice as a link // Surgically fix a duplicate link; 'name' appears twice as a link
// for two different sections, so we change the second to #name-1 // for two different sections, so we change the second to #name-1
$('pre.chroma .line:contains("ca [<id>]")') window.$('pre.chroma .line:contains("ca [<id>]")')
.next() .next()
.find('a:contains("name")') .find('a:contains("name")')
.attr('href', '#name-1'); .attr('href', '#name-1');