Author: sletellier Date: 2010-04-15 12:41:21 +0200 (Thu, 15 Apr 2010) New Revision: 457 Log: #520 : Gestion du commentaire en en-t?\195?\170te avant le titre principale Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java trunk/jrst/src/test/java/org/nuiton/jrst/Compare.java Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2010-04-12 12:14:38 UTC (rev 456) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTLexer.java 2010-04-15 10:41:21 UTC (rev 457) @@ -2102,7 +2102,7 @@ result.addAttribute("xml:space", "preserve"); // first line is part of comment - result.setText(line.substring(2).trim() + "\n"); + result.setText(line.substring(2).trim()); line = in.readLine(); int level = level(line); if (level > 0) { @@ -2121,6 +2121,44 @@ } /** + * .. comment + * + * @return Element + * @throws IOException + */ + public List<Element> peekAllComment() throws IOException { + beginPeek(); + List<Element> result = new ArrayList<Element>(); + String[] lines = in.readWhile("^\\.\\.\\s*.*$"); + if (lines != null) { +// int levelRef = level(line); + for (String line : lines) { + System.out.println(line); + Element comment = DocumentHelper.createElement("comment"); + comment.addAttribute("level", "0"); + comment.addAttribute("xml:space", "preserve"); + + // first line is part of comment + comment.setText(line.substring(2).trim()); + result.add(comment); + +// int level = level(line); +// if (level == levelRef) { +// String[] lines = readBlock(level); +// String text = line.substring(level); +// for (String l : lines) { +// text += "\n" + l.substring(level); +// } +// result.addText(text); +// } + } + } + + endPeek(); + return result; + } + + /** * .. _frungible doodads: http://www.example.org/ * * @return Element Modified: trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2010-04-12 12:14:38 UTC (rev 456) +++ trunk/jrst/src/main/java/org/nuiton/jrst/JRSTReader.java 2010-04-15 10:41:21 UTC (rev 457) @@ -564,7 +564,7 @@ } /** - * @param LinkedList + * @param title * <Element> title, String num * @return Element */ @@ -694,6 +694,12 @@ lexer.remove(); } + // skip blank line + skipBlankLine(lexer); + + // les commentaires + List<Element> comments = lexer.peekAllComment(); + // le titre du doc item = lexer.peekTitle(); if (itemEquals(TITLE, item)) { @@ -800,6 +806,11 @@ // skipBlankLine(lexer); item = lexer.peekDocInfo(); + // Ajout des commentaires + // System.out.println(comment.asXML()); + for (Element comment : comments){ + item.add(composeComment(comment)); + } } // l'abstract du doc @@ -852,7 +863,6 @@ * </p> * * @param lexer - * @param root * @return Element * @throws DocumentException * @throws IOException Modified: trunk/jrst/src/test/java/org/nuiton/jrst/Compare.java =================================================================== --- trunk/jrst/src/test/java/org/nuiton/jrst/Compare.java 2010-04-12 12:14:38 UTC (rev 456) +++ trunk/jrst/src/test/java/org/nuiton/jrst/Compare.java 2010-04-15 10:41:21 UTC (rev 457) @@ -35,6 +35,9 @@ import javax.swing.JSplitPane; import javax.swing.JTextArea; import javax.swing.plaf.FileChooserUI; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.XMLUnit; import org.dom4j.Document; @@ -50,6 +53,9 @@ */ @Ignore public class Compare { + + /** to use log facility, just put in your code: log.info(\"...\"); */ + private static Log log = LogFactory.getLog(Compare.class); static boolean[] bColorRst; @@ -73,7 +79,13 @@ JRSTReader jrst = new JRSTReader(); Document docRst = jrst.read(in); // JRST String cmd = "rst2xml " + source.getPath(); - Process p = Runtime.getRuntime().exec(cmd); // Python + Process p = null; + try { + p = Runtime.getRuntime().exec(cmd); // Python + } catch (IOException eee) { + log.error("You must install python-docutils to compare rst files"); + System.exit(0); + } ThreadRedirection t = new ThreadRedirection(p); t.start(); p.waitFor(); // On attend que le processus ce termine