Skip to content

Commit

Permalink
fix: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
fbuireu committed Sep 26, 2024
1 parent 8b21ee4 commit 1c2c3b1
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ const HEADINGS_REGEX = /<h([1-6])>(.*?)<\/h\1>/g;

export function generateTableOfContents(html: string): TableOfContentsReturnType {
const items: TableOfContentsReturnType = [];
const matches = html.matchAll(HEADINGS_REGEX);
const headings = html.matchAll(HEADINGS_REGEX);

for (const match of matches) {
const level = Number.parseInt(match[1]);
const heading = match[2];
const id = slugify(heading);
for (const heading of headings) {
const level = Number.parseInt(heading[1]);
const text = heading[2];
const id = slugify(text);

items.push({ id, heading, level });
items.push({ id, heading: text, level });
}

return items;
Expand Down

0 comments on commit 1c2c3b1

Please sign in to comment.