Page Index
Last modified by Vincent Massol on 2021/03/18 11:28
Creates an index of the headings of the current document |
Type | Snippet |
Category | |
Developed by | xwiki:XWiki.FriedemannLoew |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
#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];
}
}
%>
<%
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];
}
}
%>