]> source.dussan.org Git - gitblit.git/commitdiff
Add markup support for confluence, mediawiki, textile, trac, and twiki
authorJames Moger <james.moger@gitblit.com>
Tue, 12 Nov 2013 21:17:17 +0000 (16:17 -0500)
committerJames Moger <james.moger@gitblit.com>
Tue, 12 Nov 2013 22:56:46 +0000 (17:56 -0500)
Change-Id: I82ef161c6b6956c7b83cd4a1c37627beac6ea75b

.classpath
build.moxie
gitblit.iml
releases.moxie
src/main/distrib/data/gitblit.properties
src/main/java/com/gitblit/wicket/MarkupProcessor.java
src/main/java/com/gitblit/wicket/pages/DocsPage.html

index 08039d6f04913da95d145c8134c33a21b51b50bf..998233bcba69d16bae37887ec48becf7d4a498cf 100644 (file)
        <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" />
        <classpathentry kind="lib" path="ext/asm-util-4.1.jar" sourcepath="ext/src/asm-util-4.1.jar" />
+       <classpathentry kind="lib" path="ext/wikitext-core-1.4.jar" sourcepath="ext/src/wikitext-core-1.4.jar" />
+       <classpathentry kind="lib" path="ext/twiki-core-1.4.jar" sourcepath="ext/src/twiki-core-1.4.jar" />
+       <classpathentry kind="lib" path="ext/textile-core-1.4.jar" sourcepath="ext/src/textile-core-1.4.jar" />
+       <classpathentry kind="lib" path="ext/tracwiki-core-1.4.jar" sourcepath="ext/src/tracwiki-core-1.4.jar" />
+       <classpathentry kind="lib" path="ext/mediawiki-core-1.4.jar" sourcepath="ext/src/mediawiki-core-1.4.jar" />
+       <classpathentry kind="lib" path="ext/confluence-core-1.4.jar" sourcepath="ext/src/confluence-core-1.4.jar" />
        <classpathentry kind="lib" path="ext/org.eclipse.jgit-3.1.0.201310021548-r.jar" sourcepath="ext/src/org.eclipse.jgit-3.1.0.201310021548-r.jar" />
        <classpathentry kind="lib" path="ext/jsch-0.1.46.jar" sourcepath="ext/src/jsch-0.1.46.jar" />
        <classpathentry kind="lib" path="ext/JavaEWAH-0.5.6.jar" sourcepath="ext/src/JavaEWAH-0.5.6.jar" />
index 44f6d059235cb3f69a56ac44ab06ed1b8697632b..478374884e983cb6c810b4a642908fe392023d42 100644 (file)
@@ -105,6 +105,7 @@ properties: {
   groovy.version : 1.8.8
   bouncycastle.version : 1.47
   selenium.version : 2.28.0
+  wikitext.version : 1.4
   }
 
 # Dependencies
@@ -136,6 +137,12 @@ dependencies:
 - compile 'org.apache.lucene:lucene-highlighter:${lucene.version}' :war :fedclient
 - compile 'org.apache.lucene:lucene-memory:${lucene.version}' :war :fedclient
 - compile 'org.pegdown:pegdown:1.4.1' :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
+- compile 'org.fusesource.wikitext:tracwiki-core:${wikitext.version}' :war
+- compile 'org.fusesource.wikitext:mediawiki-core:${wikitext.version}' :war
+- compile 'org.fusesource.wikitext:confluence-core:${wikitext.version}' :war
 - compile 'org.eclipse.jgit:org.eclipse.jgit:${jgit.version}' :war :fedclient :manager :authority
 - compile 'org.eclipse.jgit:org.eclipse.jgit.http.server:${jgit.version}' :war :fedclient :manager :authority
 - compile 'org.bouncycastle:bcprov-jdk15on:${bouncycastle.version}' :war :authority
