]> source.dussan.org Git - gitblit.git/commitdiff
Support Markdown image links relative to the repository root (issue-324)
authorJames Moger <james.moger@gitblit.com>
Mon, 9 Dec 2013 21:37:20 +0000 (16:37 -0500)
committerJames Moger <james.moger@gitblit.com>
Mon, 9 Dec 2013 21:37:20 +0000 (16:37 -0500)
Change-Id: I8bad02b26a20636e4fc3d1f0ab0a16f0bacc7bf1

.classpath
build.moxie
gitblit.iml
releases.moxie
src/main/java/com/gitblit/wicket/MarkupProcessor.java

index b9367bfaf274c0e7f6c64e1f3ae76768bc02200a..6651e12b240d5d560517fd7e3a4217a2689cd012 100644 (file)
@@ -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" />
index 22fdfeac32904d8fbe1090ec6ce8cf2df6ba9f13..ce3a7e256cabf61b8fa25a56c25bd6f8ba53f680 100644 (file)
@@ -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
index f1daa9bdd7c2334d94b77be6f272e6231ec5a1c5..6ba4390a9bde3d6305df3bcf2521a02f861f87fd 100644 (file)
       </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>
index 9f559af1d6325c83aa22e1fe582e4572de9e71ae..1e8ce8c92b8bd69af0091703d82b9b7f4f8061d5 100644 (file)
@@ -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' }
index 1a5f553fc47ccb18c9aa88c7fc5185727433715a..d8344390339f15341a9082e4a0b68801136a1192 100644 (file)
@@ -15,6 +15,8 @@
  */\r
 package com.gitblit.wicket;\r
 \r
+import static org.pegdown.FastEncoder.encode;\r
+\r
 import java.io.Serializable;\r
 import java.io.StringWriter;\r
 import java.io.UnsupportedEncodingException;\r
@@ -40,6 +42,8 @@ import org.eclipse.mylyn.wikitext.textile.core.TextileLanguage;
 import org.eclipse.mylyn.wikitext.tracwiki.core.TracWikiLanguage;\r
 import org.eclipse.mylyn.wikitext.twiki.core.TWikiLanguage;\r
 import org.pegdown.LinkRenderer;\r
+import org.pegdown.ast.ExpImageNode;\r
+import org.pegdown.ast.RefImageNode;\r
 import org.pegdown.ast.WikiLinkNode;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
@@ -296,6 +300,34 @@ public class MarkupProcessor {
         */\r
        private void parse(final MarkupDocument doc, final String repositoryName, final String commitId) {\r
                LinkRenderer renderer = new LinkRenderer() {\r
+\r
+                       @Override\r
+                       public Rendering render(ExpImageNode node, String text) {\r
+                               if (node.url.indexOf("://") == -1) {\r
+                                       // repository-relative image link\r
+                                       String path = doc.getRelativePath(node.url);\r
+                                       String url = getWicketUrl(RawPage.class, repositoryName, commitId, path);\r
+                                       return new Rendering(url, text);\r
+                               }\r
+                               // absolute image link\r
+                               return new Rendering(node.url, text);\r
+                       }\r
+\r
+                       @Override\r
+                       public Rendering render(RefImageNode node, String url, String title, String alt) {\r
+                               Rendering rendering;\r
+                               if (url.indexOf("://") == -1) {\r
+                                       // repository-relative image link\r
+                                       String path = doc.getRelativePath(url);\r
+                                       String wurl = getWicketUrl(RawPage.class, repositoryName, commitId, path);\r
+                                       rendering = new Rendering(wurl, alt);\r
+                               } else {\r
+                                       // absolute image link\r
+                                       rendering = new Rendering(url, alt);\r
+                               }\r
+                               return StringUtils.isEmpty(title) ? rendering : rendering.withAttribute("title", encode(title));\r
+                       }\r
+\r
                        @Override\r
                        public Rendering render(WikiLinkNode node) {\r
                                String path = doc.getRelativePath(node.getText());\r