Unverified Commit 94168509 authored by Thomas Mortagne's avatar Thomas Mortagne Committed by GitHub
Browse files

Merge pull request #196 from michitux/XRENDERING-612

parents c28ff532 48cdf245
...@@ -66,6 +66,11 @@ public class XHTMLXWikiGeneratorListener extends DefaultXWikiGeneratorListener ...@@ -66,6 +66,11 @@ public class XHTMLXWikiGeneratorListener extends DefaultXWikiGeneratorListener
*/ */
private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("[a-zA-Z0-9+.-]*://"); private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("[a-zA-Z0-9+.-]*://");
/**
* Prefix for mailto-links.
*/
private static final String MAILTO_PREFIX = "mailto:";
private static final String CLASS_ATTRIBUTE = "class"; private static final String CLASS_ATTRIBUTE = "class";
/** /**
...@@ -142,7 +147,9 @@ public void onImage(WikiReference reference) ...@@ -142,7 +147,9 @@ public void onImage(WikiReference reference)
* <ul> * <ul>
* <li>UC1: the reference points to a valid URL, we return a reference of type "url", * <li>UC1: the reference points to a valid URL, we return a reference of type "url",
* e.g. {@code http://server/path/reference#anchor}</li> * e.g. {@code http://server/path/reference#anchor}</li>
* <li>UC2: the reference is not a valid URL, we return a reference of type "path", * <li>UC2: the reference is a mailto: link, we return a reference of type "mailto",
* e.g., {@code mailto:user@example.com}</li>
* <li>UC3: the reference is not a valid URL, we return a reference of type "path",
* e.g. {@code path/reference#anchor}</li> * e.g. {@code path/reference#anchor}</li>
* </ul> * </ul>
* *
...@@ -158,8 +165,11 @@ private ResourceReference computeResourceReference(String rawReference) ...@@ -158,8 +165,11 @@ private ResourceReference computeResourceReference(String rawReference)
if (matcher.lookingAt()) { if (matcher.lookingAt()) {
// We have UC1 // We have UC1
reference = new ResourceReference(rawReference, ResourceType.URL); reference = new ResourceReference(rawReference, ResourceType.URL);
} else { } else if (rawReference.startsWith(MAILTO_PREFIX)) {
// We have UC2 // We have UC2
reference = new ResourceReference(rawReference.substring(MAILTO_PREFIX.length()), ResourceType.MAILTO);
} else {
// We have UC3
reference = new ResourceReference(rawReference, ResourceType.PATH); reference = new ResourceReference(rawReference, ResourceType.PATH);
} }
......
.#-----------------------------------------------------
.input|xhtml/1.0
.#-----------------------------------------------------
<p>one <a href="mailto:john@doe.com">two</a> three</p>
.#-----------------------------------------------------
.expect|event/1.0
.#-----------------------------------------------------
beginDocument
beginParagraph
onWord [one]
onSpace
beginLink [Typed = [true] Type = [mailto] Reference = [john@doe.com]] [false]
onWord [two]
endLink [Typed = [true] Type = [mailto] Reference = [john@doe.com]] [false]
onSpace
onWord [three]
endParagraph
endDocument
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment