Commit d4ae54a0 authored by Liang Ding's avatar Liang Ding

Markdown 支持改进 #54

parent 608548d5
......@@ -41,7 +41,7 @@ import org.json.JSONObject;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://github.com/hzchendou">hzchendou</a>
* @version 1.2.0.25, Jun 13, 2019
* @version 1.2.0.26, Jan 25, 2020
* @since 0.4.0
*/
@RequestProcessor
......@@ -243,7 +243,14 @@ public class PreferenceConsole {
* "faviconURL": "",
* "syncGitHub": boolean,
* "pullGitHub": boolean,
* "customVars" "", // 支持配置自定义参数 https://github.com/b3log/solo/issues/12535
* "customVars": "", // 支持配置自定义参数 https://github.com/b3log/solo/issues/12535
* "showCodeBlockLn": boolean, // 支持代码块行号显示 https://github.com/88250/solo/issues/4
* "footnotes": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* "showToC": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* "autoSpace": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* "fixTermTypo": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* "chinesePunct": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* "inlineMathAllowDigitAfterOpenMarker": boolean, // Markdown 支持改进 https://github.com/88250/solo/issues/54
* }
* }
* </pre>
......
......@@ -40,7 +40,7 @@ import java.util.Locale;
* Preference management service.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.4.0.4, Jan 24, 2020
* @version 1.4.0.5, Jan 25, 2020
* @since 0.4.0
*/
@Service
......@@ -221,38 +221,38 @@ public class PreferenceMgmtService {
hljsThemeOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_HLJS_THEME));
optionRepository.update(Option.ID_C_HLJS_THEME, hljsThemeOpt);
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) {
showCodeBlockLnOpt = new JSONObject();
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_VALUE, showCodeBlockLnVal);
optionRepository.add(showCodeBlockLnOpt);
} else {
showCodeBlockLnOpt.put(Option.OPTION_VALUE, showCodeBlockLnVal);
optionRepository.update(Option.ID_C_SHOW_CODE_BLOCK_LN, showCodeBlockLnOpt);
}
emptyPreferenceOptSave(Option.ID_C_SHOW_CODE_BLOCK_LN, showCodeBlockLnVal);
Markdowns.SHOW_CODE_BLOCK_LN = "true".equalsIgnoreCase(showCodeBlockLnVal);
JSONObject showToCOpt = optionRepository.get(Option.ID_C_SHOW_TOC);
final String showToCVal = preference.optString(Option.ID_C_SHOW_TOC);
if (null == showToCOpt) {
showToCOpt = new JSONObject();
showToCOpt.put(Keys.OBJECT_ID, Option.ID_C_SHOW_TOC);
showToCOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
showToCOpt.put(Option.OPTION_VALUE, showToCVal);
optionRepository.add(showToCOpt);
} else {
showToCOpt.put(Option.OPTION_VALUE, showToCVal);
optionRepository.update(Option.ID_C_SHOW_TOC, showToCOpt);
}
Markdowns.SHOW_TOC = "true".equalsIgnoreCase(showToCVal);
final JSONObject customVarsOpt = optionRepository.get(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);
final String footnotesVal = preference.optString(Option.ID_C_FOOTNOTES);
emptyPreferenceOptSave(Option.ID_C_FOOTNOTES, footnotesVal);
Markdowns.FOOTNOTES = "true".equalsIgnoreCase(footnotesVal);
final String showToCVal = preference.optString(Option.ID_C_SHOW_TOC);
emptyPreferenceOptSave(Option.ID_C_SHOW_TOC, showToCVal);
Markdowns.SHOW_TOC = "true".equalsIgnoreCase(showToCVal);
final String autoSpaceVal = preference.optString(Option.ID_C_AUTO_SPACE);
emptyPreferenceOptSave(Option.ID_C_AUTO_SPACE, autoSpaceVal);
Markdowns.AUTO_SPACE = "true".equalsIgnoreCase(autoSpaceVal);
final String fixTermTypoVal = preference.optString(Option.ID_C_FIX_TERM_TYPO);
emptyPreferenceOptSave(Option.ID_C_FIX_TERM_TYPO, fixTermTypoVal);
Markdowns.FIX_TERM_TYPO = "true".equalsIgnoreCase(fixTermTypoVal);
final String chinesePunctVal = preference.optString(Option.ID_C_CHINESE_PUNCT);
emptyPreferenceOptSave(Option.ID_C_CHINESE_PUNCT, chinesePunctVal);
Markdowns.CHINESE_PUNCT = "true".equalsIgnoreCase(chinesePunctVal);
final String IMADAOMVal = preference.optString(Option.ID_C_IMADAOM);
emptyPreferenceOptSave(Option.ID_C_IMADAOM, IMADAOMVal);
Markdowns.IMADAOM = "true".equalsIgnoreCase(IMADAOMVal);
transaction.commit();
Markdowns.clearCache();
......@@ -267,4 +267,18 @@ public class PreferenceMgmtService {
LOGGER.log(Level.DEBUG, "Updates preference successfully");
}
private void emptyPreferenceOptSave(final String optID, final String val) throws Exception {
JSONObject opt = optionRepository.get(optID);
if (null == opt) {
opt = new JSONObject();
opt.put(Keys.OBJECT_ID, optID);
opt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
opt.put(Option.OPTION_VALUE, val);
optionRepository.add(opt);
} else {
opt.put(Option.OPTION_VALUE, val);
optionRepository.update(optID, opt);
}
}
}
......@@ -188,12 +188,6 @@
<input id="showCodeBlockLn" type="checkbox" class="normalInput"/>
</div>
</label>
<label>
<div class="fn__flex-inline">
${supportToCLabel}
<input id="showToC" type="checkbox" class="normalInput"/>
</div>
</label>
</div>
<div class="fn__margin12"></div>
<div class="fn__flex-1">
......
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