-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: wrong sidebar slugs and anchor link at content (close: #645)
Background: we want to support headers badge in headers (#540), it make us be able to write HTML tags at the end of the header. but it shouldn't be hidden at the title at the sidebar, and
- Loading branch information
Showing
4 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Md } from './util' | ||
import anchor from 'markdown-it-anchor' | ||
import slugify from '@/markdown/slugify.js' | ||
|
||
const mdS = Md().use(anchor, { | ||
slugify, | ||
permalink: true, | ||
permalinkBefore: true, | ||
permalinkSymbol: '#' | ||
}) | ||
|
||
const slugifyAsserts = { | ||
/* markdown: id */ | ||
'# a b': 'a-b', | ||
'# a-b': 'a-b', | ||
'# `<a>`': 'a', | ||
'# `<a>`b': 'a-b', | ||
'# `<a>` b': 'a-b' | ||
} | ||
|
||
describe('slugify', () => { | ||
test('should convert headers correctly', () => { | ||
for (const input in slugifyAsserts) { | ||
const output = mdS.render(input) | ||
expect(getHeading(output)).toBe(slugifyAsserts[input]) | ||
} | ||
}) | ||
}) | ||
|
||
function getHeading (output) { | ||
return output.match(/id=\\?"([^"]*)\\?"/)[1] | ||
} |
This file contains 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