Page Index Snippet

Creates an index of the headings of the current document. Headings of different levels will have different indents.

There's a similar, maybe even better behaviour if you use the TocMacro

Code

#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];
  }	
}
%>

Version 2.1 last modified by VincentMassol on 09/12/2007 at 14:39

Comments 0

No comments for this document

Attachments 0

No attachments for this document

Creator: FriedemannLoew on 2007/02/27 17:35
This wiki is licensed under a Creative Commons license
1.4.1.10194