Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.23 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.24 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.23 Mon May 14 14:41:07 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Tue May 15 10:46:49 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.23 $ + * @version $Revision: 1.24 $ * - * Last update: $Date: 2007/05/14 14:41:07 $ + * Last update: $Date: 2007/05/15 10:46:49 $ * by : $Author: sletellier $ */ @@ -57,6 +57,7 @@ import org.codelutin.jrst.directive.ContentDirective; import org.codelutin.jrst.directive.DateDirective; import org.codelutin.jrst.directive.ImageDirective; +import org.codelutin.jrst.directive.SectnumDirective; import org.codelutin.util.StringUtil; import org.dom4j.Document; import org.dom4j.DocumentException; @@ -299,7 +300,7 @@ static protected Map defaultDirectives = null; protected Map directives = new HashMap(); - + private boolean sectnum = false; private int idMax = 0; private int symbolMax = 0; private int symbolMaxRef = 0; @@ -316,6 +317,7 @@ defaultDirectives.put(DATE, new DateDirective()); defaultDirectives.put("time", new DateDirective()); defaultDirectives.put("contents", new ContentDirective()); + defaultDirectives.put("sectnum", new SectnumDirective()); // TODO put here all other directive } @@ -382,11 +384,6 @@ done=true; } } - if (e.getName().equals("title") && done){ - Element t = eTitle.getFirst(); - e.addAttribute("refid", t.attributeValue("refid")); - eTitle.removeFirst(); - } if ("true".equalsIgnoreCase(e.attributeValue("inline"))) { e.addAttribute("inline", null); try { @@ -445,29 +442,47 @@ e.addAttribute("id", value); e.addAttribute("name",value); result.addElement("title").setText(titleValue); - result.add(composeLineContent(title)); + result.add(composeLineContent(title, "")); e.setText(""); e.appendContent(result); } - private Element composeLineContent(LinkedList title) { + private Element composeLineContent(LinkedList title, String num) { Element result = DocumentHelper.createElement(BULLET_LIST); + if (sectnum) + result.addAttribute("class", "auto-toc"); Element item = null; + int cnt=0; while (!title.isEmpty()){ + boolean done=false; Element e = title.getFirst(); int level = Integer.parseInt(e.attributeValue("level")); LinkedList child = new LinkedList(); if (level==0 && !done){ + cnt++; title.removeFirst(); item = result.addElement(LIST_ITEM); Element para = item.addElement(PARAGRAPH); Element reference = para.addElement(REFERENCE); String text=e.getText(); - reference.addAttribute("id", e.attributeValue("refid")); + String id= e.attributeValue("refid"); + reference.addAttribute("id",id); reference.addAttribute("refid", text.replaceAll("\\W+", " ").trim().toLowerCase().replaceAll("\\W+", "-")); reference.addAttribute("inline","true"); + if (sectnum){ + Element generated = reference.addElement("generated").addAttribute("class", "sectnum"); + generated.setText(num+cnt+" "); + for (int i=0;i0 && !done); - + String numTmp=""; + if (sectnum) + numTmp=num+cnt+"."; if (item!=null) - item.add(composeLineContent(child)); // Appel recursif + item.add(composeLineContent(child,numTmp)); // Appel recursif else - result.add(composeLineContent(child)); // Appel recursif + result.add(composeLineContent(child,numTmp)); // Appel recursif } } return result; @@ -769,11 +786,9 @@ BufferedReader bf = new BufferedReader(reader); String line=""; String lineTmp= bf.readLine(); - //bf.skip(line.length()); while (lineTmp != null){ line += '\n'+lineTmp; lineTmp = bf.readLine(); - //bf.skip(line.length()); } result.setText(line); } @@ -1097,6 +1112,8 @@ private Node composeDirective(Element item) { Node result = item; String type = item.attributeValue(JRSTLexer.DIRECTIVE_TYPE); + if (type.equals("sectnum")) + sectnum=true; JRSTDirective directive = getDirective(type); if (directive == null) { directive = getDefaultDirective(type);