### Eclipse Workspace Patch 1.0 #P jrst Index: src/main/java/org/nuiton/jrst/ReStructuredText.java =================================================================== --- src/main/java/org/nuiton/jrst/ReStructuredText.java (revision 556) +++ src/main/java/org/nuiton/jrst/ReStructuredText.java (working copy) @@ -197,6 +197,8 @@ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Inline Elements Regex // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + public static final Pattern REGEX_ESCAPE = Pattern + .compile("^\\\\(.*)"); public static final Pattern REGEX_EMPHASIS = Pattern .compile("\\*([^*(\\]_.+\\[)].+?)\\*"); public static final Pattern REGEX_STRONG = Pattern Index: src/main/java/org/nuiton/jrst/JRSTReader.java =================================================================== --- src/main/java/org/nuiton/jrst/JRSTReader.java (revision 556) +++ src/main/java/org/nuiton/jrst/JRSTReader.java (working copy) @@ -86,6 +86,7 @@ import static org.nuiton.jrst.ReStructuredText.PARAGRAPH; import static org.nuiton.jrst.ReStructuredText.REFERENCE; import static org.nuiton.jrst.ReStructuredText.REGEX_ANONYMOUS_HYPERLINK_REFERENCE; +import static org.nuiton.jrst.ReStructuredText.REGEX_ESCAPE; import static org.nuiton.jrst.ReStructuredText.REGEX_EMAIL; import static org.nuiton.jrst.ReStructuredText.REGEX_EMPHASIS; import static org.nuiton.jrst.ReStructuredText.REGEX_FOOTNOTE_REFERENCE; @@ -2106,7 +2107,7 @@ "$1<" + REFERENCE + " refuri='mailto:$2'>$2$3"); text = REGEX_STRONG.matcher(text).replaceAll( - "<" + STRONG + ">$1"); + "<" + STRONG + "> $1 "); text = REGEX_EMPHASIS.matcher(text).replaceAll( "<" + EMPHASIS + ">$1"); text = REGEX_REFERENCE.matcher(text).replaceAll( @@ -2259,33 +2260,44 @@ } // .. _truc: http://truc.html matcher = REGEX_HYPERLINK_REFERENCE.matcher(text); + String tempText = ""; while (matcher.find()) { String txtDebut = text.substring(0, matcher.start()); String txtFin = text.substring(matcher.end(), text.length()); String ref = text.substring(matcher.start(), matcher.end() - 1); ref = StringEscapeUtils.unescapeXml(ref); - ref = ref.replaceAll("('|_)", ""); - ref = ref.replaceAll("`", ""); - Element hyper = DocumentHelper.createElement("reference"); - hyper.addAttribute("name", ref); - boolean trouve = false; - for (int i = 0; i < eTarget.size() && !trouve; i++) { - Element el = eTarget.get(i); - String refTmp = URLEncoder.encode(ref.replaceAll("\\s", "-").toLowerCase(), "UTF-8"); - if (el.attributeValue("id").equalsIgnoreCase((refTmp))) { - hyper.addAttribute("refuri", el.attributeValue("refuri")); - trouve = true; - } + Matcher escapeMatcher = REGEX_ESCAPE.matcher(ref); + if(escapeMatcher.matches()) { + tempText += txtDebut + escapeMatcher.group(1) + " "; + text = txtFin; } - if (!trouve) { - hyper.addAttribute("refid", ref); + else { + ref = ref.replaceAll("('|_)", ""); + ref = ref.replaceAll("`", ""); + Element hyper = DocumentHelper.createElement("reference"); + hyper.addAttribute("name", ref); + boolean trouve = false; + for (int i = 0; i < eTarget.size() && !trouve; i++) { + Element el = eTarget.get(i); + String refTmp = URLEncoder.encode(ref.replaceAll("\\s", "-").toLowerCase(), "UTF-8"); + if (el.attributeValue("id").equalsIgnoreCase((refTmp))) { + hyper.addAttribute("refuri", el.attributeValue("refuri")); + trouve = true; + } + } + if (!trouve) { + hyper.addAttribute("refid", ref); + } + hyper.setText(ref); + tempText += txtDebut + hyper.asXML() + " "; + text = txtFin; } - hyper.setText(ref); - text = txtDebut + hyper.asXML() + " " + txtFin; - matcher = REGEX_HYPERLINK_REFERENCE.matcher(text); - + matcher = REGEX_HYPERLINK_REFERENCE.matcher(text); } - + if(!tempText.isEmpty()) { + text = tempText + text; + } + // substitution reference matcher = REGEX_SUBSTITUTION_REFERENCE.matcher(text); int begin = 0;