Index: jrst2/src/java/org/codelutin/jrst/ReStructuredText.java diff -u jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.3 jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.4 --- jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.3 Thu Mar 8 15:05:07 2007 +++ jrst2/src/java/org/codelutin/jrst/ReStructuredText.java Wed Apr 18 16:12:58 2007 @@ -23,10 +23,10 @@ * Created: 27 oct. 06 11:10:30 * * @author poussin - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * - * Last update: $Date: 2007/03/08 15:05:07 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2007/04/18 16:12:58 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -48,7 +48,7 @@ public static final String BULLET_CHAR = "*" + "+" + "-" + "\u2022" + "\u2023" + "\u2043"; public static final String DOCINFO_ITEM = "author|authors|organization|address|contact|version|revision|status|date|copyright"; - + // public static final String ADMONITION = "admonition|caution|danger|error|hint|important|note|tip|warning"; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Root Element //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.8 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.9 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.8 Mon Apr 16 10:09:48 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Wed Apr 18 16:12:58 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Last update: $Date: 2007/04/16 10:09:48 $ + * Last update: $Date: 2007/04/18 16:12:58 $ * by : $Author: sletellier $ */ @@ -40,10 +40,12 @@ import java.io.StringReader; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeSet; import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringEscapeUtils; @@ -186,15 +188,15 @@ * abbreviation * acronym * address (done) - * admonition - * attention + * admonition (done) + * attention (done) * attribution * author (done) - * authors (partialy done) + * authors (done) * block_quote * bullet_list (done) * caption - * caution + * caution (done) * citation * citation_reference * classifier (done) @@ -204,7 +206,7 @@ * contact (done) * container * copyright (done) - * danger + * danger (done) * date (done) * decoration * definition (done) @@ -217,7 +219,7 @@ * emphasis (done) * entry (done) * enumerated_list (done) - * error + * error (done) * field (done) * field_body (done) * field_list (done) @@ -228,9 +230,9 @@ * footnote_reference * generated * header - * hint + * hint (done) * image (done) - * important + * important (done) * inline * label * legend @@ -239,7 +241,7 @@ * list_item (done) * literal (done) * literal_block (done) - * note + * note (done) * option * option_argument * option_group @@ -271,13 +273,13 @@ * term (done) * tgroup (done) * thead (done) - * tip + * tip (done) * title (done) * title_reference * topic * transition (done) * version (done) - * warning + * warning (done) * * * @author poussin @@ -388,6 +390,9 @@ Element item = null; + // skip blank line + skipBlankLine(lexer); + // le titre du doc item = lexer.peekTitle(); if (itemEquals(TITLE, item)) { @@ -397,6 +402,9 @@ title.addAttribute("inline", "true").setText(item.getText()); } + // skip blank line + skipBlankLine(lexer); + // le sous titre du doc item = lexer.peekTitle(); if (itemEquals(TITLE, item)) { @@ -406,14 +414,18 @@ subtitle.addAttribute("inline", "true").setText(item.getText()); } + // skip blank line + skipBlankLine(lexer); + // les infos du doc item = lexer.peekDocInfo(); + Element documentinfo = null; while (itemEquals(DOCINFO, item) || itemEquals(FIELD_LIST, item)) { - if (documentinfo == null) { + if (documentinfo == null) { documentinfo = result.addElement(DOCINFO); } - + skipBlankLine(lexer); if (itemEquals(FIELD_LIST, item)) { Element field = composeFieldItemList(lexer); documentinfo.add(field); @@ -436,10 +448,24 @@ documentinfo.addElement(STATUS).addAttribute("inline", "true").setText(item.getText()); } else if ("copyright".equalsIgnoreCase(item.attributeValue("type"))) { documentinfo.addElement(COPYRIGHT).addAttribute("inline", "true").setText(item.getText()); - } // TODO authors - + } else if ("authors".equalsIgnoreCase(item.attributeValue("type"))){ + Element authors = documentinfo.addElement(AUTHORS); + int t=0; + String line = item.getText(); + for (int i=0;i 0) { entry.addAttribute("morecols", String.valueOf(morecols)); } - // parse entry text in table JRSTReader reader = new JRSTReader(); Document doc = reader.read(new StringReader(text)); Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.9 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.10 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.9 Mon Apr 16 10:09:48 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Wed Apr 18 16:12:58 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ * - * Last update: $Date: 2007/04/16 10:09:48 $ + * Last update: $Date: 2007/04/18 16:12:58 $ * by : $Author: sletellier $ */ @@ -71,7 +71,8 @@ static final public String TITLE_CHAR = "-=-~'`^+:!\"#$%&*,./;|?@\\_[\\]{}<>()"; static final public String DOCINFO_ITEM = "author|authors|organization|address|contact|version|revision|status|date|copyright"; - + public static final String ADMONITION = "admonition|attention|caution|danger|error|hint|important|note|tip|warning"; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Title Elements //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -263,6 +264,7 @@ Element result = null; if (result == null) { result = peekDocInfoItem(); + } if (result == null) { result = peekFieldList(); @@ -280,6 +282,9 @@ public Element peekBodyElement() throws IOException { Element result = null; if (result == null) { + result = peekAdmonition(); + } + if (result == null) { result = peekDirectiveOrReference(); } if (result == null) { @@ -306,14 +311,97 @@ if (result == null) { result = peekBlankLine(); } - if (result == null) { + if (result == null) { result = peekPara(); } + return result; } - /** + private Element peekAdmonition() throws IOException { + beginPeek(); + /*.. Tip:: Roles based on "raw" should clearly indicate their origin, so + they are not mistaken for reStructuredText markup. Using a "raw-" + prefix for role names is recommended.*/ + + /*.. WARNING:: + + The "raw" role is a stop-gap measure allowing the author to bypass + reStructuredText's markup. It is a "power-user" feature that + should not be overused or abused. The use of "raw" ties documents + to specific output formats and makes them less portable. + + If you often need to use "raw"-derived interpreted text roles or + the "raw" directive, that is a sign either of overuse/abuse or that + functionality may be missing from reStructuredText. Please + describe your situation in a message to the Docutils-users_ mailing + list. + + .. _Docutils-users: ../../user/mailing-lists.html#docutils-user*/ + + Element result = null; +// in.skipBlankLines(); + + String line = in.readLine(); + if (line != null) { + String lineTest = line.toLowerCase(); + Pattern pAdmonition = Pattern.compile("^\\.\\.\\s*\\s*("+ADMONITION+")::\\s*(.*)$"); + Matcher matcher = pAdmonition.matcher(lineTest); + if (matcher.matches()) { + boolean admonition=false; + matcher = Pattern.compile(ADMONITION).matcher(lineTest); + matcher.find(); + result = DocumentHelper.createElement("admonition").addAttribute("level", String.valueOf(0)); + if (matcher.group().equals("admonition")){ + admonition=true; + result.addAttribute("type", "admonition"); + String title=line.substring(matcher.end()+2,line.length()); + result.addAttribute("title", title); + + + } + else{ + result.addAttribute("type",matcher.group()); + } + matcher = Pattern.compile(ADMONITION).matcher(lineTest); + matcher.find(); + String firstLine=""; + line=line.trim(); + if (!admonition && matcher.end()+2 < line.length()) + firstLine=line.substring(matcher.end()+2,line.length()); + in.skipBlankLines(); + line = in.readLine(); + int level = level(line); + if (level>0){ + String txt = firstLine.trim() + "\n" + line.trim() + "\n"; + String [] lines = in.readWhile("(^ {"+level+"}.*)|(\\s*)"); + while (lines.length > 0) { + for (String l : lines) { + l=l.trim(); + if (l.matches("\\s*")){ + txt += l + "\n"; + } + else{ + txt += l + "\n"; + } + } + lines = in.readWhile("(^ {"+level+"}.*)|(\\s*)"); + } + + result.setText(txt); + } + else + result.setText(firstLine); + } + } + + endPeek(); + return result; + + } + + /** * Lit les premieres ligne non vide et les retourne, rien n'est modifier par rapport * aux positions dans le fichier. Util pour afficher a l'utilisateur les lignes * qui ont produit une erreur @@ -526,7 +614,7 @@ String line = in.readLine(); // (?i) case inensitive on docinfo item if (line != null && line.matches("^:((?i)"+DOCINFO_ITEM+"):.*$")) { - result = DocumentHelper.createElement(DOCINFO); + result = DocumentHelper.createElement(DOCINFO); result.addAttribute("level", "0"); String infotype = line.substring(1, line.indexOf(":", 1)); @@ -541,11 +629,12 @@ result.addAttribute("type", infotype).addText(text); } - + endPeek(); - + return result; } + public Element peekTable() throws IOException { beginPeek(); @@ -821,14 +910,12 @@ } } } - } tableTmp.add(table[table.length-1]); table = new String[tableTmp.size()]; - for (int i=0;i