Index: jrst2/src/java/org/codelutin/jrst/ReStructuredText.java diff -u jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.8 jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.9 --- jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.8 Wed May 9 12:12:19 2007 +++ jrst2/src/java/org/codelutin/jrst/ReStructuredText.java Thu May 10 16:13:49 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 11:10:30 * * @author poussin - * @version $Revision: 1.8 $ + * @version $Revision: 1.9 $ * - * Last update: $Date: 2007/05/09 12:12:19 $ + * Last update: $Date: 2007/05/10 16:13:49 $ * by : $Author: sletellier $ */ @@ -196,7 +196,7 @@ 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("('.+[^<>]+'_)|([^\\S]+[^\\s<>]+_)"); + public static final Pattern REGEX_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^_<>]+\\`_)|('[^_<>]+'_)|([\\S]+[^\\s<>\\.]+_)"); public static final Pattern REGEX_ANONYMOUS_HYPERLINK_REFERENCE = Pattern.compile("(\\`[^<>`]+\\`__)|([^\\S]+[^\\s<>]+__)"); } Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.20 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.21 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.20 Thu May 10 10:18:41 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Thu May 10 16:13:49 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.20 $ + * @version $Revision: 1.21 $ * - * Last update: $Date: 2007/05/10 10:18:41 $ + * Last update: $Date: 2007/05/10 16:13:49 $ * by : $Author: sletellier $ */ @@ -367,12 +367,19 @@ public void visit(Element e) { e.addAttribute("level", null); String type = e.attributeValue("type"); + boolean done = false; if (type!=null){ if (type.equals("contents")){ composeContents(e); e.addAttribute("type",null); + done=true; } } + if (e.getName().equals("title") && done){ + Element t = eTitle.getFirst(); + e.addAttribute("refid", t.attributeValue("refid")); + eTitle.removeFirst(); + } if ("true".equalsIgnoreCase(e.attributeValue("inline"))) { e.addAttribute("inline", null); try { @@ -392,6 +399,7 @@ } } private void composeContents(Element e) { + Element result = DocumentHelper.createElement(TOPIC); String option = e.getText(); int depth=-1; @@ -405,6 +413,8 @@ } int levelInit = Integer.parseInt(eTitle.getFirst().attributeValue("level")); LinkedList title = new LinkedList(); + for (int i=0;ilevel-levelInit) + if (depth>level) title.add(el); } } @@ -746,7 +756,7 @@ result.addAttribute("anonymous", "1"); int id = ++idMax; result.addAttribute("id", "id"+id); - result.addAttribute("refuri", item.attributeValue("refuri")); + result.addAttribute("refuri", item.attributeValue("refuri").replaceAll("`|_", "").trim()); eTargetAnonymous.add(result); return result; } @@ -1000,8 +1010,12 @@ String text = item.getText(); Document doc = reader.read(new StringReader(text)); result.appendContent(doc.getRootElement()); - Element attribution = result.addElement(ATTRIBUTION); - attribution.setText(item.attributeValue(ATTRIBUTION)); + String sAttribution = item.attributeValue(ATTRIBUTION); + if (sAttribution != null){ + Element attribution = result.addElement(ATTRIBUTION); + attribution.setText(sAttribution); + attribution.addAttribute("inline","true"); + } return result; } /** @@ -1308,7 +1322,6 @@ Element title = result.addElement(TITLE); copyLevel(item, result); copyLevel(item, title); - title.addAttribute("refid", "id"+(++idMax)); title.addAttribute("inline", "true").setText(item.getText().trim()); result.addAttribute("id", item.getText().replaceAll("\\W+", " ").trim().toLowerCase().replaceAll("\\W+", "-")); result.addAttribute("name", item.getText().toLowerCase().trim()); @@ -1445,7 +1458,6 @@ */ private void inline(Element e) throws DocumentException { String text = e.getText(); - text = StringEscapeUtils.escapeXml(text); // search all LITERAL and replace it with special mark @@ -1617,10 +1629,12 @@ ref = ref.replaceAll("`", ""); Element anonym = DocumentHelper.createElement("reference"); anonym.addAttribute("anonymous","1"); - Element target = eTargetAnonymous.getLast(); - eTargetAnonymous.removeLast(); anonym.addAttribute("name", ref.trim()); - anonym.addAttribute("refuri", target.attributeValue("refuri")); + if (!eTargetAnonymous.isEmpty()){ + Element target = eTargetAnonymous.getLast(); + eTargetAnonymous.removeLast(); + anonym.addAttribute("refuri", target.attributeValue("refuri")); + } anonym.setText(ref); text=txtDebut+anonym.asXML()+txtFin; matcher = REGEX_ANONYMOUS_HYPERLINK_REFERENCE.matcher(text); @@ -1635,9 +1649,11 @@ Element hyper = DocumentHelper.createElement("reference"); hyper.addAttribute("name", ref); for (Element el : eTarget){ - if (el.attributeValue("id").equals(ref)){ + if (el.attributeValue("id").equalsIgnoreCase(ref)){ hyper.addAttribute("refuri",el.attributeValue("refuri")); } + else + hyper.addAttribute("refid",ref); } hyper.setText(ref); Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.19 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.20 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.19 Thu May 10 10:18:41 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Thu May 10 16:13:49 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.19 $ + * @version $Revision: 1.20 $ * - * Last update: $Date: 2007/05/10 10:18:41 $ + * Last update: $Date: 2007/05/10 16:13:49 $ * by : $Author: sletellier $ */ @@ -384,9 +384,6 @@ result = peekTarget(); } if (result == null) { - result = peekTargetAnonymous(); - } - if (result == null) { result = peekFootnote(); } if (result == null) { @@ -396,15 +393,18 @@ result = peekFieldList(); } if (result == null) { - result = peekLiteralBlock(); + result = peekTargetAnonymous(); } if (result == null) { - result = peekBlankLine(); + result = peekLiteralBlock(); } if (result == null) { result = peekBlockQuote(); } if (result == null) { + result = peekBlankLine(); + } + if (result == null) { result = peekPara(); } @@ -423,7 +423,7 @@ Element result = null; String line = in.readLine(); if (line != null){ - // Le header est pars� des le debut + // Le header est parse des le debut if (line.matches("^\\s*.. "+HEADER+":: .*")){ result= DocumentHelper.createElement("remove").addAttribute("level", ""+level(line)); } @@ -719,32 +719,28 @@ Element result = null; String line = in.readLine(); if (line != null){ - int level = level(line); - String txt=line; - boolean done=(level==0); - String blockQuote = null; - while (!done) { - line = in.readLine(); - if (line!=null){ - if (line.matches("(^ {"+level+"}.*)|(\\s*)")){ - if (line.matches("^ {"+level+"}--\\s.*")){ - done=true; - blockQuote=line; - blockQuote = blockQuote.replaceAll("--","").trim(); - } - else - txt += "\n" + line; - } - else - done=true; - } - else - done=true; - } - if (blockQuote!=null){ - result = DocumentHelper.createElement(BLOCK_QUOTE).addAttribute("level", String.valueOf(level)); - result.addAttribute(ATTRIBUTION, blockQuote); - result.setText(txt.trim()); + if (line.matches("\\s*")){ + line=in.readLine(); + if (line!=null){ + int level = level(line); + String blockQuote = null; + if (!(level==0)){ + String txt=line; + String [] lines=in.readWhile("(^ {"+level+"}.*)|(\\s*)"); + for (String l : lines){ + if (l.matches("^ {"+level+"}--\\s*.*")){ + blockQuote=l; + blockQuote = blockQuote.replaceAll("--","").trim(); + } + else + txt += "\n" + l.trim(); + } + result = DocumentHelper.createElement(BLOCK_QUOTE).addAttribute("level", String.valueOf(level)); + if (blockQuote!=null) + result.addAttribute(ATTRIBUTION, blockQuote); + result.setText(txt); + } + } } } endPeek(); @@ -1435,6 +1431,7 @@ String text = line.substring(level + 1).trim(); result.addText(text); + in.skipBlankLines(); } endPeek(); @@ -1607,6 +1604,7 @@ String text = line.substring(begin).trim(); result.addText(text); + in.skipBlankLines(); } } @@ -1641,7 +1639,6 @@ String line = in.readLine(); if (line != null) { - //System.out.println("peekTitle line :"+line); if (startsWithTitleChar(line)) { String [] titles = in.readLines(2); if (titles.length == 2 @@ -1696,7 +1693,7 @@ Element result = null; String line = in.readLine(); if (line!=null){ - if (line.matches("^\\s*\\.\\.\\s_.+:.*")){ + if (line.matches("^\\s*\\.\\.\\s_[^_:].+:.*")){ result = DocumentHelper.createElement(TARGET); Matcher matcher = Pattern.compile("\\.\\.\\s_").matcher(line); if (matcher.find()){ @@ -1704,8 +1701,8 @@ for (int i=matcher.end();iline.length()){ line=in.readLine(); result.addAttribute("refuri", line.trim()); @@ -1727,10 +1724,10 @@ Element result = null; String line=in.readLine(); if (line!=null){ - if (line.matches("^\\s*__ .+$")){ + if (line.matches("^\\s*__ .+$|^\\s*\\.\\. __\\:.+$")){ result = DocumentHelper.createElement("targetAnonymous"); result.addAttribute("level", ""+level(line)); - Matcher matcher = Pattern.compile("__ ").matcher(line); + Matcher matcher = Pattern.compile("__ |\\.\\. __\\:").matcher(line); if (matcher.find()){ result.addAttribute("refuri", line.substring(matcher.end(),line.length())); } @@ -1812,14 +1809,15 @@ if (line!=null){ if (line.matches("^\\s*\\.\\.\\s\\[(#|[0-9]|\\*).*\\]\\s.+$")){ bLine=true; - }else if (!line.matches("\\s")){ - + }else if (line.matches("\\s*")){ + text+="\n"+line; + line = in.readLine(); int level = level(line); if (levelAv