diff options
author | James Moger <james.moger@gitblit.com> | 2013-12-09 16:37:20 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-12-09 16:37:20 -0500 |
commit | 0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc (patch) | |
tree | 4c4bf38ce5a62c3adfeeeda193b9e46a54b76357 /src/main | |
parent | 2a5e6510782fff7562fc2272a8483f4fa3c868c1 (diff) | |
download | gitblit-0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc.tar.gz gitblit-0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc.zip |
Support Markdown image links relative to the repository root (issue-324)
Change-Id: I8bad02b26a20636e4fc3d1f0ab0a16f0bacc7bf1
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/wicket/MarkupProcessor.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/main/java/com/gitblit/wicket/MarkupProcessor.java b/src/main/java/com/gitblit/wicket/MarkupProcessor.java index 1a5f553f..d8344390 100644 --- a/src/main/java/com/gitblit/wicket/MarkupProcessor.java +++ b/src/main/java/com/gitblit/wicket/MarkupProcessor.java @@ -15,6 +15,8 @@ */
package com.gitblit.wicket;
+import static org.pegdown.FastEncoder.encode;
+
import java.io.Serializable;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
@@ -40,6 +42,8 @@ import org.eclipse.mylyn.wikitext.textile.core.TextileLanguage; import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;
import org.eclipse.mylyn.wikitext.twiki.core.TWikiLanguage;
import org.pegdown.LinkRenderer;
+import org.pegdown.ast.ExpImageNode;
+import org.pegdown.ast.RefImageNode;
import org.pegdown.ast.WikiLinkNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -296,6 +300,34 @@ public class MarkupProcessor { */
private void parse(final MarkupDocument doc, final String repositoryName, final String commitId) {
LinkRenderer renderer = new LinkRenderer() {
+
+ @Override
+ public Rendering render(ExpImageNode node, String text) {
+ if (node.url.indexOf("://") == -1) {
+ // repository-relative image link
+ String path = doc.getRelativePath(node.url);
+ String url = getWicketUrl(RawPage.class, repositoryName, commitId, path);
+ return new Rendering(url, text);
+ }
+ // absolute image link
+ return new Rendering(node.url, text);
+ }
+
+ @Override
+ public Rendering render(RefImageNode node, String url, String title, String alt) {
+ Rendering rendering;
+ if (url.indexOf("://") == -1) {
+ // repository-relative image link
+ String path = doc.getRelativePath(url);
+ String wurl = getWicketUrl(RawPage.class, repositoryName, commitId, path);
+ rendering = new Rendering(wurl, alt);
+ } else {
+ // absolute image link
+ rendering = new Rendering(url, alt);
+ }
+ return StringUtils.isEmpty(title) ? rendering : rendering.withAttribute("title", encode(title));
+ }
+
@Override
public Rendering render(WikiLinkNode node) {
String path = doc.getRelativePath(node.getText());
|