Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down