Commit d952c2fc authored by Liang Ding's avatar Liang Ding

#4

parent e2793585
...@@ -300,6 +300,14 @@ public final class Server extends BaseServer { ...@@ -300,6 +300,14 @@ public final class Server extends BaseServer {
final SkinMgmtService skinMgmtService = beanManager.getReference(SkinMgmtService.class); final SkinMgmtService skinMgmtService = beanManager.getReference(SkinMgmtService.class);
skinMgmtService.loadSkins(skin); skinMgmtService.loadSkins(skin);
final JSONObject preference = optionQueryService.getPreference();
if (null == preference) {
return;
}
final String showClodeBlockLn = preference.optString(org.b3log.solo.model.Option.ID_C_SHOW_CODE_BLOCK_LN);
Markdowns.SHOW_CODE_BLOCK_LN = StringUtils.equalsIgnoreCase(showClodeBlockLn, "true");
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e); LOGGER.log(Level.ERROR, e.getMessage(), e);
......
...@@ -30,6 +30,7 @@ import org.b3log.latke.service.annotation.Service; ...@@ -30,6 +30,7 @@ import org.b3log.latke.service.annotation.Service;
import org.b3log.latke.util.Locales; import org.b3log.latke.util.Locales;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.repository.OptionRepository; import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.util.Markdowns;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Iterator; import java.util.Iterator;
...@@ -221,21 +222,26 @@ public class PreferenceMgmtService { ...@@ -221,21 +222,26 @@ public class PreferenceMgmtService {
optionRepository.update(Option.ID_C_HLJS_THEME, hljsThemeOpt); optionRepository.update(Option.ID_C_HLJS_THEME, hljsThemeOpt);
JSONObject showCodeBlockLnOpt = optionRepository.get(Option.ID_C_SHOW_CODE_BLOCK_LN); JSONObject showCodeBlockLnOpt = optionRepository.get(Option.ID_C_SHOW_CODE_BLOCK_LN);
final String showCodeBlockLnVal = preference.optString(Option.ID_C_SHOW_CODE_BLOCK_LN);
if (null == showCodeBlockLnOpt) { if (null == showCodeBlockLnOpt) {
showCodeBlockLnOpt = new JSONObject(); showCodeBlockLnOpt = new JSONObject();
showCodeBlockLnOpt.put(Keys.OBJECT_ID, Option.ID_C_SHOW_CODE_BLOCK_LN); showCodeBlockLnOpt.put(Keys.OBJECT_ID, Option.ID_C_SHOW_CODE_BLOCK_LN);
showCodeBlockLnOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE); showCodeBlockLnOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
showCodeBlockLnOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SHOW_CODE_BLOCK_LN)); showCodeBlockLnOpt.put(Option.OPTION_VALUE, showCodeBlockLnVal);
optionRepository.add(showCodeBlockLnOpt); optionRepository.add(showCodeBlockLnOpt);
} else { } else {
showCodeBlockLnOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SHOW_CODE_BLOCK_LN)); showCodeBlockLnOpt.put(Option.OPTION_VALUE, showCodeBlockLnVal);
optionRepository.update(Option.ID_C_SHOW_CODE_BLOCK_LN, showCodeBlockLnOpt); optionRepository.update(Option.ID_C_SHOW_CODE_BLOCK_LN, showCodeBlockLnOpt);
} }
Markdowns.SHOW_CODE_BLOCK_LN = "true".equalsIgnoreCase(showCodeBlockLnVal);
final JSONObject customVarsOpt = optionRepository.get(Option.ID_C_CUSTOM_VARS); final JSONObject customVarsOpt = optionRepository.get(Option.ID_C_CUSTOM_VARS);
customVarsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_CUSTOM_VARS)); customVarsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_CUSTOM_VARS));
optionRepository.update(Option.ID_C_CUSTOM_VARS, customVarsOpt); optionRepository.update(Option.ID_C_CUSTOM_VARS, customVarsOpt);
transaction.commit(); transaction.commit();
Markdowns.clearCache();
} catch (final Exception e) { } catch (final Exception e) {
if (transaction.isActive()) { if (transaction.isActive()) {
transaction.rollback(); transaction.rollback();
......
...@@ -60,7 +60,7 @@ import java.util.concurrent.*; ...@@ -60,7 +60,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.11, Jan 17, 2020 * @version 2.3.1.12, Jan 18, 2020
* @since 0.4.5 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
...@@ -112,6 +112,15 @@ public final class Markdowns { ...@@ -112,6 +112,15 @@ public final class Markdowns {
*/ */
public static boolean LUTE_AVAILABLE; public static boolean LUTE_AVAILABLE;
public static boolean SHOW_CODE_BLOCK_LN = false;
/**
* Clears cache.
*/
public static void clearCache() {
MD_CACHE.clear();
}
/** /**
* Cleans the specified HTML. * Cleans the specified HTML.
* *
...@@ -258,6 +267,7 @@ public final class Markdowns { ...@@ -258,6 +267,7 @@ public final class Markdowns {
private static String toHtmlByLute(final String markdownText) throws Exception { private static String toHtmlByLute(final String markdownText) throws Exception {
final URL url = new URL(LUTE_ENGINE_URL); final URL url = new URL(LUTE_ENGINE_URL);
final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("X-CodeSyntaxHighlightLineNum", String.valueOf(Markdowns.SHOW_CODE_BLOCK_LN));
conn.setConnectTimeout(100); conn.setConnectTimeout(100);
conn.setReadTimeout(1000); conn.setReadTimeout(1000);
conn.setDoOutput(true); conn.setDoOutput(true);
......
This diff is collapsed.
This diff is collapsed.
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