Skip to content

Commit

Permalink
fix: section heading links
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Oct 18, 2024
1 parent 8aeaa17 commit 7e46217
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions wiki/public/js/wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ window.Wiki = class Wiki {
$(".doc-sidebar,.web-sidebar").on(
"click",
".collapsible",
this.toggle_sidebar,
this.toggle_sidebar
);

$(".sidebar-item.active")
Expand All @@ -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}`);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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 = $('<a class="no-underline">')
.prop("href", "#" + id)
Expand All @@ -115,7 +117,7 @@ window.Wiki = class Wiki {
$("pre code")
.parent("pre")
.prepend(
`<button title="Copy Code" class="btn copy-btn" data-toggle="tooltip"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clipboard"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg></button>`,
`<button title="Copy Code" class="btn copy-btn" data-toggle="tooltip"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-clipboard"><path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"></path><rect x="8" y="2" width="8" height="4" rx="1" ry="1"></rect></svg></button>`
);

$(".copy-btn").on("click", function () {
Expand Down
2 changes: 1 addition & 1 deletion wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 7e46217

Please sign in to comment.