Skip to content

Commit

Permalink
Add page numbers to TOC in paged mode
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgio committed Aug 8, 2024
1 parent fceb9d3 commit cf1306a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,22 @@ class QuarkdownHtmlNodeRenderer(context: Context) : BaseHtmlNodeRenderer(context
+visit(tableOfContentsItemsToList(node.items))
}

override fun visit(node: TableOfContents.Item) =
buildTag("a") {
+node.text
override fun visit(node: TableOfContents.Item): CharSequence {
val link =
buildTag("a") {
+node.text

if (node.children.isNotEmpty()) {
+visit(tableOfContentsItemsToList(node.subItems))
// Link to the target anchor (e.g. a heading).
attribute("href", "#" + HtmlIdentifierProvider.of(this@QuarkdownHtmlNodeRenderer).getId(node.target))
}

// Link to the target anchor (e.g. a heading).
attribute("href", "#" + HtmlIdentifierProvider.of(this@QuarkdownHtmlNodeRenderer).getId(node.target))
// Recursively render sub-items.
return if (node.subItems.isNotEmpty()) {
link + visit(tableOfContentsItemsToList(node.subItems))
} else {
link
}
}

// Inline

Expand Down
8 changes: 7 additions & 1 deletion core/src/main/resources/render/theme/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ h1, h2, h3, h4, h5, h6 {

.stack > p, .clip > p {
margin: 0;
}
}

.table-of-contents li a::after {
/* TOC page counter on supported targets */
content: target-counter(attr(href), page);
float: right;
}

0 comments on commit cf1306a

Please sign in to comment.