Created
February 7, 2024 10:31
-
-
Save tdalon/6149f8baeed97a0206e7753ff59ec8d5 to your computer and use it in GitHub Desktop.
Confluence Bookmarklets for Numbered Headings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addIndex() { | |
var indices = []; | |
jQuery(".ak-editor-content-area .ProseMirror").find("h1,h2,h3,h4,h5,h6").each(function(i,e) { | |
var hIndex = parseInt(this.nodeName.substring(1)) - 1; | |
if (indices.length - 1 > hIndex) { | |
indices= indices.slice(0, hIndex + 1 ); | |
} | |
if (indices[hIndex] == undefined) { | |
indices[hIndex] = 0; | |
} | |
if (jQuery(this).html().toLowerCase() !== "table of contents"){ | |
indices[hIndex]++; | |
jQuery(this).html(indices.join(".")+". " + removeNo(jQuery(this).html())); | |
} | |
}); | |
} | |
function removeNo(str) { | |
let newstr = str.trim(); | |
newstr = newstr.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g,' '); | |
if(IsNumeric(newstr.substring(0,newstr.indexOf(' ')))){ | |
return newstr.substring(newstr.indexOf(' ')+1).trim(); | |
} | |
return newstr; | |
} | |
function IsNumeric(num) { | |
num = num.split('.').join(""); | |
return (num >=0 || num < 0); | |
} | |
addIndex(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeIndex() { | |
var indices = []; | |
jQuery(".ak-editor-content-area .ProseMirror").find("h1,h2,h3,h4,h5,h6").each(function(i,e) { | |
jQuery(this).html(removeNo(jQuery(this).html())); | |
}); | |
} | |
function removeNo(str) { | |
let newstr = str.trim(); | |
newstr = newstr.replace(/[\u00A0\u1680\u180e\u2000-\u2009\u200a\u200b\u202f\u205f\u3000]/g,' '); | |
if(IsNumeric(newstr.substring(0,newstr.indexOf(' ')))){ | |
return newstr.substring(newstr.indexOf(' ')+1).trim(); | |
} | |
return newstr; | |
} | |
function IsNumeric(num) { | |
num = num.split('.').join(""); | |
return (num >=0 || num < 0); | |
} | |
removeIndex(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See details https://tdalon.blogspot.com/2024/02/confluence-numbered-headings.html