inside
// the ; this line finds those and adds a .chroma class
// to the outer pre element, and our CSS file has a style to
// ensure the inner code block does not produce extra padding
$('article > pre:not(.chroma) > code:not(.cmd)').parent().addClass('chroma');
// Add links to Caddyfile directive tokens in code blocks.
// See include/docs-head.html for the whitelist bootstrapping logic
$('pre.chroma .k')
.filter((k, item) =>
window.CaddyfileDirectives.includes(item.innerText)
|| item.innerText === ''
)
.map(function(k, item) {
let text = item.innerText;
let url = text === ''
? '/docs/caddyfile/directives'
: '/docs/caddyfile/directives/' + text;
text = text.replace(//g,'>');
$(item).html('' + text + '');
});
// Add links to [] or named matcher tokens in code blocks.
// The matcher text includes <> characters which are parsed as HTML,
// so we must use text() to change the link text.
$('pre.chroma .nd')
.map(function(k, item) {
let text = item.innerText.replace(//g,'>');
$(item).html('' + text + '');
});
// Add links to [] or named matcher tokens in code blocks.
// The matcher text includes <> characters which are parsed as HTML,
// so we must use text() to change the link text.
$('pre.chroma .s:contains("")')
.add('pre.chroma .s:contains("")')
.map(function(k, /** @type { HTMLElement } */ item) {
const anchor = document.createElement("a");
anchor.href = "/docs/caddyfile/response-matchers#syntax";
anchor.style.color = "inherit";
anchor.title = "Response matcher token";
item.replaceWith(anchor);
anchor.appendChild(item);
});
// Wrap all tables in a div so we can apply overflow-x: scroll
$('table').wrap('');
});
// addLinkaddLinksToSubdirectivessToAnchors finds all the ID anchors
// in the article, and turns any directive or subdirective span into
// links that have an ID on the page. This is opt-in for each page,
// because it's not necessary to run everywhere.
function addLinksToSubdirectives() {
let anchors = $('article *[id]').map((i, el) => el.id).toArray();
$('pre.chroma .k')
.filter((k, item) => anchors.includes(item.innerText))
.map(function(k, item) {
let text = item.innerText.replace(//g,'>');
let url = '#' + item.innerText;
$(item).html('' + text + '');
});
}
function stripScheme(url) {
return url.substring(url.indexOf("://")+3);
}
// splitTypeName splits a fully qualified type name into
// its package path and type name components, for example:
// "github.com/foo/bar.Type" => "github.com/foo/bar" and "Type".
function splitTypeName(fqtn) {
let lastDotPos = fqtn.lastIndexOf('.');
let pkg = fqtn.substr(0, lastDotPos);
let typeName = fqtn.substr(lastDotPos+1);
return {pkg: pkg, typeName: typeName};
}