Commit bc6fa3b4 authored by Liang Ding's avatar Liang Ding

merge

parents c55d2083 21061996
# [Solo](https://github.com/b3log/solo) [![Build Status](https://img.shields.io/travis/b3log/solo.svg?style=flat)](https://travis-ci.org/b3log/solo) [![Coverage Status](https://img.shields.io/coveralls/b3log/b3log-solo.svg?style=flat)](https://coveralls.io/r/b3log/b3log-solo) [![Apache License](http://img.shields.io/badge/license-apache2-orange.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](http://img.shields.io/badge/download-~5K-blue.svg?style=flat)](http://pan.baidu.com/share/link?shareid=541735&uk=3255126224) # [Solo](https://github.com/b3log/solo) [![Build Status](https://img.shields.io/travis/b3log/solo.svg?style=flat)](https://travis-ci.org/b3log/solo) [![Coverage Status](https://img.shields.io/coveralls/b3log/solo.svg?style=flat)](https://coveralls.io/github/b3log/solo?branch=master) [![Apache License](http://img.shields.io/badge/license-apache2-orange.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0) [![Download](http://img.shields.io/badge/download-~5K-blue.svg?style=flat)](http://pan.baidu.com/share/link?shareid=541735&uk=3255126224)
<img src="https://cloud.githubusercontent.com/assets/873584/6817919/72ffdb5c-d2e2-11e4-8be8-37ac1b08ff81.jpg" width="96%" /> <img src="https://cloud.githubusercontent.com/assets/873584/6817919/72ffdb5c-d2e2-11e4-8be8-37ac1b08ff81.jpg" width="96%" />
......
...@@ -64,7 +64,7 @@ public class ListHandler extends AbstractEventListener<JSONObject> { ...@@ -64,7 +64,7 @@ public class ListHandler extends AbstractEventListener<JSONObject> {
final StringBuilder listBuilder = new StringBuilder(); final StringBuilder listBuilder = new StringBuilder();
listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticPath() + "/plugins/list/style.css\" />"); listBuilder.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + Latkes.getStaticServePath() + "/plugins/list/style.css\" />");
final Elements hs = doc.select("h1, h2, h3, h4, h5"); final Elements hs = doc.select("h1, h2, h3, h4, h5");
......
...@@ -15,27 +15,24 @@ ...@@ -15,27 +15,24 @@
*/ */
package org.b3log.solo.util; package org.b3log.solo.util;
import org.apache.commons.lang.StringUtils;
import java.io.StringReader;
import java.io.StringWriter;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.util.Strings; import org.b3log.latke.util.Strings;
import org.tautua.markdownpapers.Markdown; import org.pegdown.Extensions;
import org.tautua.markdownpapers.parser.ParseException; import org.pegdown.PegDownProcessor;
/** /**
* <a href="http://en.wikipedia.org/wiki/Markdown">Markdown</a> utilities. * <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> * <p>
* Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Feb 8, 2013 * @version 2.0.0.1, May 16, 2016
* @since 0.4.5 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
/** /**
* Logger. * Logger.
*/ */
...@@ -43,32 +40,29 @@ public final class Markdowns { ...@@ -43,32 +40,29 @@ public final class Markdowns {
/** /**
* Converts the specified markdown text to HTML. * Converts the specified markdown text to HTML.
* *
* @param markdownText the specified markdown text * @param markdownText the specified markdown text
* @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}, returns "Markdown error" if * @return converted HTML, returns {@code null} if the specified markdown text is "" or {@code null}, returns
* exception * "Markdown error" if exception
*/ */
public static String toHTML(final String markdownText) { public static String toHTML(final String markdownText) {
if (Strings.isEmptyOrNull(markdownText)) { if (Strings.isEmptyOrNull(markdownText)) {
return null; return "";
} }
final StringWriter writer = new StringWriter(); final PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.ALL, 5000);
final Markdown markdown = new Markdown(); String ret = pegDownProcessor.markdownToHtml(markdownText);
try { if (!StringUtils.startsWith(ret, "<p>")) {
markdown.transform(new StringReader(markdownText), writer); ret = "<p>" + ret + "</p>";
} catch (final ParseException e) {
LOGGER.log(Level.ERROR, "Markdown error", e);
return "Markdown error";
} }
return writer.toString(); return ret;
} }
/** /**
* Private constructor. * Private constructor.
*/ */
private Markdowns() {} private Markdowns() {
}
} }
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
# Browser visit protocol # Browser visit protocol
serverScheme=http serverScheme=http
# Browser visit domain name # Browser visit domain name
serverHost=192.168.20.8 serverHost=localhost
# Browser visit port, 80 as usual, THIS IS NOT SERVER LISTEN PORT! # Browser visit port, 80 as usual, THIS IS NOT SERVER LISTEN PORT!
serverPort=8080 serverPort=8080
......
...@@ -21,20 +21,20 @@ ...@@ -21,20 +21,20 @@
# #
#### H2 runtime #### #### H2 runtime ####
#runtimeDatabase=H2 runtimeDatabase=H2
#jdbc.username=root
#jdbc.password=
#jdbc.driver=org.h2.Driver
#jdbc.URL=jdbc:h2:~/b3log_solo_h2/db
#jdbc.pool=h2
#### MySQL runtime ####
runtimeDatabase=MYSQL
jdbc.username=root jdbc.username=root
jdbc.password= jdbc.password=
jdbc.driver=com.mysql.jdbc.Driver jdbc.driver=org.h2.Driver
jdbc.URL=jdbc:mysql://localhost:3306/b3log?useUnicode=yes&characterEncoding=utf8 jdbc.URL=jdbc:h2:~/b3log_solo_h2/db
jdbc.pool=druid jdbc.pool=h2
#### MySQL runtime ####
#runtimeDatabase=MYSQL
#jdbc.username=root
#jdbc.password=
#jdbc.driver=com.mysql.jdbc.Driver
#jdbc.URL=jdbc:mysql://localhost:3306/b3log?useUnicode=yes&characterEncoding=utf8
#jdbc.pool=druid
# The minConnCnt MUST larger or equal to 3 # The minConnCnt MUST larger or equal to 3
jdbc.minConnCnt=5 jdbc.minConnCnt=5
......
...@@ -29,7 +29,7 @@ import org.testng.Assert; ...@@ -29,7 +29,7 @@ import org.testng.Assert;
* {@link org.b3log.solo.util.Markdowns} test case. * {@link org.b3log.solo.util.Markdowns} test case.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, May 16, 2013 * @version 1.0.1.2, May 18, 2016
* @since 0.4.5 * @since 0.4.5
*/ */
public final class MarkdownsTestCase { public final class MarkdownsTestCase {
...@@ -44,7 +44,7 @@ public final class MarkdownsTestCase { ...@@ -44,7 +44,7 @@ public final class MarkdownsTestCase {
String markdownText = ""; String markdownText = "";
String html = Markdowns.toHTML(markdownText); String html = Markdowns.toHTML(markdownText);
Assert.assertNull(html); Assert.assertEquals(html, "");
markdownText = "# Solo Markdown Editor"; markdownText = "# Solo Markdown Editor";
html = Markdowns.toHTML(markdownText); html = Markdowns.toHTML(markdownText);
......
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