Skip to content

Commit da2f10c

Browse files
committed
Expand heading detection beyond 2 & 3 (and rename typoed file)
1 parent fa044df commit da2f10c

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

src/components/modules/table-content/table-content.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { HeadingGroup } from '@/lib/mdx/utils/extract-tittles';
1+
import type { HeadingGroup } from '@/lib/mdx/utils/extract-titles';
22

33
export interface TableContentSubitem {
44
text: string;

src/lib/mdx/utils/extract-tittles.ts renamed to src/lib/mdx/utils/extract-titles.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ export function getHeadings(source: string): HeadingGroup[] {
1515

1616
return headingLines.map(raw => {
1717
const text = raw.replace(/^###*\s/, '');
18-
const level = raw.slice(0, 3) === '###' ? 3 : 2;
18+
const level = (
19+
raw.split('').findIndex(char => char !== '#') || 6
20+
) as HeadingGroup['level'];
1921

2022
return { text, level };
2123
});

src/lib/mdx/utils/get-heading-links.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'path';
22

3-
import { extractHeadingsFromMDX } from './extract-tittles';
3+
import { extractHeadingsFromMDX } from './extract-titles';
44
import { groupByLevel } from './group-by-level';
55
import { formatLinks } from './groups-to-links';
66

src/lib/mdx/utils/group-by-level.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { HeadingGroup } from './extract-tittles';
1+
import type { HeadingGroup } from './extract-titles';
22

33
export interface HeadingGroupWithSubItems extends HeadingGroup {
44
subItems: HeadingGroup[];

0 commit comments

Comments
 (0)