]> source.dussan.org Git - gitblit.git/commitdiff
Strip Markdown extension from rendered [[WikiLink]] (issue-324)
authorJames Moger <james.moger@gitblit.com>
Fri, 25 Oct 2013 13:24:23 +0000 (09:24 -0400)
committerJames Moger <james.moger@gitblit.com>
Fri, 25 Oct 2013 13:24:23 +0000 (09:24 -0400)
Change-Id: I2f695f5d5d72d8c08272981f756334b45398a1f7

src/main/java/com/gitblit/wicket/pages/DocsPage.java
src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
src/main/java/com/gitblit/wicket/pages/SummaryPage.java

index 58471ef9e3b61f4a801c73dfed36718d3220c558..2634ea8e36fcf5378e3ae2f02feb1e9e3a5bee7a 100644 (file)
@@ -74,7 +74,7 @@ public class DocsPage extends RepositoryPage {
                        // load the document\r
                        String [] encodings = GitBlit.getEncodings();\r
                        markdown = JGitUtils.getStringContent(r, head.getTree(), doc, encodings);\r
-                       html = MarkdownUtils.transformMarkdown(markdown, getLinkRenderer());\r
+                       html = MarkdownUtils.transformMarkdown(markdown, getMarkdownLinkRenderer());\r
                }\r
 \r
                Fragment fragment = null;\r
index e0c85cf59ad5af7d52ad0d4ff9eccebc3144c08e..0034984c77f7687520ba546b5562a8116474aa71 100644 (file)
@@ -79,7 +79,7 @@ public class MarkdownPage extends RepositoryPage {
 \r
                String htmlText;\r
                try {\r
-                       htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());\r
+                       htmlText = MarkdownUtils.transformMarkdown(markdownText, getMarkdownLinkRenderer());\r
                } catch (Exception e) {\r
                        logger.error("failed to transform markdown", e);\r
                        if (markdownText == null) {\r
index 157f9e7c8b1b719fbeb83a7cde751bf92dd66f8a..508b8654821e420f2838608ae09c8be5199a0483 100644 (file)
@@ -653,7 +653,7 @@ public abstract class RepositoryPage extends RootPage {
         *\r
         * @return a link renderer\r
         */\r
-       protected LinkRenderer getLinkRenderer() {\r
+       protected LinkRenderer getMarkdownLinkRenderer() {\r
                RevCommit head = JGitUtils.getCommit(r, "HEAD");\r
                final String id = getBestCommitId(head);\r
                LinkRenderer renderer = new LinkRenderer() {\r
@@ -662,10 +662,21 @@ public abstract class RepositoryPage extends RootPage {
                                try {\r
                                        String fsc = GitBlit.getString(Keys.web.forwardSlashCharacter, "/");\r
                                        String path = URLEncoder.encode(node.getText().replace(' ', '-'), "UTF-8").replace("%2F", fsc);\r
+\r
+                                       // extract document name\r
                                        String name = node.getText();\r
                                        if (name.indexOf('/') > -1) {\r
                                                name = name.substring(name.lastIndexOf('/') + 1);\r
                                        }\r
+\r
+                                       // strip Markdown extension\r
+                                       for (String ext : GitBlit.getStrings(Keys.web.markdownExtensions)) {\r
+                                               String x = "." + ext;\r
+                                               if (name.endsWith(x)) {\r
+                                                       name = name.substring(0, name.length() - x.length());\r
+                                                       break;\r
+                                               }\r
+                                       }\r
                                        String url = urlFor(MarkdownPage.class, WicketUtils.newPathParameter(repositoryName, id, path)).toString();\r
                                        return new Rendering(url, name);\r
                                } catch (UnsupportedEncodingException e) {\r
index 827e079965ccf665c03890fafbfee5be448e56e0..3ea71d675acd88174247219b490b4507428ba3b9 100644 (file)
@@ -167,7 +167,7 @@ public class SummaryPage extends RepositoryPage {
                                String [] encodings = GitBlit.getEncodings();\r
                                markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);\r
                                if (isMarkdown) {\r
-                                       htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());\r
+                                       htmlText = MarkdownUtils.transformMarkdown(markdownText, getMarkdownLinkRenderer());\r
                                } else {\r
                                        htmlText = MarkdownUtils.transformPlainText(markdownText);\r
                                }\r