Skip to content

Instantly share code, notes, and snippets.

@timaschew
Last active December 19, 2015 00:18
Show Gist options
  • Save timaschew/5867273 to your computer and use it in GitHub Desktop.
Save timaschew/5867273 to your computer and use it in GitHub Desktop.
Confluence Anchor with the Excerp Include Macro: If you a TOC (table of contents) macro within a excerp macro the generated hyperlinks have html achnors. When using the excerp include macro the hyperlinks don't work. There is no HTTP request, only the anchor of the current page will be changed. To fix it, use this script. Can be embeded it at th…
<script type="text/javascript">
jQuery(document).ready(function($) {
//console.log(">>>>>>>>>>>>>>>>>>>>>>>>>> hello from custom toc");
var panel = $("div.panel div.panelHeader");
var panelContent = $("div.panel div.panelContent h2");
if (typeof(panel) != 'undefined' && typeof(panelContent) != 'undefined') {
var pages = $(".panelHeader:first-child");
$(pages).each(function(index, p) {
var pageElem = $(p);
var page = pageElem.text();
//console.log("name: " + page);
var list = pageElem.parent().find("li");
//console.log("liste: " + list);
$(list).each(function(index, e) {
var elem = $(e);
//console.log(index + ': ' + elem);
var link = elem.children().first();
//console.log("link: " + link);
var url = link.attr("href");
if (url.indexOf("#") != -1 ) {
//console.log(">> "+url);
link.attr("href", page + url);
} else {
//console.log("<< "+url);
}
});
});
} else {
//console.log("nothing found");
}
//console.log("<<<<<<<<<<<<<<<<<<<<<<<< bye from custom toc");
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment