Commit 493a8f97 authored by Liang Ding's avatar Liang Ding

Merge branch 'master' into 3.6.5-dev

parents 8fe1aebc 6b4c5201
......@@ -59,7 +59,7 @@ import javax.servlet.http.HttpSessionEvent;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Vanessa</a>
* @version 1.11.0.22, Aug 18, 2019
* @version 1.11.0.23, Sep 17, 2019
* @since 0.3.1
*/
public final class SoloServletListener extends AbstractServletListener {
......@@ -94,10 +94,10 @@ public final class SoloServletListener extends AbstractServletListener {
final Latkes.RuntimeMode runtimeMode = Latkes.getRuntimeMode();
final String jdbcUsername = Latkes.getLocalProperty("jdbc.username");
final String jdbcURL = Latkes.getLocalProperty("jdbc.URL");
final boolean markdownHttpAvailable = Markdowns.MARKDOWN_HTTP_AVAILABLE;
final boolean luteAvailable = Markdowns.LUTE_AVAILABLE;
LOGGER.log(Level.INFO, "Solo is booting [ver=" + VERSION + ", servletContainer=" + Latkes.getServletInfo(servletContextEvent.getServletContext())
+ ", os=" + Latkes.getOperatingSystemName() + ", isDocker=" + Latkes.isDocker() + ", markdownHttpAvailable=" + markdownHttpAvailable + ", pid=" + Latkes.currentPID()
+ ", os=" + Latkes.getOperatingSystemName() + ", isDocker=" + Latkes.isDocker() + ", luteAvailable=" + luteAvailable + ", pid=" + Latkes.currentPID()
+ ", runtimeDatabase=" + runtimeDatabase + ", runtimeMode=" + runtimeMode + ", jdbc.username=" + jdbcUsername + ", jdbc.URL=" + jdbcURL + "]");
validateSkin();
......
......@@ -22,7 +22,7 @@ package org.b3log.solo.model;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/e">Dongxu Wang</a>
* @version 1.7.0.5, Mar 29, 2019
* @version 1.7.0.6, Sep 17, 2019
* @since 0.3.1
*/
public final class Common {
......@@ -68,9 +68,9 @@ public final class Common {
public static final String UPLOAD_TOKEN = "uploadToken";
/**
* Key of marked engine available.
* Key of Lute engine available.
*/
public static final String MARKED_AVAILABLE = "markedAvailable";
public static final String LUTE_AVAILABLE = "luteAvailable";
/**
* Key of keyword.
......
......@@ -66,7 +66,7 @@ import java.util.*;
* Admin console render processing.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.7.0.15, Jul 13, 2019
* @version 1.7.0.16, Sep 17, 2019
* @since 0.4.1
*/
@Singleton
......@@ -147,8 +147,7 @@ public class AdminConsole {
dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.ID_C_SKIN_DIR_NAME));
Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614
dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE);
dataModel.put(Common.LUTE_AVAILABLE, Markdowns.LUTE_AVAILABLE);
// 内置 HTTPS+CDN 文件存储 https://github.com/b3log/solo/issues/12556
dataModel.put(Common.UPLOAD_TOKEN, "");
dataModel.put(Common.UPLOAD_URL, "");
......
......@@ -59,7 +59,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.7.0.10, Apr 22, 2019
* @version 1.7.0.11, Sep 17, 2019
* @since 0.3.1
*/
@Service
......@@ -597,9 +597,7 @@ public class DataModelService {
}
dataModel.put("customVars", customVars);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614
dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE);
dataModel.put(Common.LUTE_AVAILABLE, Markdowns.LUTE_AVAILABLE);
String hljsTheme = preference.optString(Option.ID_C_HLJS_THEME);
if (StringUtils.isBlank(hljsTheme)) {
hljsTheme = Option.DefaultPreference.DEFAULT_HLJS_THEME;
......
......@@ -58,7 +58,7 @@ import java.util.concurrent.*;
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.3.1.8, Jul 29, 2019
* @version 2.3.1.9, Sep 17, 2019
* @since 0.4.5
*/
public final class Markdowns {
......@@ -101,42 +101,24 @@ public final class Markdowns {
private static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build();
/**
* Markdown engine serve path.
* Lute engine serve path. https://github.com/b3log/lute
*/
private static final String MARKDOWN_ENGINE_URL = "http://localhost:8250";
private static final String LUTE_ENGINE_URL = "http://localhost:8249";
/**
* Whether markdown-http is available.
* Whether Lute is available.
*/
public static boolean MARKDOWN_HTTP_AVAILABLE;
public static boolean LUTE_AVAILABLE;
static {
try {
final URL url = new URL(MARKDOWN_ENGINE_URL);
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
try (final OutputStream outputStream = conn.getOutputStream()) {
IOUtils.write("昔日舞曲", outputStream, "UTF-8");
}
String html;
try (final InputStream inputStream = conn.getInputStream()) {
html = IOUtils.toString(inputStream, "UTF-8");
}
conn.disconnect();
MARKDOWN_HTTP_AVAILABLE = StringUtils.contains(html, "<p>昔日舞曲</p>");
if (MARKDOWN_HTTP_AVAILABLE) {
LOGGER.log(Level.INFO, "[markdown-http] is available, uses it for markdown processing");
} else {
LOGGER.log(Level.INFO, "[markdown-http] is not available, uses built-in [flexmark] for markdown processing");
final String html = toHtmlByLute("旧日的足迹");
LUTE_AVAILABLE = StringUtils.contains(html, "<p>旧日的足迹</p>");
if (LUTE_AVAILABLE) {
LOGGER.log(Level.INFO, "[Lute] is available");
}
} catch (final Exception e) {
LOGGER.log(Level.INFO, "[markdown-http] is not available, uses built-in [flexmark] for markdown processing. " +
"Please read FAQ section in user guide (https://hacpai.com/article/1492881378588) for more details.");
// ignored
}
}
......@@ -177,31 +159,23 @@ public final class Markdowns {
final Callable<String> call = () -> {
threadId[0] = Thread.currentThread().getId();
String html = langPropsService.get("contentRenderFailedLabel");
if (MARKDOWN_HTTP_AVAILABLE) {
String html = null;
if (LUTE_AVAILABLE) {
try {
html = toHtmlByMarkdownHTTP(markdownText);
if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>";
}
html = toHtmlByLute(markdownText);
} catch (final Exception e) {
LOGGER.log(Level.WARN, "Failed to use [markdown-http] for markdown [md=" + StringUtils.substring(markdownText, 0, 256) + "]: " + e.getMessage());
com.vladsch.flexmark.util.ast.Node document = PARSER.parse(markdownText);
html = RENDERER.render(document);
if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>";
}
}
} else {
com.vladsch.flexmark.util.ast.Node document = PARSER.parse(markdownText);
html = RENDERER.render(document);
if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>";
LOGGER.log(Level.WARN, "Failed to use [Lute] for markdown [md=" + StringUtils.substring(markdownText, 0, 256) + "]: " + e.getMessage());
}
}
if (StringUtils.isBlank(html)) {
html = toHtmlByFlexmark(markdownText);
}
if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>";
}
final Document doc = Jsoup.parse(html);
doc.select("a").forEach(a -> {
final String src = a.attr("href");
......@@ -291,9 +265,11 @@ public final class Markdowns {
return langPropsService.get("contentRenderFailedLabel");
}
private static String toHtmlByMarkdownHTTP(final String markdownText) throws Exception {
final URL url = new URL(MARKDOWN_ENGINE_URL);
private static String toHtmlByLute(final String markdownText) throws Exception {
final URL url = new URL(LUTE_ENGINE_URL);
final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(7000);
conn.setDoOutput(true);
try (final OutputStream outputStream = conn.getOutputStream()) {
......@@ -305,11 +281,17 @@ public final class Markdowns {
ret = IOUtils.toString(inputStream, "UTF-8");
}
//conn.disconnect();
conn.disconnect();
return ret;
}
private static String toHtmlByFlexmark(final String markdownText) {
com.vladsch.flexmark.util.ast.Node document = PARSER.parse(markdownText);
return RENDERER.render(document);
}
/**
* Gets HTML for the specified markdown text.
*
......
......@@ -21,7 +21,7 @@
var Label = {
servePath: "${servePath}",
staticServePath: "${staticServePath}",
markedAvailable: ${markedAvailable?c},
luteAvailable: ${luteAvailable?c},
hljsStyle: '${hljsTheme}',
langLabel: "${langLabel}",
version: "${version}",
......
......@@ -150,7 +150,7 @@ var Util = {
if ($('.vditor-reset pre > code').length === 0) {
return
}
Vditor.highlightRender(Label.hljsStyle, !Label.markedAvailable, document)
Vditor.highlightRender(Label.hljsStyle, !Label.luteAvailable, document)
},
/**
* 按需加载数学公式、流程图、代码复制、五线谱、多媒体、图表
......
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