From 2c6a8a0f9fa1124cf88352ee59de0ff97d1aceb5 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Wed, 16 Sep 2020 19:46:38 -0400 Subject: [PATCH] docs: Add links to matchers and (#84) --- src/resources/js/docs.js | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/resources/js/docs.js b/src/resources/js/docs.js index c99643d..5203b61 100644 --- a/src/resources/js/docs.js +++ b/src/resources/js/docs.js @@ -31,19 +31,34 @@ $(function() { // ensure the inner code block does not produce extra padding $('article > pre:not(.chroma) > code:not(.cmd)').parent().addClass('chroma'); - // Add links to Caddyfile directives in code blocks. + // Add links to Caddyfile directive tokens in code blocks. // See include/docs-head.html for the whitelist bootstrapping logic $('pre.chroma .k') .filter(function (k, item) { - return window.CaddyfileDirectives.includes(item.innerText); + return window.CaddyfileDirectives.includes(item.innerText) + || item.innerText === ''; }) .map(function(k, item) { - $(item).html( - '' - + item.innerText - + '' - ); + let text = item.innerText; + let url = text === '' + ? '/docs/caddyfile/directives' + : '/docs/caddyfile/directives/' + text; + $(item) + .html('') + .find('a') + .text(text); + }); + + // Add links to [] or named matcher tokens in code blocks. + // We can't do it exactly the same as the above block, because + // the matcher text includes <> character which are parsed as HTML + // unless we use text() to change the link text. + $('pre.chroma .nd') + .map(function(k, item) { + let text = item.innerText; + $(item) + .html('') + .find('a') + .text(text); }); }); \ No newline at end of file