Page Index

Last modified by Vincent Massol on 2021/03/18 11:28

cogCreates an index of the headings of the current document
TypeSnippet
Category
Developed by

xwiki:XWiki.FriedemannLoew

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

There's now a TOC Macro.

#set($plaincontent = $doc.getContent())

<%
vcontext=context.get("vcontext");
plaincontent=vcontext.get("plaincontent");
backSubString = plaincontent;
i=0;
sternchen=["*", "**", "***", "****", "*****", "******"]
while (backSubString.matches("(?s).*\\n1(\\.1)* .*")){
 level=1;
 backSubString = backSubString.split("\\n1", 2)[1];
 while (backSubString.matches("(?s)\\.1.*")){
   level++;
   backSubString=backSubString.split("\\.1", 2)[1];
  }
 if (! backSubString.matches("(?s)\\..*")) { // is not a List
   heading=backSubString.split("[\\n\\r]", 2)[0];
   encHeading=URLEncoder.encode(heading, "UTF-8");
   encHeading=encHeading.replaceAll("[+%-\\.]", "");
   println(sternchen[level-1] + " ["+heading+">#H"+encHeading+"]");
   i++;
  } else {
   backSubString=backSubString.split("\\.(1\\.)*", 2)[1];
  }
}
%>
Tags:
     

Get Connected