-
Notifications
You must be signed in to change notification settings - Fork 692
Also sanitize dots and parenthesises for slug generation #6904
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
Conversation
89b45ec to
b1d8f6e
Compare
b1d8f6e to
43338ea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances slug generation by sanitizing dots and parentheses in title anchors, ensuring consistency with GitHub's rendering.
- Updates the sanitization logic in generalReferenceLinker.js to remove dots and parentheses.
- Adds a test case in CodeSection.test.js for verifying the new heading escaping behavior.
- Modifies CodeSection.js to apply consistent slug sanitization.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| platform/lib/tools/generalReferenceLinker.js | Updated slug sanitization to remove dots and parentheses |
| platform/lib/samples/CodeSection.test.js | Added test to verify heading sanitation |
| platform/lib/samples/CodeSection.js | Updated heading id generation with enhanced sanitization logic |
Comments suppressed due to low confidence (1)
platform/lib/tools/generalReferenceLinker.js:247
- The slug sanitization logic here is similar to what is used elsewhere in the project. Consider extracting this logic into a shared utility function to promote consistency and reduce duplication.
const sectionId = section !== null ? section[0].replace(/\s/g, '').replace(/\./g, '-').replace(/[\(\)]/g, '') : '';
platform/lib/samples/CodeSection.js
Outdated
| let id = name.toLowerCase(); | ||
| id = id.replace(/\s+/g, '-'); | ||
| id = id.replace(/\./g, '-'); | ||
| id = id.replace(/[\(\)]/g, ''); |
Copilot
AI
Jun 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar slug transformation logic is implemented here. Consider refactoring to use a common helper function for slug generation to ensure consistency across the codebase.
| let id = name.toLowerCase(); | |
| id = id.replace(/\s+/g, '-'); | |
| id = id.replace(/\./g, '-'); | |
| id = id.replace(/[\(\)]/g, ''); | |
| const id = generateSlug(name); |
43338ea to
ce3fdfc
Compare
ce3fdfc to
7a4aeb9
Compare
This is to address an issue that the titles' anchors are not sanitized properly, leaving dots and parenthesises there. This is not consistent with how github renders its page. We hereby remove them the same way.
I elected to use a new function name, instead of rewriting the
slugfunction, to ensure that we do not accidentally fallback to the system default function.