Commit cc1d3e63 authored by Liang Ding's avatar Liang Ding

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

parent 6391464a
...@@ -913,13 +913,15 @@ public final class Filler { ...@@ -913,13 +913,15 @@ public final class Filler {
} }
/** /**
* Processes the abstract of the specified article with the specified * Processes the abstract of the specified article with the specified preference.
* preference.
* *
* <p> <ul> <li>If the abstract is {@code null}, sets it with ""</li> <li>If * <p>
* user configured preference "titleOnly", sets the abstract with ""</li> * <ul>
* <li>If user configured preference "titleAndContent", sets the abstract * <li>If the abstract is {@code null}, sets it with ""</li>
* with the content of the article</li> </ul> </p> * <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 preference the specified preference
* @param article the specified article * @param article the specified article
......
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, 2013, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import java.io.StringReader; import java.io.StringReader;
import java.io.StringWriter; import java.io.StringWriter;
import org.b3log.latke.util.Strings; import java.util.logging.Level;
import org.tautua.markdownpapers.Markdown; import java.util.logging.Logger;
import org.b3log.latke.util.Strings;
import org.tautua.markdownpapers.Markdown;
/** import org.tautua.markdownpapers.parser.ParseException;
* <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities.
*
* <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p> /**
* * <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities.
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> *
* @version 1.0.0.0, Apr 28, 2012 * <p>Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
* @since 0.4.5 *
*/ * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
public final class Markdowns { * @version 1.0.0.1, Feb 8, 2013
* @since 0.4.5
/** */
* Converts the specified markdown text to HTML. public final class Markdowns {
*
* @param markdownText the specified markdown text /**
* @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null} * Logger.
* @throws Exception exception */
*/ private static final Logger LOGGER = Logger.getLogger(Markdowns.class.getName());
public static String toHTML(final String markdownText) throws Exception {
if (Strings.isEmptyOrNull(markdownText)) { /**
return null; * Converts the specified markdown text to HTML.
} *
* @param markdownText the specified markdown text
final StringWriter writer = new StringWriter(); * @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}, returns "Markdown error" if
final Markdown markdown = new Markdown(); * exception
*/
markdown.transform(new StringReader(markdownText), writer); public static String toHTML(final String markdownText) {
if (Strings.isEmptyOrNull(markdownText)) {
return writer.toString(); return null;
} }
/** final StringWriter writer = new StringWriter();
* Private constructor. final Markdown markdown = new Markdown();
*/
private Markdowns() {} try {
} markdown.transform(new StringReader(markdownText), writer);
} catch (final ParseException e) {
LOGGER.log(Level.SEVERE, "Markdown error", e);
return "Markdown error";
}
return writer.toString();
}
/**
* Private constructor.
*/
private Markdowns() {}
}
This diff is collapsed.
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