Also sanitize dots and parenthesises for slug generation#6904
Merged
Conversation
89b45ec to
b1d8f6e
Compare
b1d8f6e to
43338ea
Compare
There was a problem hiding this comment.
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
Comment on lines
274
to
277
| let id = name.toLowerCase(); | ||
| id = id.replace(/\s+/g, '-'); | ||
| id = id.replace(/\./g, '-'); | ||
| id = id.replace(/[\(\)]/g, ''); |
There was a problem hiding this comment.
Similar slug transformation logic is implemented here. Consider refactoring to use a common helper function for slug generation to ensure consistency across the codebase.
Suggested change
| let id = name.toLowerCase(); | |
| id = id.replace(/\s+/g, '-'); | |
| id = id.replace(/\./g, '-'); | |
| id = id.replace(/[\(\)]/g, ''); | |
| const id = generateSlug(name); |
erwinmombay
approved these changes
Jun 9, 2025
43338ea to
ce3fdfc
Compare
ce3fdfc to
7a4aeb9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.