summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-10-25 09:24:23 -0400
committerJames Moger <james.moger@gitblit.com>2013-10-25 09:24:23 -0400
commit96a6dae0c86e505e129ce4af33886f4dda69d169 (patch)
treeb76e4a69141108aac149658c01fad5acd2ac85e9 /src
parent91fcabfb47311b4f902b1e3ae3a3da4abe4c05b8 (diff)
downloadgitblit-96a6dae0c86e505e129ce4af33886f4dda69d169.tar.gz
gitblit-96a6dae0c86e505e129ce4af33886f4dda69d169.zip
Strip Markdown extension from rendered [[WikiLink]] (issue-324)
Change-Id: I2f695f5d5d72d8c08272981f756334b45398a1f7
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/gitblit/wicket/pages/DocsPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/MarkdownPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RepositoryPage.java13
-rw-r--r--src/main/java/com/gitblit/wicket/pages/SummaryPage.java2
4 files changed, 15 insertions, 4 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/DocsPage.java b/src/main/java/com/gitblit/wicket/pages/DocsPage.java
index 58471ef9..2634ea8e 100644
--- a/src/main/java/com/gitblit/wicket/pages/DocsPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/DocsPage.java
@@ -74,7 +74,7 @@ public class DocsPage extends RepositoryPage {
// load the document
String [] encodings = GitBlit.getEncodings();
markdown = JGitUtils.getStringContent(r, head.getTree(), doc, encodings);
- html = MarkdownUtils.transformMarkdown(markdown, getLinkRenderer());
+ html = MarkdownUtils.transformMarkdown(markdown, getMarkdownLinkRenderer());
}
Fragment fragment = null;
diff --git a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
index e0c85cf5..0034984c 100644
--- a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
@@ -79,7 +79,7 @@ public class MarkdownPage extends RepositoryPage {
String htmlText;
try {
- htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());
+ htmlText = MarkdownUtils.transformMarkdown(markdownText, getMarkdownLinkRenderer());
} catch (Exception e) {
logger.error("failed to transform markdown", e);
if (markdownText == null) {
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index 157f9e7c..508b8654 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -653,7 +653,7 @@ public abstract class RepositoryPage extends RootPage {
*
* @return a link renderer
*/
- protected LinkRenderer getLinkRenderer() {
+ protected LinkRenderer getMarkdownLinkRenderer() {
RevCommit head = JGitUtils.getCommit(r, "HEAD");
final String id = getBestCommitId(head);
LinkRenderer renderer = new LinkRenderer() {
@@ -662,10 +662,21 @@ public abstract class RepositoryPage extends RootPage {
try {
String fsc = GitBlit.getString(Keys.web.forwardSlashCharacter, "/");
String path = URLEncoder.encode(node.getText().replace(' ', '-'), "UTF-8").replace("%2F", fsc);
+
+ // extract document name
String name = node.getText();
if (name.indexOf('/') > -1) {
name = name.substring(name.lastIndexOf('/') + 1);
}
+
+ // strip Markdown extension
+ for (String ext : GitBlit.getStrings(Keys.web.markdownExtensions)) {
+ String x = "." + ext;
+ if (name.endsWith(x)) {
+ name = name.substring(0, name.length() - x.length());
+ break;
+ }
+ }
String url = urlFor(MarkdownPage.class, WicketUtils.newPathParameter(repositoryName, id, path)).toString();
return new Rendering(url, name);
} catch (UnsupportedEncodingException e) {
diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
index 827e0799..3ea71d67 100644
--- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
@@ -167,7 +167,7 @@ public class SummaryPage extends RepositoryPage {
String [] encodings = GitBlit.getEncodings();
markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
if (isMarkdown) {
- htmlText = MarkdownUtils.transformMarkdown(markdownText, getLinkRenderer());
+ htmlText = MarkdownUtils.transformMarkdown(markdownText, getMarkdownLinkRenderer());
} else {
htmlText = MarkdownUtils.transformPlainText(markdownText);
}