index c31d1e9e56ab92cf8b970be5bd27b1d8e4ff7515..af35a7a4ad357d1fa169e681d217b98fb6f1936d 100644 (file)
         </SOURCES>
       </library>
     </orderEntry>
+    <orderEntry type="module-library">
+      <library name="wikitext-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/wikitext-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/wikitext-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="twiki-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/twiki-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/twiki-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="textile-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/textile-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/textile-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="tracwiki-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/tracwiki-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/tracwiki-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="mediawiki-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/mediawiki-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/mediawiki-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
+    <orderEntry type="module-library">
+      <library name="confluence-core-1.4.jar">
+        <CLASSES>
+          <root url="jar://$MODULE_DIR$/ext/confluence-core-1.4.jar!/" />
+        </CLASSES>
+        <JAVADOC />
+        <SOURCES>
+          <root url="jar://$MODULE_DIR$/ext/src/confluence-core-1.4.jar!/" />
+        </SOURCES>
+      </library>
+    </orderEntry>
     <orderEntry type="module-library">
       <library name="org.eclipse.jgit-3.1.0.201310021548-r.jar">
         <CLASSES>
index 3a0bee6056e870567ac6174b062082de1e1dff1a..658b82a6d287c6289a5f16ef5f1eaa87805c2605 100644 (file)
@@ -34,6 +34,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 rendering confluence, mediawiki, textile, tracwiki, and twiki markup documents
        - Added setting to globally disable anonymous pushes in the receive pack
        - Added a normalized diffstat display to the commit, commitdiff, and compare pages
        - Added GO setting to automatically redirect all http requests to the secure https connector
