diff --git a/docusaurus.config.js b/docusaurus.config.js index 45bd5b731..98dcd8bf5 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -303,6 +303,29 @@ module.exports = { if (node.title) return `[${node.title}](${url})`; return url; }, + code: (node) => { + const apiMethods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS']; + const splitValue = node.value.trim().split('\n'); + + splitValue.forEach((item, i, valuesArray) => { + if (!apiMethods.some((method) => item.startsWith(method))) { + // try to parse as URL, if successful, prefix with absolute URL + try { + const parsedUrl = parse(valuesArray[i + 1]); + if (isInternal(parsedUrl) && parsedUrl.pathname) { + valuesArray[i + 1] = `${config.absoluteUrl}${parsedUrl.pathname}`; + } + } catch { + // do nothing, leave the line as is + } + } + }); + + if (apiMethods.some((method) => node.value.trim().startsWith(method))) { + node.lang = node.lang.toLowerCase(); + } + return `\n\`\`\`${node.lang || ''}\n${node.value}\n\`\`\`\n`; + }, }, }, excludeRoutes: [