-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): support dynamic headers and nesting in outline (#1281)
Co-authored-by: fi3ework <[email protected]>
- Loading branch information
Showing
12 changed files
with
368 additions
and
65 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
__tests__/client/theme-default/composables/outline.spec.ts
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,166 @@ | ||
import { describe, test, expect } from 'vitest' | ||
import * as outline from 'client/theme-default/composables/outline' | ||
|
||
describe('client/theme-default/composables/outline', () => { | ||
describe('resolveHeader', () => { | ||
test('levels range', () => { | ||
expect( | ||
outline.resolveHeaders( | ||
[ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1' | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 1', | ||
link: '#h3-1' | ||
} | ||
], | ||
[2, 3] | ||
) | ||
).toEqual([ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1', | ||
children: [ | ||
{ | ||
level: 3, | ||
title: 'h3 - 1', | ||
link: '#h3-1' | ||
} | ||
] | ||
} | ||
]) | ||
}) | ||
|
||
test('specific level', () => { | ||
expect( | ||
outline.resolveHeaders( | ||
[ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1' | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 1', | ||
link: '#h3-1' | ||
} | ||
], | ||
2 | ||
) | ||
).toEqual([ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1' | ||
} | ||
]) | ||
}) | ||
|
||
test('complex deep', () => { | ||
expect( | ||
outline.resolveHeaders( | ||
[ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1' | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 1', | ||
link: '#h3-1' | ||
}, | ||
{ | ||
level: 4, | ||
title: 'h4 - 1', | ||
link: '#h4-1' | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 2', | ||
link: '#h3-2' | ||
}, | ||
{ | ||
level: 4, | ||
title: 'h4 - 2', | ||
link: '#h4-2' | ||
}, | ||
{ | ||
level: 2, | ||
title: 'h2 - 2', | ||
link: '#h2-2' | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 3', | ||
link: '#h3-3' | ||
}, | ||
{ | ||
level: 4, | ||
title: 'h4 - 3', | ||
link: '#h4-3' | ||
} | ||
], | ||
'deep' | ||
) | ||
).toEqual([ | ||
{ | ||
level: 2, | ||
title: 'h2 - 1', | ||
link: '#h2-1', | ||
children: [ | ||
{ | ||
level: 3, | ||
title: 'h3 - 1', | ||
link: '#h3-1', | ||
children: [ | ||
{ | ||
level: 4, | ||
title: 'h4 - 1', | ||
link: '#h4-1' | ||
} | ||
] | ||
}, | ||
{ | ||
level: 3, | ||
title: 'h3 - 2', | ||
link: '#h3-2', | ||
children: [ | ||
{ | ||
level: 4, | ||
title: 'h4 - 2', | ||
link: '#h4-2' | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
level: 2, | ||
title: 'h2 - 2', | ||
link: '#h2-2', | ||
children: [ | ||
{ | ||
level: 3, | ||
title: 'h3 - 3', | ||
link: '#h3-3', | ||
children: [ | ||
{ | ||
level: 4, | ||
title: 'h4 - 3', | ||
link: '#h4-3' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
]) | ||
}) | ||
}) | ||
}) |
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
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
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
Oops, something went wrong.