@@ -41,6 +42,7 @@ r20: {
        - updated to Jetty 7.6.13
        - updated to JGit 3.1.0
        - replaced MarkdownPapers with pegdown 1.4.1
+       - added Eclipse WikiText libraries for processing confluence, mediawiki, textile, tracwiki, and twiki
     settings:
     - { name: 'git.createRepositoriesShared', defaultValue: 'false' }
     - { name: 'git.allowAnonymousPushes', defaultValue: 'false' }
index 722c5014a2d3d3a39995b8bad644b31f929c59f3..a791c1fd7bae8a7abfd442e1e2b8742a5ed33f16 100644 (file)
@@ -1016,6 +1016,41 @@ web.prettyPrintExtensions = aea agc basic c cbm cl clj cpp cs css dart el erl er
 # SINCE 0.5.0\r
 web.markdownExtensions = md mkd markdown MD MKD\r
 \r
+# Registered extensions for mediawiki transformation\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.4.0\r
+web.mediawikiExtensions = mw mediawiki\r
+\r
+# Registered extensions for twiki transformation\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.4.0\r
+web.twikiExtensions = twiki\r
+\r
+# Registered extensions for textile transformation\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.4.0\r
+web.textileExtensions = textile\r
+\r
+# Registered extensions for confluence transformation\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.4.0\r
+web.confluenceExtensions = confluence\r
+\r
+# Registered extensions for tracwiki transformation\r
+#\r
+# SPACE-DELIMITED\r
+# CASE-SENSITIVE\r
+# SINCE 1.4.0\r
+web.tracwikiExtensions = tracwiki\r
+\r
 # Image extensions\r
 #\r
 # SPACE-DELIMITED\r
index 4b4bee6748616302a383b99f137c8e621db6f747..4324f805021710d69bf7662dda346766d49857df 100644 (file)
@@ -16,6 +16,7 @@
 package com.gitblit.wicket;\r
 \r
 import java.io.Serializable;\r
+import java.io.StringWriter;\r
 import java.io.UnsupportedEncodingException;\r
 import java.net.URLEncoder;\r
 import java.text.MessageFormat;\r
@@ -26,6 +27,15 @@ import org.apache.wicket.Page;
 import org.apache.wicket.RequestCycle;\r
 import org.eclipse.jgit.lib.Repository;\r
 import org.eclipse.jgit.revwalk.RevCommit;\r
+import org.eclipse.mylyn.wikitext.confluence.core.ConfluenceLanguage;\r
+import org.eclipse.mylyn.wikitext.core.parser.Attributes;\r
+import org.eclipse.mylyn.wikitext.core.parser.MarkupParser;\r
+import org.eclipse.mylyn.wikitext.core.parser.builder.HtmlDocumentBuilder;\r
+import org.eclipse.mylyn.wikitext.core.parser.markup.MarkupLanguage;\r
+import org.eclipse.mylyn.wikitext.mediawiki.core.MediaWikiLanguage;\r
+import org.eclipse.mylyn.wikitext.textile.core.TextileLanguage;\r
+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.WikiLinkNode;\r
 import org.slf4j.Logger;\r
@@ -38,6 +48,7 @@ import com.gitblit.utils.JGitUtils;
 import com.gitblit.utils.MarkdownUtils;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.pages.DocPage;\r
+import com.gitblit.wicket.pages.RawPage;\r
 \r
 /**\r
  * Processes markup content and generates html with repository-relative page and\r
@@ -49,7 +60,7 @@ import com.gitblit.wicket.pages.DocPage;
 public class MarkupProcessor {\r
 \r
        public enum MarkupSyntax {\r
-               PLAIN, MARKDOWN\r
+               PLAIN, MARKDOWN, TWIKI, TRACWIKI, TEXTILE, MEDIAWIKI, CONFLUENCE\r
        }\r
 \r
        private Logger logger = LoggerFactory.getLogger(getClass());\r
@@ -62,7 +73,12 @@ public class MarkupProcessor {
 \r
        public List<String> getMarkupExtensions() {\r
                List<String> list = new ArrayList<String>();\r
+               list.addAll(settings.getStrings(Keys.web.confluenceExtensions));\r
                list.addAll(settings.getStrings(Keys.web.markdownExtensions));\r
+               list.addAll(settings.getStrings(Keys.web.mediawikiExtensions));\r
+               list.addAll(settings.getStrings(Keys.web.textileExtensions));\r
+               list.addAll(settings.getStrings(Keys.web.tracwikiExtensions));\r
+               list.addAll(settings.getStrings(Keys.web.twikiExtensions));\r
                return list;\r
        }\r
 \r
@@ -72,8 +88,18 @@ public class MarkupProcessor {
                        return MarkupSyntax.PLAIN;\r
                }\r
 \r
-               if (settings.getStrings(Keys.web.markdownExtensions).contains(ext)) {\r
+               if (settings.getStrings(Keys.web.confluenceExtensions).contains(ext)) {\r
+                       return MarkupSyntax.CONFLUENCE;\r
+               } else if (settings.getStrings(Keys.web.markdownExtensions).contains(ext)) {\r
                        return MarkupSyntax.MARKDOWN;\r
+               } else if (settings.getStrings(Keys.web.mediawikiExtensions).contains(ext)) {\r
+                       return MarkupSyntax.MEDIAWIKI;\r
+               } else if (settings.getStrings(Keys.web.textileExtensions).contains(ext)) {\r
+                       return MarkupSyntax.TEXTILE;\r
+               } else if (settings.getStrings(Keys.web.tracwikiExtensions).contains(ext)) {\r
+                       return MarkupSyntax.TRACWIKI;\r
+               } else if (settings.getStrings(Keys.web.twikiExtensions).contains(ext)) {\r
+                       return MarkupSyntax.TWIKI;\r
                }\r
 \r
                return MarkupSyntax.PLAIN;\r
@@ -115,9 +141,24 @@ public class MarkupProcessor {
                if (markupText != null) {\r
                        try {\r
                                switch (syntax){\r
+                               case CONFLUENCE:\r
+                                       parse(doc, repositoryName, commitId, new ConfluenceLanguage());\r
+                                       break;\r
                                case MARKDOWN:\r
                                        parse(doc, repositoryName, commitId);\r
                                        break;\r
+                               case MEDIAWIKI:\r
+                                       parse(doc, repositoryName, commitId, new MediaWikiLanguage());\r
+                                       break;\r
+                               case TEXTILE:\r
+                                       parse(doc, repositoryName, commitId, new TextileLanguage());\r
+                                       break;\r
+                               case TRACWIKI:\r
+                                       parse(doc, repositoryName, commitId, new TracWikiLanguage());\r
+                                       break;\r
+                               case TWIKI:\r
+                                       parse(doc, repositoryName, commitId, new TWikiLanguage());\r
+                                       break;\r
                                default:\r
                                        doc.html = MarkdownUtils.transformPlainText(markupText);\r
                                        break;\r
@@ -139,6 +180,61 @@ public class MarkupProcessor {
                return doc;\r
        }\r
 \r
+       /**\r
+        * Parses the markup using the specified markup language\r
+        *\r
+        * @param doc\r
+        * @param repositoryName\r
+        * @param commitId\r
+        * @param lang\r
+        */\r
+       private void parse(final MarkupDocument doc, final String repositoryName, final String commitId, MarkupLanguage lang) {\r
+               StringWriter writer = new StringWriter();\r
+               HtmlDocumentBuilder builder = new HtmlDocumentBuilder(writer) {\r
+\r
+                       @Override\r
+                       public void image(Attributes attributes, String imagePath) {\r
+                               String url;\r
+                               if (imagePath.indexOf("://") == -1) {\r
+                                       // relative image\r
+                                       String path = doc.getRelativePath(imagePath);\r
+                                       url = getWicketUrl(RawPage.class, repositoryName, commitId, path);\r
+                               } else {\r
+                                       // absolute image\r
+                                       url = imagePath;\r
+                               }\r
+                               super.image(attributes, url);\r
+                       }\r
+\r
+                       @Override\r
+                       public void link(Attributes attributes, String hrefOrHashName, String text) {\r
+                               String url;\r
+                               if (hrefOrHashName.charAt(0) != '#') {\r
+                                       if (hrefOrHashName.indexOf("://") == -1) {\r
+                                               // relative link\r
+                                               String path = doc.getRelativePath(hrefOrHashName);\r
+                                               url = getWicketUrl(DocPage.class, repositoryName, commitId, path);\r
+                                       } else {\r
+                                               // absolute link\r
+                                               url = hrefOrHashName;\r
+                                       }\r
+                               } else {\r
+                                       // page-relative hash link\r
+                                       url = hrefOrHashName;\r
+                               }\r
+                               super.link(attributes, url, text);\r
+                       }\r
+               };\r
+\r
+               // avoid the <html> and <body> tags\r
+               builder.setEmitAsDocument(false);\r
+\r
+               MarkupParser parser = new MarkupParser(lang);\r
+               parser.setBuilder(builder);\r
+               parser.parse(doc.markup);\r
+               doc.html = writer.toString();\r
+       }\r
+\r
        /**\r
         * Parses the document as Markdown using Pegdown.\r
         *\r
index 7f1e64e077fbefd8efcaa4749a1f2dbb863461e9..ab4d0b9754c3cf3b5d6ab8329fc7d4319784d6a7 100644 (file)
@@ -15,7 +15,9 @@
                <li><a data-toggle="tab" href="#pages"><wicket:message key="gb.pages">[pages]</wicket:message></a></li>\r
        </ul>\r
        <div class="tab-content">\r
-               <div id="home" wicket:id="index" class="tab-pane active"></div>\r
+               <div id="home" class="tab-pane active">\r
+                       <div class="markdown" wicket:id="index"></div>\r
+               </div>\r
                <div id="pages" wicket:id="documents" class="tab-pane"></div>\r
        </div>\r
 </wicket:fragment>\r