Commit cc1d3e63 authored by Liang Ding's avatar Liang Ding

Markdown 解析错误时返回 "Markdown error"

parent 6391464a
......@@ -913,13 +913,15 @@ public final class Filler {
}
/**
* Processes the abstract of the specified article with the specified
* preference.
*
* <p> <ul> <li>If the abstract is {@code null}, sets it with ""</li> <li>If
* user configured preference "titleOnly", sets the abstract with ""</li>
* <li>If user configured preference "titleAndContent", sets the abstract
* with the content of the article</li> </ul> </p>
* Processes the abstract of the specified article with the specified preference.
*
* <p>
* <ul>
* <li>If the abstract is {@code null}, sets it with ""</li>
* <li>If user configured preference "titleOnly", sets the abstract with ""</li>
* <li>If user configured preference "titleAndContent", sets the abstract with the content of the article</li>
* </ul>
* </p>
*
* @param preference the specified preference
* @param article the specified article
......
......@@ -18,8 +18,11 @@ package org.b3log.solo.util;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.b3log.latke.util.Strings;
import org.tautua.markdownpapers.Markdown;
import org.tautua.markdownpapers.parser.ParseException;
/**
......@@ -28,19 +31,24 @@ import org.tautua.markdownpapers.Markdown;
* <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
*
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
* @version 1.0.0.0, Apr 28, 2012
* @version 1.0.0.1, Feb 8, 2013
* @since 0.4.5
*/
public final class Markdowns {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(Markdowns.class.getName());
/**
* Converts the specified markdown text to HTML.
*
* @param markdownText the specified markdown text
* @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}
* @throws Exception exception
* @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}, returns "Markdown error" if
* exception
*/
public static String toHTML(final String markdownText) throws Exception {
public static String toHTML(final String markdownText) {
if (Strings.isEmptyOrNull(markdownText)) {
return null;
}
......@@ -48,7 +56,13 @@ public final class Markdowns {
final StringWriter writer = new StringWriter();
final Markdown markdown = new Markdown();
try {
markdown.transform(new StringReader(markdownText), writer);
} catch (final ParseException e) {
LOGGER.log(Level.SEVERE, "Markdown error", e);
return "Markdown error";
}
return writer.toString();
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Description: B3log Solo parent POM.
Version: 2.0.2.7, Jan 15, 2013
Version: 2.0.2.8, Feb 8, 2013
Author: Liang Ding
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
......@@ -38,7 +38,7 @@
<freemarker-gae.version>2.3.19</freemarker-gae.version>
<jsoup.version>1.5.2</jsoup.version>
<markdownpapers-core.version>1.2.7</markdownpapers-core.version>
<markdownpapers-core.version>1.3.2</markdownpapers-core.version>
<!-- <com.google.api.client.version>1.2.1-alpha</com.google.api.client.version>-->
<!-- maven plugin -->
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment