Skip to content

Commit

Permalink
Expand heading detection beyond 2 & 3 (and rename typoed file)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Nov 21, 2024
1 parent b1e650a commit c9836ca
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HeadingGroup } from '@/lib/mdx/utils/extract-tittles';
import type { HeadingGroup } from '@/lib/mdx/utils/extract-titles';

export interface TableContentSubitem {
text: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export function getHeadings(source: string): HeadingGroup[] {

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

return { text, level };
});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mdx/utils/get-heading-links.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path';

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

Expand Down
2 changes: 1 addition & 1 deletion src/lib/mdx/utils/group-by-level.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HeadingGroup } from './extract-tittles';
import type { HeadingGroup } from './extract-titles';

export interface HeadingGroupWithSubItems extends HeadingGroup {
subItems: HeadingGroup[];
Expand Down

0 comments on commit c9836ca

Please sign in to comment.