Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.12 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.13 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.12 Mon Apr 23 15:25:55 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Tue Apr 24 14:28:59 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * - * Last update: $Date: 2007/04/23 15:25:55 $ + * Last update: $Date: 2007/04/24 14:28:59 $ * by : $Author: sletellier $ */ @@ -242,12 +242,12 @@ * literal (done) * literal_block (done) * note (done) - * option - * option_argument (dtd) - * option_group - * option_list - * option_list_item - * option_string + * option (done) + * option_argument (done) + * option_group (done) + * option_list (done) + * option_list_item (done) + * option_string (done) * organization (done) * paragraph (done) * pending @@ -594,6 +594,9 @@ lexer.remove(); Element list =composeBlockQuote(lexer, item); parent.add(list); + } else if (itemEquals(OPTION_LIST, item)) { + Element list =composeOptionList(lexer); + parent.add(list); } else { @@ -617,6 +620,39 @@ } + private Element composeOptionList(JRSTLexer lexer) throws Exception { + Element item = lexer.peekOption(); + Element result = DocumentHelper.createElement(OPTION_LIST); + while (itemEquals(OPTION_LIST, item) ) { + lexer.remove(); + Element optionListItem = result.addElement(OPTION_LIST_ITEM); + + + Element optionGroup = optionListItem.addElement(OPTION_GROUP); + + List option = (List)item.selectNodes("option"); + + for (Element e : option){ + Element eOption = optionGroup.addElement(OPTION); + eOption.addElement("option_string").setText(e.attributeValue("option_string")); + if (e.attributeValue("delimiterExiste").equals("true")){ + eOption.addElement("option_argument").addAttribute("delimiter", e.attributeValue("delimiter")).setText(e.attributeValue("option_argument")); + } + + + } + JRSTReader reader = new JRSTReader(); + String text = item.getText(); + Document doc = reader.read(new StringReader(text)); + optionListItem.addElement("description").appendContent(doc.getRootElement()); + + + item = lexer.peekOption(); + } + return result; + } + + private Element composeTopic(JRSTLexer lexer, Element item) throws Exception { Element result = null; result=DocumentHelper.createElement(TOPIC); Index: jrst2/src/java/org/codelutin/jrst/AdvancedReader.java diff -u jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.2 jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.3 --- jrst2/src/java/org/codelutin/jrst/AdvancedReader.java:1.2 Fri Nov 10 14:21:11 2006 +++ jrst2/src/java/org/codelutin/jrst/AdvancedReader.java Tue Apr 24 14:28:59 2007 @@ -23,10 +23,10 @@ * Created: 27 oct. 06 00:24:57 * * @author poussin - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * - * Last update: $Date: 2006/11/10 14:21:11 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2007/04/24 14:28:59 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -135,6 +135,7 @@ return this.lineNumber; } + /** * remove number of char in buffer * @@ -270,7 +271,6 @@ return result.toString(); } } - /** * passe les lignes blanches * @throws IOException Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.12 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.13 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.12 Thu Apr 19 15:54:01 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Tue Apr 24 14:28:59 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.12 $ + * @version $Revision: 1.13 $ * - * Last update: $Date: 2007/04/19 15:54:01 $ + * Last update: $Date: 2007/04/24 14:28:59 $ * by : $Author: sletellier $ */ @@ -91,7 +91,9 @@ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ static final public String TRANSITION = "transition"; - + public static final String SIDEBAR = "sidebar"; + public static final String TOPIC = "topic"; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Body Elements //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -104,6 +106,7 @@ static final public String FIELD_LIST = "field_list"; static final public String DEFINITION_LIST = "definition_list"; static final public String ENUMERATED_LIST = "enumerated_list"; + static final public String OPTION_LIST = "option_list"; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Table Elements @@ -175,7 +178,9 @@ public void remove() throws IOException { in.skip(elementLength); } - + public void removeLine(int l) throws IOException { + // TODO + } private void beginPeek() throws IOException { elementLength = 0; in.mark(); @@ -231,7 +236,27 @@ } return result; } - + public Element peekHeader() throws IOException { + beginPeek(); // TODO elever la ligne pour quelle ne soit pas lu 2 fois + Element result = null; + String[] line = in.readAll(); + if (line != null){ + int i=0; + for (String l : line){ + i++; + if (l.matches("^\\s*.. header:: .*")){ + int level = level(l); + l=l.replaceAll("^\\s*.. header:: ", ""); + result = DocumentHelper.createElement("header").addAttribute("level", String.valueOf(level)); + result.addAttribute("line", ""+i); + result.setText(l); + } + } + } + endPeek(); + return result; + + } /** * Return title or para * @return @@ -283,9 +308,18 @@ public Element peekBodyElement() throws IOException { Element result = null; if (result == null) { + result = peekDoctestBlock(); + } + if (result == null) { result = peekAdmonition(); } if (result == null) { + result = peekSidebar(); + } + if (result == null) { + result = peekTopic(); + } + if (result == null) { result = peekDirectiveOrReference(); } if (result == null) { @@ -295,6 +329,12 @@ result = peekTable(); } if (result == null) { + result = peekLineBlock(); + } + if (result == null) { + result = peekOption(); + } + if (result == null) { result = peekBulletList(); } if (result == null) { @@ -324,6 +364,221 @@ return result; } + public Element peekOption() throws IOException { + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("^\\s*-{1,2}.\\s+.*$")){ + result = DocumentHelper.createElement(OPTION_LIST).addAttribute("level", ""+level(line)); + char delimiter; + do{ + Matcher matcher = Pattern.compile("-{1,2}.+").matcher(line); + matcher.find(); + Element option=result.addElement("option"); + String option_stringTmp=matcher.group(); + matcher = Pattern.compile("^-{1,2}\\w+").matcher(option_stringTmp); + matcher.find(); + String option_string=matcher.group(); + option.addAttribute("option_string", option_string); + delimiter=option_stringTmp.charAt(matcher.end()); + option_stringTmp=option_stringTmp.substring(matcher.end()+1, option_stringTmp.length()); + option.addAttribute("delimiterExiste", "false"); + boolean done=false; + if (delimiter==' '){ + + if (option_stringTmp.charAt(0)==' '){ + done=true; + } + } + + if ((delimiter=='=' || delimiter==' ')&&!done){ + option.addAttribute("delimiterExiste", "true"); + option.addAttribute("delimiter", ""+delimiter); + matcher = Pattern.compile("[ =]\\w+").matcher(option_stringTmp); + String option_argument; + if (matcher.find()){ + option_argument= matcher.group().substring(1, matcher.group().length()); + + option.addAttribute("option_argument", option_argument); + if (option_stringTmp.charAt(option_argument.length())==','){ + delimiter = ','; + line=line.substring(option_string.length()+option_argument.length()+3,line.length()); + + } + else if (option_stringTmp.charAt(option_argument.length())==' ') + done=true; + } + else{ + option_argument=option_stringTmp; + option.addAttribute("option_argument", option_argument); + line = in.readLine(); + result.setText(line.trim()); + } + } + + if (done) + result.setText(option_stringTmp.substring(matcher.end(),option_stringTmp.length()).trim()); + + }while (delimiter==','); + + + + + } + } + + endPeek(); + return result; + } + + private Element peekTopic() throws IOException { + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("^\\.\\.\\s*("+TOPIC+")::\\s*(.*)$")){ + Matcher matcher = Pattern.compile(TOPIC+"::").matcher(line); + matcher.find(); + result = DocumentHelper.createElement(TOPIC).addAttribute("level", ""+level(line)); + String title = line.substring(matcher.end(),line.length()); + result.addAttribute("title",title); + line = in.readLine(); + String txt = joinBlock(readBlock(level(line))); + result.setText(txt); + + } + } + + endPeek(); + return result; + } + + private Element peekSidebar() throws IOException { + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("^\\.\\.\\s*("+SIDEBAR+")::\\s*(.*)$")){ + Matcher matcher = Pattern.compile(SIDEBAR+"::").matcher(line); + matcher.find(); + result = DocumentHelper.createElement(SIDEBAR).addAttribute("level", ""+level(line)); + String title = line.substring(matcher.end(),line.length()); + result.addAttribute("title",title); + line = in.readLine(); + if (line.matches("^\\s+:subtitle:\\s*(.*)$*")){ + matcher = Pattern.compile(":subtitle:\\s*").matcher(line); + matcher.find(); + String subTitle=line.substring(matcher.end(),line.length()); + result.addAttribute("subExiste", "true"); + result.addAttribute("subtitle",subTitle); + line = in.readLine(); + } + else + result.addAttribute("subExiste", "false"); + String txt = joinBlock(readBlock(level(line))); + result.setText(txt); + + } + } + + endPeek(); + return result; + } + + private Element peekLineBlock() throws IOException { + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("\\|\\s.*")){ + String[] linesTmp = readBlock(0); + String[] lines = new String[linesTmp.length+1]; + lines[0]=line; + for (int i=0;i>> sont transforme en >>> + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line != null){ + if (line.matches("^\\s*>>>\\s.*")){ + int level = level(line); + result = DocumentHelper.createElement("doctest_block").addAttribute("level", String.valueOf(level)); + result.addAttribute("xml:space", "preserve"); + line += "\n"+joinBlock(readBlock(level)); + result.setText(line); + } + } + endPeek(); + return result; + } private Element peekBlockQuote() throws IOException { beginPeek(); Element result = null; @@ -367,7 +622,7 @@ String line = in.readLine(); if (line != null) { String lineTest = line.toLowerCase(); - Pattern pAdmonition = Pattern.compile("^\\.\\.\\s*\\s*("+ADMONITION+")::\\s*(.*)$"); + Pattern pAdmonition = Pattern.compile("^\\.\\.\\s*("+ADMONITION+")::\\s*(.*)$"); Matcher matcher = pAdmonition.matcher(lineTest); if (matcher.matches()) { boolean admonition=false;