mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 13:22:26 +02:00
fix(utils): allow any non-boundary characters in Markdown heading ID (#7604)
This commit is contained in:
parent
0114f00069
commit
89e146f596
3 changed files with 61 additions and 4 deletions
|
@ -833,6 +833,53 @@ describe('parseMarkdownHeadingId', () => {
|
|||
id: 'id',
|
||||
});
|
||||
});
|
||||
|
||||
it('does not parse empty id', () => {
|
||||
expect(parseMarkdownHeadingId('## a {#}')).toEqual({
|
||||
text: '## a {#}',
|
||||
id: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('can parse id with more characters', () => {
|
||||
expect(parseMarkdownHeadingId('## a {#你好}')).toEqual({
|
||||
text: '## a',
|
||||
id: '你好',
|
||||
});
|
||||
|
||||
expect(parseMarkdownHeadingId('## a {#2022.1.1}')).toEqual({
|
||||
text: '## a',
|
||||
id: '2022.1.1',
|
||||
});
|
||||
|
||||
expect(parseMarkdownHeadingId('## a {#a#b}')).toEqual({
|
||||
text: '## a',
|
||||
id: 'a#b',
|
||||
});
|
||||
});
|
||||
|
||||
// The actual behavior is unspecified, just need to ensure it stays consistent
|
||||
it('handles unmatched boundaries', () => {
|
||||
expect(parseMarkdownHeadingId('## a {# a {#bcd}')).toEqual({
|
||||
text: '## a {# a',
|
||||
id: 'bcd',
|
||||
});
|
||||
|
||||
expect(parseMarkdownHeadingId('## a {#bcd}}')).toEqual({
|
||||
text: '## a {#bcd}}',
|
||||
id: undefined,
|
||||
});
|
||||
|
||||
expect(parseMarkdownHeadingId('## a {#b{cd}')).toEqual({
|
||||
text: '## a',
|
||||
id: 'b{cd',
|
||||
});
|
||||
|
||||
expect(parseMarkdownHeadingId('## a {#b{#b}')).toEqual({
|
||||
text: '## a {#b',
|
||||
id: 'b',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('writeMarkdownHeadingId', () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue