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; ...@@ -59,7 +59,7 @@ import javax.servlet.http.HttpSessionEvent;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Vanessa</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 * @since 0.3.1
*/ */
public final class SoloServletListener extends AbstractServletListener { public final class SoloServletListener extends AbstractServletListener {
...@@ -94,10 +94,10 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -94,10 +94,10 @@ public final class SoloServletListener extends AbstractServletListener {
final Latkes.RuntimeMode runtimeMode = Latkes.getRuntimeMode(); final Latkes.RuntimeMode runtimeMode = Latkes.getRuntimeMode();
final String jdbcUsername = Latkes.getLocalProperty("jdbc.username"); final String jdbcUsername = Latkes.getLocalProperty("jdbc.username");
final String jdbcURL = Latkes.getLocalProperty("jdbc.URL"); 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()) 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 + "]"); + ", runtimeDatabase=" + runtimeDatabase + ", runtimeMode=" + runtimeMode + ", jdbc.username=" + jdbcUsername + ", jdbc.URL=" + jdbcURL + "]");
validateSkin(); validateSkin();
......
...@@ -22,7 +22,7 @@ package org.b3log.solo.model; ...@@ -22,7 +22,7 @@ package org.b3log.solo.model;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/e">Dongxu Wang</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 * @since 0.3.1
*/ */
public final class Common { public final class Common {
...@@ -68,9 +68,9 @@ public final class Common { ...@@ -68,9 +68,9 @@ public final class Common {
public static final String UPLOAD_TOKEN = "uploadToken"; 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. * Key of keyword.
......
...@@ -66,7 +66,7 @@ import java.util.*; ...@@ -66,7 +66,7 @@ import java.util.*;
* Admin console render processing. * Admin console render processing.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.1
*/ */
@Singleton @Singleton
...@@ -147,8 +147,7 @@ public class AdminConsole { ...@@ -147,8 +147,7 @@ public class AdminConsole {
dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.ID_C_SKIN_DIR_NAME)); dataModel.put(Option.CATEGORY_C_SKIN, skin.optString(Option.ID_C_SKIN_DIR_NAME));
Keys.fillRuntime(dataModel); Keys.fillRuntime(dataModel);
dataModelService.fillMinified(dataModel); dataModelService.fillMinified(dataModel);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614 dataModel.put(Common.LUTE_AVAILABLE, Markdowns.LUTE_AVAILABLE);
dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE);
// 内置 HTTPS+CDN 文件存储 https://github.com/b3log/solo/issues/12556 // 内置 HTTPS+CDN 文件存储 https://github.com/b3log/solo/issues/12556
dataModel.put(Common.UPLOAD_TOKEN, ""); dataModel.put(Common.UPLOAD_TOKEN, "");
dataModel.put(Common.UPLOAD_URL, ""); dataModel.put(Common.UPLOAD_URL, "");
......
...@@ -59,7 +59,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT; ...@@ -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://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</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 * @since 0.3.1
*/ */
@Service @Service
...@@ -597,9 +597,7 @@ public class DataModelService { ...@@ -597,9 +597,7 @@ public class DataModelService {
} }
dataModel.put("customVars", customVars); dataModel.put("customVars", customVars);
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614 dataModel.put(Common.LUTE_AVAILABLE, Markdowns.LUTE_AVAILABLE);
dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE);
String hljsTheme = preference.optString(Option.ID_C_HLJS_THEME); String hljsTheme = preference.optString(Option.ID_C_HLJS_THEME);
if (StringUtils.isBlank(hljsTheme)) { if (StringUtils.isBlank(hljsTheme)) {
hljsTheme = Option.DefaultPreference.DEFAULT_HLJS_THEME; hljsTheme = Option.DefaultPreference.DEFAULT_HLJS_THEME;
......
...@@ -58,7 +58,7 @@ import java.util.concurrent.*; ...@@ -58,7 +58,7 @@ import java.util.concurrent.*;
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @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 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
...@@ -101,42 +101,24 @@ public final class Markdowns { ...@@ -101,42 +101,24 @@ public final class Markdowns {
private static final HtmlRenderer RENDERER = HtmlRenderer.builder(OPTIONS).build(); 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 { static {
try { try {
final URL url = new URL(MARKDOWN_ENGINE_URL); final String html = toHtmlByLute("旧日的足迹");
final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); LUTE_AVAILABLE = StringUtils.contains(html, "<p>旧日的足迹</p>");
conn.setDoOutput(true); if (LUTE_AVAILABLE) {
LOGGER.log(Level.INFO, "[Lute] is available");
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");
} }
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.INFO, "[markdown-http] is not available, uses built-in [flexmark] for markdown processing. " + // ignored
"Please read FAQ section in user guide (https://hacpai.com/article/1492881378588) for more details.");
} }
} }
...@@ -177,30 +159,22 @@ public final class Markdowns { ...@@ -177,30 +159,22 @@ public final class Markdowns {
final Callable<String> call = () -> { final Callable<String> call = () -> {
threadId[0] = Thread.currentThread().getId(); threadId[0] = Thread.currentThread().getId();
String html = langPropsService.get("contentRenderFailedLabel"); String html = null;
if (LUTE_AVAILABLE) {
if (MARKDOWN_HTTP_AVAILABLE) {
try { try {
html = toHtmlByMarkdownHTTP(markdownText); html = toHtmlByLute(markdownText);
if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>";
}
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.WARN, "Failed to use [markdown-http] for markdown [md=" + StringUtils.substring(markdownText, 0, 256) + "]: " + e.getMessage()); LOGGER.log(Level.WARN, "Failed to use [Lute] 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); if (StringUtils.isBlank(html)) {
html = RENDERER.render(document); html = toHtmlByFlexmark(markdownText);
}
if (!StringUtils.startsWith(html, "<p>")) { if (!StringUtils.startsWith(html, "<p>")) {
html = "<p>" + html + "</p>"; html = "<p>" + html + "</p>";
} }
}
final Document doc = Jsoup.parse(html); final Document doc = Jsoup.parse(html);
doc.select("a").forEach(a -> { doc.select("a").forEach(a -> {
...@@ -291,9 +265,11 @@ public final class Markdowns { ...@@ -291,9 +265,11 @@ public final class Markdowns {
return langPropsService.get("contentRenderFailedLabel"); return langPropsService.get("contentRenderFailedLabel");
} }
private static String toHtmlByMarkdownHTTP(final String markdownText) throws Exception { private static String toHtmlByLute(final String markdownText) throws Exception {
final URL url = new URL(MARKDOWN_ENGINE_URL); final URL url = new URL(LUTE_ENGINE_URL);
final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(1000);
conn.setReadTimeout(7000);
conn.setDoOutput(true); conn.setDoOutput(true);
try (final OutputStream outputStream = conn.getOutputStream()) { try (final OutputStream outputStream = conn.getOutputStream()) {
...@@ -305,11 +281,17 @@ public final class Markdowns { ...@@ -305,11 +281,17 @@ public final class Markdowns {
ret = IOUtils.toString(inputStream, "UTF-8"); ret = IOUtils.toString(inputStream, "UTF-8");
} }
//conn.disconnect(); conn.disconnect();
return ret; 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. * Gets HTML for the specified markdown text.
* *
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
var Label = { var Label = {
servePath: "${servePath}", servePath: "${servePath}",
staticServePath: "${staticServePath}", staticServePath: "${staticServePath}",
markedAvailable: ${markedAvailable?c}, luteAvailable: ${luteAvailable?c},
hljsStyle: '${hljsTheme}', hljsStyle: '${hljsTheme}',
langLabel: "${langLabel}", langLabel: "${langLabel}",
version: "${version}", version: "${version}",
......
...@@ -150,7 +150,7 @@ var Util = { ...@@ -150,7 +150,7 @@ var Util = {
if ($('.vditor-reset pre > code').length === 0) { if ($('.vditor-reset pre > code').length === 0) {
return 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