diff --git a/kit/preprocessors/hashInCode.js b/kit/preprocessors/hashInCode.js index 9e666725..e578769b 100644 --- a/kit/preprocessors/hashInCode.js +++ b/kit/preprocessors/hashInCode.js @@ -6,12 +6,17 @@ export const hashInCodePreprocess = { markup: async ({ content }) => { const REGEX_CODE_BLOCK = /```.*?```/gs; const REGEX_INLINE_CODE = /`.*?`/g; + const REGEX_INLINE_EXCEPTION = /(?!.*HF_DOC_BODY_START)`.*?`(? { return codeContent.replaceAll("#", "#"); }); content = await replaceAsync(content, REGEX_INLINE_CODE, async (codeContent) => { return codeContent.replaceAll("#", "#"); }); + // Exception: we don't want to replace `#` in code blocks that are part of the doc body, as they may be hrefs + content = await replaceAsync(content, REGEX_INLINE_EXCEPTION, async (codeContent) => { + return codeContent.replaceAll("#", "#"); + }); return { code: content }; }, };