From 7e4621708226cf1d09a35ebe4bfea894f66af7c5 Mon Sep 17 00:00:00 2001 From: Aysha Date: Fri, 18 Oct 2024 14:25:25 +0530 Subject: [PATCH] fix: section heading links --- wiki/public/js/wiki.js | 12 +++++++----- wiki/wiki/doctype/wiki_page/wiki_page.py | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wiki/public/js/wiki.js b/wiki/public/js/wiki.js index 4069f87f..eb48b1f5 100644 --- a/wiki/public/js/wiki.js +++ b/wiki/public/js/wiki.js @@ -32,7 +32,7 @@ window.Wiki = class Wiki { $(".doc-sidebar,.web-sidebar").on( "click", ".collapsible", - this.toggle_sidebar, + this.toggle_sidebar ); $(".sidebar-item.active") @@ -46,7 +46,7 @@ window.Wiki = class Wiki { set_last_updated_date() { const lastUpdatedDate = frappe.datetime.prettyDate( - $(".user-contributions").data("date"), + $(".user-contributions").data("date") ); $(".user-contributions").append(`last updated ${lastUpdatedDate}`); } @@ -57,7 +57,7 @@ window.Wiki = class Wiki { const src = $(".navbar-brand img").attr("src"); if ( !["{{ light_mode_logo }}", "{{ dark_mode_logo }}", "None", ""].includes( - altSrc, + altSrc ) ) { $(".navbar-brand img").attr("src", altSrc); @@ -96,7 +96,9 @@ window.Wiki = class Wiki { const text = $heading.textContent.trim(); $heading.id = text .replace(/[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]/g, "") - .replace(/[ ]/g, "-"); + .replace(/[ ]/g, "-") + .toLowerCase(); + let id = $heading.id; let $a = $('') .prop("href", "#" + id) @@ -115,7 +117,7 @@ window.Wiki = class Wiki { $("pre code") .parent("pre") .prepend( - ``, + `` ); $(".copy-btn").on("click", function () { diff --git a/wiki/wiki/doctype/wiki_page/wiki_page.py b/wiki/wiki/doctype/wiki_page/wiki_page.py index 9e0b9032..4354c4a5 100644 --- a/wiki/wiki/doctype/wiki_page/wiki_page.py +++ b/wiki/wiki/doctype/wiki_page/wiki_page.py @@ -188,7 +188,7 @@ def calculate_toc_html(self, html): toc_html = "" for heading in headings: title = heading.get_text().strip() - heading_id = re.sub(r"[^a-zA-Z0-9]+", "-", title.lower()) + heading_id = re.sub(r"[^\u00C0-\u1FFF\u2C00-\uD7FF\w\- ]", "", title).replace(" ", "-").lower() heading["id"] = heading_id title = heading.get_text().strip() level = int(heading.name[1])