Skip to content

Commit 83fd801

Browse files
committed
refactor
1 parent 03a71b4 commit 83fd801

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
rehype plugin to generate a table of contents from headings in your markdown.
88

9-
You can create the table of contents such below.
9+
You can create the table of contents as follows.
1010

1111
![A table of contents whose each items are anchor link.](assets/toc.png)
1212

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ const searchSameLevelUlElement = (
6868
return rootLiElement
6969
}
7070

71-
if (rootLiElement.children[1] === undefined) {
71+
const childUlElement = assertElementNodeList(rootLiElement.children)[1]
72+
if (childUlElement === undefined) {
7273
return
7374
}
74-
const childUlElement = assertElementNode(rootLiElement.children[1])
7575

7676
return searchSameLevelUlElement(
7777
assertElementNodeList(childUlElement.children),
@@ -87,10 +87,10 @@ const getDeepestLiElement = (rootUlElement: Element[]): Element => {
8787
rootUlElement[rootUlElement.length - 1]
8888
)
8989

90-
if (!rootLiElement.children[1]) {
90+
const olElement = assertElementNodeList(rootLiElement.children)[1]
91+
if (!olElement) {
9192
return rootLiElement
9293
}
93-
const olElement = assertElementNode(rootLiElement.children[1])
9494

9595
return getDeepestLiElement(assertElementNodeList(olElement.children))
9696
}

0 commit comments

Comments
 (0)