summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/gitblit
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r--src/main/java/com/gitblit/GitBlit.java3
-rw-r--r--src/main/java/com/gitblit/utils/MarkdownUtils.java40
-rw-r--r--src/main/java/com/gitblit/wicket/pages/MarkdownPage.java4
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RepositoryPage.java2
-rw-r--r--src/main/java/com/gitblit/wicket/pages/SummaryPage.java4
5 files changed, 18 insertions, 35 deletions
diff --git a/src/main/java/com/gitblit/GitBlit.java b/src/main/java/com/gitblit/GitBlit.java
index 7f82432d..a23dd8c2 100644
--- a/src/main/java/com/gitblit/GitBlit.java
+++ b/src/main/java/com/gitblit/GitBlit.java
@@ -32,7 +32,6 @@ import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.security.Principal;
import java.text.MessageFormat;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -2713,7 +2712,7 @@ public class GitBlit implements ServletContextListener {
try {
String prepared = processCommitMessageRegex(repository.name, text);
return MarkdownUtils.transformMarkdown(prepared);
- } catch (ParseException e) {
+ } catch (Exception e) {
logger.error("Failed to render commit message as markdown", e);
}
break;
diff --git a/src/main/java/com/gitblit/utils/MarkdownUtils.java b/src/main/java/com/gitblit/utils/MarkdownUtils.java
index 15242364..33d7a6ae 100644
--- a/src/main/java/com/gitblit/utils/MarkdownUtils.java
+++ b/src/main/java/com/gitblit/utils/MarkdownUtils.java
@@ -15,14 +15,14 @@
*/
package com.gitblit.utils;
+import static org.pegdown.Extensions.ALL;
+
import java.io.IOException;
import java.io.Reader;
-import java.io.StringReader;
import java.io.StringWriter;
-import org.slf4j.LoggerFactory;
-import org.tautua.markdownpapers.Markdown;
-import org.tautua.markdownpapers.parser.ParseException;
+import org.apache.commons.io.IOUtils;
+import org.pegdown.PegDownProcessor;
/**
* Utility methods for transforming raw markdown text to html.
@@ -39,17 +39,10 @@ public class MarkdownUtils {
* @return html version of markdown text
* @throws java.text.ParseException
*/
- public static String transformMarkdown(String markdown) throws java.text.ParseException {
- try {
- StringReader reader = new StringReader(markdown);
- String html = transformMarkdown(reader);
- reader.close();
- return html;
- } catch (IllegalArgumentException e) {
- throw new java.text.ParseException(e.getMessage(), 0);
- } catch (NullPointerException p) {
- throw new java.text.ParseException("Markdown string is null!", 0);
- }
+ public static String transformMarkdown(String markdown) {
+ PegDownProcessor pd = new PegDownProcessor(ALL);
+ String html = pd.markdownToHtml(markdown);
+ return html;
}
/**
@@ -60,22 +53,13 @@ public class MarkdownUtils {
* @return html version of the markdown text
* @throws java.text.ParseException
*/
- public static String transformMarkdown(Reader markdownReader) throws java.text.ParseException {
+ public static String transformMarkdown(Reader markdownReader) throws IOException {
// Read raw markdown content and transform it to html
StringWriter writer = new StringWriter();
try {
- Markdown md = new Markdown();
- md.transform(markdownReader, writer);
- return writer.toString().trim();
- } catch (StringIndexOutOfBoundsException e) {
- LoggerFactory.getLogger(MarkdownUtils.class).error("MarkdownPapers failed to parse Markdown!", e);
- throw new java.text.ParseException(e.getMessage(), 0);
- } catch (ParseException p) {
- LoggerFactory.getLogger(MarkdownUtils.class).error("MarkdownPapers failed to parse Markdown!", p);
- throw new java.text.ParseException(p.getMessage(), 0);
- } catch (Exception e) {
- LoggerFactory.getLogger(MarkdownUtils.class).error("MarkdownPapers failed to parse Markdown!", e);
- throw new java.text.ParseException(e.getMessage(), 0);
+ IOUtils.copy(markdownReader, writer);
+ String markdown = writer.toString();
+ return transformMarkdown(markdown);
} finally {
try {
writer.close();
diff --git a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
index 5aa80294..188a5b4b 100644
--- a/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/MarkdownPage.java
@@ -16,7 +16,6 @@
package com.gitblit.wicket.pages;
import java.text.MessageFormat;
-import java.text.ParseException;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
@@ -60,7 +59,8 @@ public class MarkdownPage extends RepositoryPage {
String htmlText;
try {
htmlText = MarkdownUtils.transformMarkdown(markdownText);
- } catch (ParseException p) {
+ } catch (Exception e) {
+ logger.error("failed to transform markdown", e);
markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
htmlText = StringUtils.breakLinesForHtml(markdownText);
}
diff --git a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
index e5ce22a1..dabaed03 100644
--- a/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RepositoryPage.java
@@ -75,7 +75,7 @@ import com.gitblit.wicket.panels.RefsPanel;
public abstract class RepositoryPage extends RootPage {
- private final Logger logger = LoggerFactory.getLogger(getClass());
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
private final String PARAM_STAR = "star";
diff --git a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
index 00d77a4e..cc9697c6 100644
--- a/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/SummaryPage.java
@@ -18,7 +18,6 @@ package com.gitblit.wicket.pages;
import java.awt.Color;
import java.awt.Dimension;
import java.text.MessageFormat;
-import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@@ -166,7 +165,8 @@ public class SummaryPage extends RepositoryPage {
markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
htmlText = MarkdownUtils.transformMarkdown(markdownText);
}
- } catch (ParseException p) {
+ } catch (Exception e) {
+ logger.error("failed to transform markdown", e);
markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
htmlText = StringUtils.breakLinesForHtml(markdownText);
}