-
Notifications
You must be signed in to change notification settings - Fork 45
fix: preserve underscores in slug generation for anchor link compatibility #733
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
Changes from 1 commit
0d8152e
2f8127f
edea511
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you remove redundant tests? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,8 @@ describe('slug', () => { | |
| }); | ||
|
|
||
| describe('special character to hyphen replacement', () => { | ||
| it('replaces underscores with hyphens', () => { | ||
| assert.strictEqual(slug('foo_bar', identity), 'foo-bar'); | ||
| it('preserves underscores (does not replace with hyphens)', () => { | ||
| assert.strictEqual(slug('foo_bar', identity), 'foo_bar'); | ||
| }); | ||
|
||
|
|
||
| it('replaces forward slashes with hyphens', () => { | ||
|
|
@@ -46,6 +46,24 @@ describe('slug', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('underscore preservation (anchor link compatibility)', () => { | ||
| it('preserves leading underscores so __dirname slug matches #__dirname anchor', () => { | ||
| assert.strictEqual(slug('__dirname', identity), '__dirname'); | ||
| }); | ||
|
|
||
| it('preserves leading underscores so __filename slug matches #__filename anchor', () => { | ||
| assert.strictEqual(slug('__filename', identity), '__filename'); | ||
| }); | ||
|
|
||
| it('preserves underscores within names', () => { | ||
| assert.strictEqual(slug('child_process', identity), 'child_process'); | ||
| }); | ||
|
|
||
| it('preserves mixed underscores and other characters', () => { | ||
| assert.strictEqual(slug('foo_bar:baz', identity), 'foo_bar-baz'); | ||
| }); | ||
| }); | ||
avivkeller marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| describe('leading hyphen removal', () => { | ||
| it('removes a single leading hyphen', () => { | ||
| assert.strictEqual(slug('-foo', identity), 'foo'); | ||
|
|
@@ -85,13 +103,21 @@ describe('slug', () => { | |
| assert.strictEqual(slug('Hello World'), 'hello-world'); | ||
| }); | ||
|
|
||
| it('converts underscored names to hyphenated slugs', () => { | ||
| assert.strictEqual(slug('child_process'), 'child-process'); | ||
| it('preserves underscores in names (no hyphenation)', () => { | ||
| assert.strictEqual(slug('child_process'), 'child_process'); | ||
| }); | ||
|
|
||
| it('handles titles with no special characters', () => { | ||
| assert.strictEqual(slug('stability index'), 'stability-index'); | ||
| }); | ||
|
|
||
| it('generates correct slug for __dirname', () => { | ||
| assert.strictEqual(slug('__dirname'), '__dirname'); | ||
| }); | ||
|
|
||
| it('generates correct slug for __filename', () => { | ||
| assert.strictEqual(slug('__filename'), '__filename'); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
||
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.