summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-12-09 16:37:20 -0500
committerJames Moger <james.moger@gitblit.com>2013-12-09 16:37:20 -0500
commit0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc (patch)
tree4c4bf38ce5a62c3adfeeeda193b9e46a54b76357
parent2a5e6510782fff7562fc2272a8483f4fa3c868c1 (diff)
downloadgitblit-0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc.tar.gz
gitblit-0c0bb9c0c479b0c04e918f1dfb57e2998d0b3ecc.zip
Support Markdown image links relative to the repository root (issue-324)
Change-Id: I8bad02b26a20636e4fc3d1f0ab0a16f0bacc7bf1
-rw-r--r--.classpath6
-rw-r--r--build.moxie2
-rw-r--r--gitblit.iml18
-rw-r--r--releases.moxie3
-rw-r--r--src/main/java/com/gitblit/wicket/MarkupProcessor.java32
5 files changed, 47 insertions, 14 deletions
diff --git a/.classpath b/.classpath
index b9367bfa..6651e12b 100644
--- a/.classpath
+++ b/.classpath
@@ -30,9 +30,9 @@
<classpathentry kind="lib" path="ext/lucene-queryparser-4.6.0.jar" sourcepath="ext/src/lucene-queryparser-4.6.0.jar" />
<classpathentry kind="lib" path="ext/lucene-sandbox-4.6.0.jar" sourcepath="ext/src/lucene-sandbox-4.6.0.jar" />
<classpathentry kind="lib" path="ext/jakarta-regexp-1.4.jar" />
- <classpathentry kind="lib" path="ext/pegdown-1.4.1.jar" sourcepath="ext/src/pegdown-1.4.1.jar" />
- <classpathentry kind="lib" path="ext/parboiled-java-1.1.5.jar" sourcepath="ext/src/parboiled-java-1.1.5.jar" />
- <classpathentry kind="lib" path="ext/parboiled-core-1.1.5.jar" sourcepath="ext/src/parboiled-core-1.1.5.jar" />
+ <classpathentry kind="lib" path="ext/pegdown-1.4.2.jar" sourcepath="ext/src/pegdown-1.4.2.jar" />
+ <classpathentry kind="lib" path="ext/parboiled-java-1.1.6.jar" sourcepath="ext/src/parboiled-java-1.1.6.jar" />
+ <classpathentry kind="lib" path="ext/parboiled-core-1.1.6.jar" sourcepath="ext/src/parboiled-core-1.1.6.jar" />
<classpathentry kind="lib" path="ext/asm-4.1.jar" sourcepath="ext/src/asm-4.1.jar" />
<classpathentry kind="lib" path="ext/asm-tree-4.1.jar" sourcepath="ext/src/asm-tree-4.1.jar" />
<classpathentry kind="lib" path="ext/asm-analysis-4.1.jar" sourcepath="ext/src/asm-analysis-4.1.jar" />
diff --git a/build.moxie b/build.moxie
index 22fdfeac..ce3a7e25 100644
--- a/build.moxie
+++ b/build.moxie
@@ -145,7 +145,7 @@ dependencies:
- compile 'org.apache.lucene:lucene-highlighter:${lucene.version}' :war :fedclient
- compile 'org.apache.lucene:lucene-memory:${lucene.version}' :war :fedclient
- compile 'org.apache.lucene:lucene-queryparser:${lucene.version}' :war :fedclient
-- compile 'org.pegdown:pegdown:1.4.1' :war
+- compile 'org.pegdown:pegdown:1.4.2' :war
- compile 'org.fusesource.wikitext:wikitext-core:${wikitext.version}' :war
- compile 'org.fusesource.wikitext:twiki-core:${wikitext.version}' :war
- compile 'org.fusesource.wikitext:textile-core:${wikitext.version}' :war
diff --git a/gitblit.iml b/gitblit.iml
index f1daa9bd..6ba4390a 100644
--- a/gitblit.iml
+++ b/gitblit.iml
@@ -287,35 +287,35 @@
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="pegdown-1.4.1.jar">
+ <library name="pegdown-1.4.2.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/pegdown-1.4.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/pegdown-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/pegdown-1.4.1.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/pegdown-1.4.2.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="parboiled-java-1.1.5.jar">
+ <library name="parboiled-java-1.1.6.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/parboiled-java-1.1.5.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/parboiled-java-1.1.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/parboiled-java-1.1.5.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/parboiled-java-1.1.6.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library">
- <library name="parboiled-core-1.1.5.jar">
+ <library name="parboiled-core-1.1.6.jar">
<CLASSES>
- <root url="jar://$MODULE_DIR$/ext/parboiled-core-1.1.5.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/parboiled-core-1.1.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
- <root url="jar://$MODULE_DIR$/ext/src/parboiled-core-1.1.5.jar!/" />
+ <root url="jar://$MODULE_DIR$/ext/src/parboiled-core-1.1.6.jar!/" />
</SOURCES>
</library>
</orderEntry>
diff --git a/releases.moxie b/releases.moxie
index 9f559af1..1e8ce8c9 100644
--- a/releases.moxie
+++ b/releases.moxie
@@ -47,6 +47,7 @@ r20: {
- Set Link: <url>; rel="canonical" http header for SEO (issue-304)
- Added raw links to the commit, commitdiff, and compare pages (issue-319)
- Support intradocument linking in Markdown content using [[WikiLinks]] syntax (issue-324)
+ - Support Markdown image links relative to the repository root (issue-324)
- Added filesystem write permission check (issue-345)
- Support rendering confluence, mediawiki, textile, tracwiki, and twiki markup documents
- Added setting to globally disable anonymous pushes in the receive pack
@@ -59,7 +60,7 @@ r20: {
- updated to JGit 3.1.0
- updated to Lucene 4.6.0
- updated to BouncyCastle 1.49
- - replaced MarkdownPapers with pegdown 1.4.1
+ - replaced MarkdownPapers with pegdown 1.4.2
- added Eclipse WikiText libraries for processing confluence, mediawiki, textile, tracwiki, and twiki
settings:
- { name: 'git.createRepositoriesShared', defaultValue: 'false' }
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());