Skip to content

Commit 4a686aa

Browse files
authored
Merge pull request #322 from pratikb64/add-title-toc
feat: add post title in toc
2 parents 4b90f3e + 581f762 commit 4a686aa

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Diff for: wiki/public/js/wiki.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ window.Wiki = class Wiki {
8888
}
8989

9090
add_link_to_headings() {
91-
$(".wiki-content")
91+
$(".from-markdown")
9292
.not(".revision-content")
93-
.find("h2, h3, h4, h5, h6")
93+
.find("h1, h2, h3, h4, h5, h6")
9494
.each((i, $heading) => {
9595
const text = $heading.textContent.trim();
9696
$heading.id = text

Diff for: wiki/wiki/doctype/wiki_page/wiki_page.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ def calculate_toc_html(self, html):
183183
from bs4 import BeautifulSoup
184184

185185
soup = BeautifulSoup(html, "html.parser")
186-
headings = soup.find_all(["h2", "h3", "h4", "h5", "h6"])
187-
188-
toc_html = ""
186+
headings = soup.find_all(["h1", "h2", "h3", "h4", "h5", "h6"])
187+
# Add the title as the first entry in the TOC
188+
toc_html = f"<li><a style='padding-left: 1rem' href='#{re.sub(r'[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]', '', self.title).replace(' ', '-').lower()}'>{self.title}</a></li>"
189189
for heading in headings:
190190
title = heading.get_text().strip()
191191
heading_id = re.sub(r"[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]", "", title).replace(" ", "-").lower()

0 commit comments

Comments
 (0)