Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autodoc parameter hrefs #516

Merged
merged 1 commit into from
Sep 13, 2024
Merged
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
5 changes: 5 additions & 0 deletions kit/preprocessors/hashInCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`.*?`(?<!HF_DOC_BODY_END.*)/gs;
Copy link
Member Author

@gante gante Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic tl;dr: find all inline code blocks (`.*?`) between HF_DOC_BODY_START and HF_DOC_BODY_END, the autodocs delimiters

content = await replaceAsync(content, REGEX_CODE_BLOCK, async (codeContent) => {
return codeContent.replaceAll("#", "&amp;num;");
});
content = await replaceAsync(content, REGEX_INLINE_CODE, async (codeContent) => {
return codeContent.replaceAll("#", "&amp;num;");
});
// 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("&amp;num;", "#");
});
return { code: content };
},
};
Loading