Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.7 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.8 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.7 Thu Mar 8 15:05:07 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Mon Apr 16 10:09:48 2007 @@ -23,10 +23,10 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.7 $ + * @version $Revision: 1.8 $ * - * Last update: $Date: 2007/03/08 15:05:07 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2007/04/16 10:09:48 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -265,7 +265,7 @@ * subtitle (done) * superscript * system_message - * table (done, only complexe table in lexer) + * table (done) * target * tbody (done) * term (done) @@ -528,6 +528,12 @@ } } item = lexer.peekTitleOrBodyElement(); + + // Pour afficher le "PseudoXML" + + /*if (item!=null) + System.out.println(item.asXML());*/ + } return parent; } @@ -573,6 +579,7 @@ * @return */ private Element composeTable(JRSTLexer lexer, Element item) throws Exception { + Element result = DocumentHelper.createElement(TABLE); int tableWidth = Integer.parseInt(item.attributeValue(JRSTLexer.TABLE_WIDTH)); Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.8 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.9 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.8 Tue Apr 10 16:48:05 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Mon Apr 16 10:09:48 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Last update: $Date: 2007/04/10 16:48:05 $ + * Last update: $Date: 2007/04/16 10:09:48 $ * by : $Author: sletellier $ */ @@ -34,6 +34,8 @@ import java.io.IOException; import java.io.Reader; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -577,6 +579,7 @@ Element row = DocumentHelper.createElement(ROW); String [] table = in.readUntilBlank(); + boolean done = false; for (String l : table) { done =false; @@ -726,41 +729,170 @@ // line += "\n" + joinBlock(table, "\n", false); // // result.addText(line); - } else if (line.matches("^\\s*(=+ +)+=+\\s*$")) { // simple table - // TODO now we take table as LITERAL_BLOCK, but in near - // futur we must parse correctly TABLE (show JRSTGenerator and JRSTReader too) - + } else if (line.matches("^\\s*(=+ +)+=+\\s*$")) { + // Les donnees de la table peuvent depasser de celle-ci + /* + ===== ===== ====== + Inputs Output + ------------ ------ + A B A or B + ===== ===== ====== + False False Second column of row 1. + True False Second column of row 2. + + True 2 - Second column of row 3. + + - Second item in bullet + list (row 3, column 2). + ============ ====== + */ - // dans les tables simples il peut y avoir des lignes blanches au - // milieu. Mais la premiere et la derniere lignes sont identiques - // TODO cela ne parse pas la table, il faut le faire - String first = line; - - result = DocumentHelper.createElement(LITERAL_BLOCK); - result.addAttribute("level", String.valueOf(level(line))); - - String [] table = in.readUntil(first); - line += "\n" + joinBlock(table, "\n", false); - String next = in.readLine(); - line += "\n" + next; - - next = in.readLine(); - if (line != null) { - if (next.matches("\\s*")) { - // no header - in.unread(next, true); - } else { - // read body table - table = in.readUntil(first); - line += "\n" + joinBlock(table, "\n", false); - next = in.readLine(); - line += "\n" + next; - } + result = DocumentHelper.createElement(TABLE); + line = line.trim(); + Pattern pBordersEquals = Pattern.compile("^\\s*(=+ +)+=+\\s*$"); // Separation = + Pattern pBordersTiret = Pattern.compile("^\\s*(-+ +)+-+\\s*$"); // Separation - + Pattern pBorders = Pattern.compile("^\\s*([=-]+ +)+[=-]+\\s*$"); // = ou - + String [] table = in.readUntilBlank(); // Recuperation de la table + + int tableWidth=line.length(); + int nbSeparations=0; + for (String l : table){ + if(l.length()>tableWidth)tableWidth=l.length(); // Determination de la longueur max + matcher = pBordersEquals.matcher(l); + if(matcher.matches())nbSeparations++; + } - result.addText(line); + // Header if the table contains 3 equals separations + result.addAttribute(TABLE_HEADER,""+(nbSeparations==2)); + int level = level(line); + result.addAttribute("level", String.valueOf(level)); + result.addAttribute(TABLE_WIDTH, String.valueOf(tableWidth+1)); + Element row = DocumentHelper.createElement(ROW); + // Determination of the columns positions + List columns = new LinkedList(); + matcher = Pattern.compile("=+\\s+").matcher(line); + for (int cellNumber=0; matcher.find(); cellNumber++) { + columns.add(matcher.end()); + } + columns.add(tableWidth); + + // Traitement du tbl + /* + ===== ===== ====== + Inputs Output + ------------ ------ + A B A or B + ===== ===== ====== + False False Second column of row 1. + True False Second column of row 2. + + True 2 - Second column of row 3. + + - Second item in bullet + list (row 3, column 2). + ============ ====== + devient l'équivalent : + ===== ===== ====== + Inputs Output + ------------ ------ + A B A or B + ===== ===== ====== + False False Second column of row 1. + ----- ----- ------ + True False Second column of row 2. + ----- ----- ------ + True 2 - Second column of row 3. + - Second item in bullet + list (row 3, column 2). + ============ ====== + */ + String lineRef = line.replace('=','-'); + Matcher matcher2; + List tableTmp = new LinkedList(); + + for (int i=0;i