Index: jrst2/src/java/org/codelutin/jrst/ReStructuredText.java diff -u jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.14 jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.15 --- jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.14 Thu May 24 15:03:17 2007 +++ jrst2/src/java/org/codelutin/jrst/ReStructuredText.java Wed May 30 19:20:34 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 11:10:30 * * @author poussin - * @version $Revision: 1.14 $ + * @version $Revision: 1.15 $ * - * Last update: $Date: 2007/05/24 15:03:17 $ + * Last update: $Date: 2007/05/30 19:20:34 $ * by : $Author: sletellier $ */ @@ -164,7 +164,7 @@ public static final String STRONG = "strong"; public static final String LITERAL = "literal"; public static final String REFERENCE = "reference"; - public static final String FOOTNOTE_REFERENCE = "footnote-reference"; + public static final String FOOTNOTE_REFERENCE = "footnote_reference"; public static final String CITATION_REFERENCE = "citation_reference"; public static final String SUBSTITUTION_REFERENCE = "substitution_reference"; public static final String TITLE_REFERENCE = "title_reference"; @@ -181,7 +181,7 @@ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public static final Pattern REGEX_EMPHASIS = Pattern.compile("\\*([^*(\\]_.+\\[)].+?)\\*"); public static final Pattern REGEX_STRONG = Pattern.compile("\\*\\*(.+?)\\*\\*"); - public static final Pattern REGEX_LITERAL = Pattern.compile("``(.+?)``"); + public static final Pattern REGEX_LITERAL = Pattern.compile("``([^`]+)``"); public static final Pattern REGEX_REFERENCE = Pattern.compile("(http://[-/%#[\\&&&[^(>)]]\\._\\w]+\\w+)((\\W|&|$)+)"); public static final Pattern REGEX_INLINE_REFERENCE = Pattern.compile("`(.+) \\<\\;(http://[-/%#&\\._\\w]+)(\\>\\;)`"); public static final Pattern REGEX_EMAIL = Pattern.compile("(^|[^_\\w])([-\\._\\w]+@[-\\._\\w]+)([^-\\._\\w]|$)"); @@ -196,8 +196,8 @@ public static final Pattern REGEX_INLINE = Pattern.compile("(.*?)"); public static final Pattern REGEX_PROBLEMATIC = Pattern.compile("(.*?)"); public static final Pattern REGEX_GENERATED = Pattern.compile("(.*?)"); - public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^_<>]+\\`_\\W)|('[^_<>]+'_(\\W|$))|([\\S]+[^\\s<>\\.]+_(\\W|$))"); - public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`]+\\`__)|([\\w]+[^`\\s<>]+__)"); + public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^_<>]+\\`_\\W)|(('|`)[^_<`(')>]+('|`)_(\\W|$))|([\\S]+[^\\s<>\\.`]+_(\\W|$))"); + public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`\\]\\[]+\\`__)|(\\w+[^()`\\s<>]+__)"); } Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.30 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.31 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.30 Thu May 24 15:03:17 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Wed May 30 19:20:34 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.30 $ + * @version $Revision: 1.31 $ * - * Last update: $Date: 2007/05/24 15:03:17 $ + * Last update: $Date: 2007/05/30 19:20:34 $ * by : $Author: sletellier $ */ @@ -36,7 +36,6 @@ import java.io.BufferedReader; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; @@ -192,7 +191,7 @@ * copyright (done) * danger (done) * date (done) - * decoration + * decoration (done) * definition (done) * definition_list (done) * definition_list_item (done) @@ -209,11 +208,11 @@ * field_list (done) * field_name (done) * figure - * footer + * footer (done) * footnote (done) * footnote_reference (done) * generated - * header (parcialy done) + * header (done) * hint (done) * image (done) * important (done) @@ -237,7 +236,7 @@ * pending * problematic * raw - * reference (partialy done) + * reference (done) * revision (done) * row (done) * rubric @@ -252,7 +251,7 @@ * superscript * system_message * table (done) - * target + * target (done) * tbody (done) * term (done) * tgroup (done) @@ -840,9 +839,7 @@ } // Pour afficher le "PseudoXML" - /* - * if (item!=null) System.out.println(item.asXML()); - */ + //if (item!=null) System.out.println(item.asXML()); item = lexer.peekTitleOrBodyElement(); } @@ -1065,8 +1062,11 @@ result = DocumentHelper.createElement(TOPIC); result.addElement(TITLE).addAttribute("inline", "true").setText( item.attributeValue(TITLE)); - result.addElement(PARAGRAPH).addAttribute("inline", "true").setText( - item.getText()); + JRSTReader reader = new JRSTReader(); + String text = item.getText(); + Document doc = reader.read(new StringReader(text)); + result.appendContent(doc.getRootElement()); + return result; } @@ -1694,7 +1694,6 @@ // this prevent substitution in literal, example **something** must not // change in literal Map temporaries = new HashMap(); - Matcher matcher = REGEX_LITERAL.matcher(text); int index = 0; while (matcher.find()) { @@ -1704,11 +1703,10 @@ + LITERAL + ">"; String key = "literal" + index++; temporaries.put(key, literal); - - text = text.substring(0, start) + "``" + key + "``" + text = text.substring(0, start) + "" + key + "" + text.substring(end); + matcher = REGEX_LITERAL.matcher(text); } - // search all REGEX_INLINE_REFERENCE and replace it with special mark // this prevent substitution of URL with REGEX_REFERENCE. Use same // mechanisme as literal for that @@ -1722,10 +1720,11 @@ ref.setText(matcher.group(1)); String key = "inlineReference" + index++; temporaries.put(key, ref.asXML()); - text = text.substring(0, start) + "``" + key + "``" + text = text.substring(0, start) + "" + key + "" + text.substring(end); + matcher = REGEX_INLINE_REFERENCE.matcher(text); + } - // do all substitution inline text = REGEX_EMAIL.matcher(text).replaceAll( "$1<" + REFERENCE + " refuri='mailto:$2'>$2$1"); text = REGEX_REFERENCE.matcher(text).replaceAll( "<" + REFERENCE + " refuri='$1'>$1$2"); - matcher = REGEX_FOOTNOTE_REFERENCE.matcher(text); while (matcher.find()) { String txtDebut = text.substring(0, matcher.start()); @@ -1882,8 +1880,9 @@ matcher = REGEX_HYPERLINK_REFERENCE.matcher(text); while (matcher.find()) { String txtDebut = text.substring(0, matcher.start()); - String txtFin = text.substring(matcher.end(), text.length()); + String txtFin = text.substring(matcher.end()-1, text.length()); String ref = text.substring(matcher.start(), matcher.end() - 1); + ref = ref.replaceAll("('|_)", ""); ref = ref.replaceAll("[\\W&&[^-]]", " ").trim(); Element hyper = DocumentHelper.createElement("reference"); @@ -1902,8 +1901,9 @@ hyper.setText(ref); text = txtDebut + hyper.asXML() + txtFin; matcher = REGEX_HYPERLINK_REFERENCE.matcher(text); - + } + // substitution reference matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text); int begin = 0; @@ -1927,18 +1927,19 @@ } - // undo substitution in LITERAL - matcher = REGEX_LITERAL.matcher(text); + Pattern p = Pattern.compile("([^<>]+)"); + + matcher = p.matcher(text); while (matcher.find()) { String start = text.substring(0, matcher.start()); String end = text.substring(matcher.end()); String tempKey = matcher.group(1); text = start + temporaries.get(tempKey) + end; - + matcher = p.matcher(text); } - Element result = DocumentHelper.parseText("" + text + "") + Element result = DocumentHelper.parseText("" + text.trim() + "") .getRootElement(); e.setText(""); Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.26 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.27 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.26 Thu May 24 15:03:17 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Wed May 30 19:20:34 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.26 $ + * @version $Revision: 1.27 $ * - * Last update: $Date: 2007/05/24 15:03:17 $ + * Last update: $Date: 2007/05/30 19:20:34 $ * by : $Author: sletellier $ */ @@ -439,10 +439,10 @@ result = peekLineBlock(); } if (result == null) { - result = peekOption(); + result = peekBulletList(); } if (result == null) { - result = peekBulletList(); + result = peekOption(); } if (result == null) { result = peekEnumeratedList(); @@ -572,7 +572,7 @@ Element result = null; String line = in.readLine(); if (line != null){ - if (line.matches("^\\s*-{1,2}.\\s+.*$")){ + if (line.matches("^(\\s*-{1,2}.+\\s+.*)+\\s+.+$")){ result = DocumentHelper.createElement(OPTION_LIST).addAttribute("level", ""+level(line)); char delimiter; do{ @@ -585,27 +585,27 @@ 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"); + option_stringTmp=option_stringTmp.substring(matcher.end(), option_stringTmp.length()); + option.addAttribute("delimiterExiste", "false"); boolean done=false; if (delimiter==' '){ // S'il ya 2 espace a suivre, l'option est finit - if (option_stringTmp.charAt(0)==' '){ + if (option_stringTmp.charAt(1)==' '){ done=true; } } if ((delimiter=='=' || delimiter==' ')&&!done){ option.addAttribute("delimiterExiste", "true"); option.addAttribute("delimiter", ""+delimiter); - matcher = Pattern.compile("[ =]\\w+").matcher(option_stringTmp); + matcher = Pattern.compile(delimiter+"\\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())==','){ + if (option_stringTmp.charAt(option_argument.length()+1)==','){ delimiter = ','; line=line.substring(option_string.length()+option_argument.length()+3,line.length()); } - else if (option_stringTmp.charAt(option_argument.length())==' ') + else done=true; } else{ // Si la description n'est pas sur la meme ligne @@ -616,8 +616,8 @@ } } if (done) - result.setText(option_stringTmp.substring(matcher.end()-1,option_stringTmp.length()).trim()); - }while (delimiter==','); + result.setText(option_stringTmp.substring(matcher.end(),option_stringTmp.length()).trim()); + }while (delimiter==','); } } endPeek(); @@ -646,7 +646,10 @@ String title = line.substring(matcher.end(),line.length()); result.addAttribute(TITLE,title); line = in.readLine(); - String txt = joinBlock(readBlock(level(line))); + String [] lines=in.readWhile("(^ {"+level(line)+"}.*)|(\\s*)"); + String txt=""; + for (String txtTmp : lines) + txt += "\n"+txtTmp.trim(); result.setText(txt); } @@ -1074,7 +1077,7 @@ String [] prefix = in.readLines(2); if (prefix.length == 2 && - prefix[0].matches("::\\s*") && prefix[1].matches("\\s*")) { + prefix[0].matches("\\s*::\\s*") && prefix[1].matches("\\s*")) { String para = in.readLine(); if (para != null) { @@ -1536,7 +1539,7 @@ Element result = null; // in.skipBlankLines(); String line = in.readLine(); - if (line != null && line.matches("^\\s*["+escapeRegex(BULLET_CHAR)+"] \\S.*")) { + if (line != null && line.matches("^\\s*["+escapeRegex(BULLET_CHAR)+"] +\\S.*")) { int level = level(line); String bullet = line.substring(level, level + 1); Index: jrst2/src/java/org/codelutin/jrst/JRST.java diff -u jrst2/src/java/org/codelutin/jrst/JRST.java:1.8 jrst2/src/java/org/codelutin/jrst/JRST.java:1.9 --- jrst2/src/java/org/codelutin/jrst/JRST.java:1.8 Tue May 22 14:01:15 2007 +++ jrst2/src/java/org/codelutin/jrst/JRST.java Wed May 30 19:20:34 2007 @@ -23,9 +23,9 @@ * Created: 3 nov. 06 20:56:00 * * @author poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Last update: $Date: 2007/05/22 14:01:15 $ + * Last update: $Date: 2007/05/30 19:20:34 $ * by : $Author: sletellier $ */ @@ -190,7 +190,7 @@ public String getXslFile(); public boolean isXslFile(); - @Option(shortName="t", pattern = "xhtml|docbook|xml|html|xdoc|rst", // TODO |pdf|rst|odt|rtf", + @Option(shortName="t", pattern = "xhtml|docbook|xml|html|xdoc|rst", // TODO pdf|rst|odt|rtf", description = "Output type") public String getOutType(); public boolean isOutType();