diff options
author | James Moger <james.moger@gitblit.com> | 2014-03-11 10:02:28 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-03-11 10:02:28 -0400 |
commit | d2d0c66bc2fa9c030fe19b6a6da4f153fe8a2f77 (patch) | |
tree | af940ec16a27772ed1ca7bae581c9a7b80b217b4 /src/main/java/com/gitblit/utils | |
parent | 1221a4386de08586e06917fe163333d3de76662b (diff) | |
download | gitblit-d2d0c66bc2fa9c030fe19b6a6da4f153fe8a2f77.tar.gz gitblit-d2d0c66bc2fa9c030fe19b6a6da4f153fe8a2f77.zip |
Workaround pegdown bug and improve relative image path processing
Diffstat (limited to 'src/main/java/com/gitblit/utils')
-rw-r--r-- | src/main/java/com/gitblit/utils/MarkdownUtils.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/main/java/com/gitblit/utils/MarkdownUtils.java b/src/main/java/com/gitblit/utils/MarkdownUtils.java index dcd79f16..da0db79d 100644 --- a/src/main/java/com/gitblit/utils/MarkdownUtils.java +++ b/src/main/java/com/gitblit/utils/MarkdownUtils.java @@ -25,10 +25,13 @@ import java.text.MessageFormat; import org.apache.commons.io.IOUtils;
import org.pegdown.LinkRenderer;
+import org.pegdown.ParsingTimeoutException;
import org.pegdown.PegDownProcessor;
+import org.pegdown.ast.RootNode;
import com.gitblit.IStoredSettings;
import com.gitblit.Keys;
+import com.gitblit.wicket.MarkupProcessor.WorkaroundHtmlSerializer;
/**
* Utility methods for transforming raw markdown text to html.
@@ -72,9 +75,13 @@ public class MarkdownUtils { * @throws java.text.ParseException
*/
public static String transformMarkdown(String markdown, LinkRenderer linkRenderer) {
- PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);
- String html = pd.markdownToHtml(markdown, linkRenderer == null ? new LinkRenderer() : linkRenderer);
- return html;
+ try {
+ PegDownProcessor pd = new PegDownProcessor(ALL & ~SMARTYPANTS);
+ RootNode astRoot = pd.parseMarkdown(markdown.toCharArray());
+ return new WorkaroundHtmlSerializer(linkRenderer == null ? new LinkRenderer() : linkRenderer).toHtml(astRoot);
+ } catch (ParsingTimeoutException e) {
+ return null;
+ }
}
/**
|