Index: jrst2/src/java/org/codelutin/jrst/JRSTLexer.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.15 jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.16 --- jrst2/src/java/org/codelutin/jrst/JRSTLexer.java:1.15 Thu Apr 26 10:22:20 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTLexer.java Thu May 3 16:37:08 2007 @@ -23,9 +23,9 @@ * Created: 28 oct. 06 00:44:20 * * @author poussin - * @version $Revision: 1.15 $ + * @version $Revision: 1.16 $ * - * Last update: $Date: 2007/04/26 10:22:20 $ + * Last update: $Date: 2007/05/03 16:37:08 $ * by : $Author: sletellier $ */ @@ -120,7 +120,9 @@ public static final String ATTRIBUTION = "attribution"; public static final String DOCTEST_BLOCK = "doctest_block"; public static final String ADMONITION = "admonition"; - + public static final String TARGET = "target"; + public static final String FOOTNOTE = "footnote"; + //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Table Elements //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -379,6 +381,12 @@ result = peekEnumeratedList(); } if (result == null) { + result = peekTarget(); + } + if (result == null) { + result = peekFootnote(); + } + if (result == null) { result = peekDefinitionList(); } if (result == null) { @@ -1674,6 +1682,123 @@ return result; } /** + * .. _frungible doodads: http://www.example.org/ + * + * @return Element + * @throws IOException + */ + private Element peekTarget() throws IOException { + beginPeek(); + Element result = null; + String line = in.readLine(); + if (line!=null){ + if (line.matches("^\\s*\\.\\.\\s_.+: .+$")){ + result = DocumentHelper.createElement(TARGET); + Matcher matcher = Pattern.compile("\\.\\.\\s_").matcher(line); + if (matcher.find()){ + boolean done=false; + for (int i=matcher.end();i0){ + line=linesTmp[0]; + bLine=true; + } + } + + + + } + if (line==null) + line=""; + footnote.setText(text); + done=true; + } + + } + } + + + }while(bLine); + } + } + endPeek(); + return result; + } + /** * Read block text, block text have same indentation * * @param minLeftMargin min left blank needed to accept to read block @@ -1693,6 +1818,12 @@ } return txt; } + private String[] readBlockWithBlank(int level) throws IOException{ + + String [] lines = in.readWhile("(^ {"+level+"}.*)|(\\s*)"); + + return lines; + } /** * 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 Index: jrst2/src/java/org/codelutin/jrst/ReStructuredText.java diff -u jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.4 jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.5 --- jrst2/src/java/org/codelutin/jrst/ReStructuredText.java:1.4 Wed Apr 18 16:12:58 2007 +++ jrst2/src/java/org/codelutin/jrst/ReStructuredText.java Thu May 3 16:37:08 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 11:10:30 * * @author poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update: $Date: 2007/04/18 16:12:58 $ + * Last update: $Date: 2007/05/03 16:37:08 $ * by : $Author: sletellier $ */ @@ -184,7 +184,8 @@ public static final Pattern REGEX_REFERENCE = Pattern.compile("(http://[-/%#&\\._\\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]|$)"); - public static final Pattern REGEX_FOOTNOTE_REFERENCE = Pattern.compile("\\[([0-9]+?|#)\\]"); + public static final Pattern REGEX_FOOTNOTE_REFERENCE = Pattern.compile("\\[(#|[0-9])\\w*\\]_"); + //"\\[([0-9]+?|#)\\]"); public static final Pattern REGEX_CITATION_REFERENCE = Pattern.compile("\\[([^\\]]+?)\\]"); public static final Pattern REGEX_SUBSTITUTION_REFERENCE = Pattern.compile("\\|([^|]+?)\\|"); public static final Pattern REGEX_ABBREVIATION = Pattern.compile("(.*?)"); @@ -194,6 +195,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<>]+_)"); } Index: jrst2/src/java/org/codelutin/jrst/JRSTReader.java diff -u jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.15 jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.16 --- jrst2/src/java/org/codelutin/jrst/JRSTReader.java:1.15 Thu Apr 26 10:22:20 2007 +++ jrst2/src/java/org/codelutin/jrst/JRSTReader.java Thu May 3 16:37:08 2007 @@ -23,9 +23,9 @@ * Created: 27 oct. 06 00:15:34 * * @author poussin - * @version $Revision: 1.15 $ + * @version $Revision: 1.16 $ * - * Last update: $Date: 2007/04/26 10:22:20 $ + * Last update: $Date: 2007/05/03 16:37:08 $ * by : $Author: sletellier $ */ @@ -37,10 +37,13 @@ import java.io.Reader; import java.io.StringReader; 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; import org.apache.commons.logging.Log; @@ -220,8 +223,8 @@ * field_name (done) * figure * footer - * footnote - * footnote_reference + * footnote (done) + * footnote_reference (done) * generated * header (parcialy done) * hint (done) @@ -290,6 +293,11 @@ static protected Map defaultDirectives = null; protected Map directives = new HashMap(); + private int idMax = 0; + private LinkedList lblFootnotes = new LinkedList(); + private LinkedList lblFootnotesRef = new LinkedList(); + private LinkedList eFootnotes = new LinkedList(); + static { defaultDirectives = new HashMap(); defaultDirectives.put(IMAGE, new ImageDirective()); @@ -393,11 +401,7 @@ if (itemEquals(HEADER, item)){ Element decoration = result.addElement(DECORATION); Element header = decoration.addElement(HEADER); - JRSTReader reader = new JRSTReader(); - String text = item.getText(); - Document doc = reader.read(new StringReader(text)); - header.appendContent(doc.getRootElement()); - + header.addAttribute("inline", "true").setText(item.getText()); } item = lexer.peekRemove(); if (itemEquals("remove", item)) @@ -420,7 +424,7 @@ if (itemEquals(TITLE, item)) { lexer.remove(); Element subtitle = result.addElement(SUBTITLE); - copyLevel(item, subtitle); + copyLevel(item, subtitle);DocumentHelper.createElement("footnotes"); subtitle.addAttribute("inline", "true").setText(item.getText()); } @@ -529,7 +533,7 @@ while (!lexer.eof() && itemNotEquals(TITLE, item) && isUpperLevel(item, parent)) { if (itemEquals(JRSTLexer.BLANK_LINE, item)) { - // go to the next element + // go t o the next element lexer.remove(); }else if (itemEquals("remove", item)) { lexer.remove(); @@ -601,6 +605,15 @@ } else if (itemEquals(OPTION_LIST, item)) { Element list =composeOptionList(lexer); parent.add(list); + } else if (itemEquals(TARGET, item)) { + lexer.remove(); + Element list =composeTarget(item); + parent.add(list); + } else if (itemEquals("footnotes", item)) { + lexer.remove(); + Element[] list =composeFootnote(item); + for (Element l : list) + parent.add(l); } else { @@ -620,6 +633,105 @@ return parent; } /** + * @param item + * @return Element + */ + private Element composeTarget(Element item) { + return item; + } + /** + * @param item + * @return Element + * @throws Exception + */ + private Element[] composeFootnote(Element item) throws Exception { + Element[] result=null; + if (itemEquals("footnotes", item) ) { + List footnotes = (List)item.selectNodes(FOOTNOTE); + result = new Element[footnotes.size()]; + int cnt=0; + for (Element footnote : footnotes){ + result[cnt] = DocumentHelper.createElement(FOOTNOTE); + Element efootnote = DocumentHelper.createElement(FOOTNOTE); + int labelMax=0; + + for (int i = 0; i temporaries = new HashMap(); + Matcher matcher = REGEX_LITERAL.matcher(text); int index = 0; while(matcher.find()) { @@ -1216,10 +1330,151 @@ String reference = "<"+REFERENCE+" refuri='"+matcher.group(2)+"'>"+matcher.group(1)+""; String key = "inlineReference" + index++; temporaries.put(key, reference); - text = text.substring(0, start) + "``" + key + "``" + text.substring(end); } - + matcher = REGEX_FOOTNOTE_REFERENCE.matcher(text); + while (matcher.find()){ + String txtDebut=text.substring(0,matcher.start()); + String txtFin=text.substring(matcher.end(),text.length()); + Element footnote = DocumentHelper.createElement(FOOTNOTE_REFERENCE); + String sFootnote = matcher.group(); + boolean done = false; + for (int i=0;i$2$3"); @@ -1227,6 +1482,8 @@ text = REGEX_EMPHASIS.matcher(text).replaceAll("<"+EMPHASIS+">$1"); text = REGEX_REFERENCE.matcher(text).replaceAll("<"+REFERENCE+" refuri='$1'>$1$2"); + + // substitution reference matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text); int begin = 0; @@ -1249,6 +1506,8 @@ matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text); } + + // undo substitution in LITERAL matcher = REGEX_LITERAL.matcher(text); while(matcher.find()) { Index: jrst2/src/java/org/codelutin/jrst/JRST.java diff -u jrst2/src/java/org/codelutin/jrst/JRST.java:1.4 jrst2/src/java/org/codelutin/jrst/JRST.java:1.5 --- jrst2/src/java/org/codelutin/jrst/JRST.java:1.4 Thu Feb 8 11:48:15 2007 +++ jrst2/src/java/org/codelutin/jrst/JRST.java Thu May 3 16:37:08 2007 @@ -23,10 +23,10 @@ * Created: 3 nov. 06 20:56:00 * * @author poussin - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * - * Last update: $Date: 2007/02/08 11:48:15 $ - * by : $Author: bpoussin $ + * Last update: $Date: 2007/05/03 16:37:08 $ + * by : $Author: sletellier $ */ package org.codelutin.jrst; @@ -86,7 +86,8 @@ static final private String docbook2javahelp = walshDir + "/javahelp/javahelp.xsl"; // static final private String dbkx2html = walshDir + "/html/onechunk.xsl"; static final private String docbook2htmlhelp = walshDir + "/htmlhelp/htmlhelp.xsl"; - + static final private String rst2rst = "/xsl/xml2rst.xsl"; + // Out put type available static final public String TYPE_HTML = "html"; static final public String TYPE_XDOC = "xdoc"; @@ -94,6 +95,7 @@ static final public String TYPE_XHTML = "xhtml"; static final public String TYPE_JAVAHELP = "javahelp"; static final public String TYPE_HTMLHELP = "htmlhelp"; + static final public String TYPE_RST = "rst"; /** key, Out type; value: chain of XSL file to provide wanted file for output */ static private Map stylesheets = null; @@ -106,6 +108,7 @@ stylesheets.put(TYPE_XHTML, rst2docbook+","+docbook2xhtml); stylesheets.put(TYPE_JAVAHELP, rst2docbook+","+docbook2javahelp); stylesheets.put(TYPE_HTMLHELP, rst2docbook+","+docbook2htmlhelp); + stylesheets.put(TYPE_RST, rst2rst); } static public void main(String [] args) throws Exception { @@ -194,7 +197,7 @@ public String getXslFile(); public boolean isXslFile(); - @Option(shortName="t", pattern = "xhtml|docbook|xml|html|xdoc", // 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();