Commit 2e7b6690 authored by Liang Ding's avatar Liang Ding

Markdown 支持 [ToC] #52

parent cb90a05e
...@@ -47,7 +47,7 @@ import org.json.JSONObject; ...@@ -47,7 +47,7 @@ import org.json.JSONObject;
* Server. * Server.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.8, Jan 13, 2020 * @version 2.0.0.9, Jan 24, 2020
* @since 1.2.0 * @since 1.2.0
*/ */
public final class Server extends BaseServer { public final class Server extends BaseServer {
...@@ -308,6 +308,8 @@ public final class Server extends BaseServer { ...@@ -308,6 +308,8 @@ public final class Server extends BaseServer {
final String showClodeBlockLn = preference.optString(org.b3log.solo.model.Option.ID_C_SHOW_CODE_BLOCK_LN); 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"); Markdowns.SHOW_CODE_BLOCK_LN = StringUtils.equalsIgnoreCase(showClodeBlockLn, "true");
final String showToC = preference.optString(org.b3log.solo.model.Option.ID_C_SHOW_TOC);
Markdowns.SHOW_TOC = StringUtils.equalsIgnoreCase(showToC, "true");
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, e.getMessage(), e); LOGGER.log(Level.ERROR, e.getMessage(), e);
......
...@@ -26,7 +26,7 @@ import org.json.JSONObject; ...@@ -26,7 +26,7 @@ import org.json.JSONObject;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://github.com/hzchendou">hzchendou</a> * @author <a href="https://github.com/hzchendou">hzchendou</a>
* @version 1.6.0.3, Jan 18, 2020 * @version 1.6.0.4, Jan 24, 2020
* @since 0.6.0 * @since 0.6.0
*/ */
public final class Option { public final class Option {
...@@ -53,7 +53,12 @@ public final class Option { ...@@ -53,7 +53,12 @@ public final class Option {
// oId constants // oId constants
/** /**
* Key of code block line num show flag. 支持代码块行号显示 https://github.com/88250/solo/issues/4 * Key of show ToC flag. 支持 ToC 显示 https://github.com/88250/solo/issues/52
*/
public static final String ID_C_SHOW_TOC = "showToC";
/**
* Key of show code block line num flag. 支持代码块行号显示 https://github.com/88250/solo/issues/4
*/ */
public static final String ID_C_SHOW_CODE_BLOCK_LN = "showCodeBlockLn"; public static final String ID_C_SHOW_CODE_BLOCK_LN = "showCodeBlockLn";
......
...@@ -40,7 +40,7 @@ import java.util.Locale; ...@@ -40,7 +40,7 @@ import java.util.Locale;
* Preference management service. * Preference management service.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.4.0.3, Jan 18, 2020 * @version 1.4.0.4, Jan 24, 2020
* @since 0.4.0 * @since 0.4.0
*/ */
@Service @Service
...@@ -235,6 +235,20 @@ public class PreferenceMgmtService { ...@@ -235,6 +235,20 @@ public class PreferenceMgmtService {
} }
Markdowns.SHOW_CODE_BLOCK_LN = "true".equalsIgnoreCase(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); 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);
......
...@@ -22,6 +22,7 @@ import com.vladsch.flexmark.ext.footnotes.FootnoteExtension; ...@@ -22,6 +22,7 @@ import com.vladsch.flexmark.ext.footnotes.FootnoteExtension;
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension; import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension;
import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension; import com.vladsch.flexmark.ext.gfm.tasklist.TaskListExtension;
import com.vladsch.flexmark.ext.tables.TablesExtension; import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.ext.toc.TocExtension;
import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.util.data.DataHolder; import com.vladsch.flexmark.util.data.DataHolder;
import com.vladsch.flexmark.util.data.MutableDataSet; import com.vladsch.flexmark.util.data.MutableDataSet;
...@@ -61,7 +62,7 @@ import java.util.concurrent.*; ...@@ -61,7 +62,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.13, Jan 20, 2020 * @version 2.3.1.14, Jan 24, 2020
* @since 0.4.5 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
...@@ -115,6 +116,7 @@ public final class Markdowns { ...@@ -115,6 +116,7 @@ public final class Markdowns {
public static boolean LUTE_AVAILABLE; public static boolean LUTE_AVAILABLE;
public static boolean SHOW_CODE_BLOCK_LN = false; public static boolean SHOW_CODE_BLOCK_LN = false;
public static boolean SHOW_TOC = false;
/** /**
* Clears cache. * Clears cache.
...@@ -270,6 +272,7 @@ public final class Markdowns { ...@@ -270,6 +272,7 @@ public final class Markdowns {
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.setRequestProperty("X-CodeSyntaxHighlightLineNum", String.valueOf(Markdowns.SHOW_CODE_BLOCK_LN));
conn.setRequestProperty("X-ToC", String.valueOf(Markdowns.SHOW_TOC));
conn.setConnectTimeout(100); conn.setConnectTimeout(100);
conn.setReadTimeout(1000); conn.setReadTimeout(1000);
conn.setDoOutput(true); conn.setDoOutput(true);
......
...@@ -183,6 +183,12 @@ ...@@ -183,6 +183,12 @@
<input id="showCodeBlockLn" type="checkbox" class="normalInput"/> <input id="showCodeBlockLn" type="checkbox" class="normalInput"/>
</div> </div>
</label> </label>
<label>
<div class="fn__flex-inline">
${showToCLabel}
<input id="showToC" type="checkbox" class="normalInput"/>
</div>
</label>
</div> </div>
<div class="fn__margin12"></div> <div class="fn__margin12"></div>
<div class="fn__flex-1"> <div class="fn__flex-1">
......
This diff is collapsed.
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* *
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.0.3, Aug 18, 2019 * @version 1.3.0.4, Jan 24, 2020
*/ */
/* preference 相关操作 */ /* preference 相关操作 */
...@@ -78,6 +78,7 @@ admin.preference = { ...@@ -78,6 +78,7 @@ admin.preference = {
'true' === preference.syncGitHub ? $('#syncGitHub').attr('checked', 'checked') : $('syncGitHub').removeAttr('checked') 'true' === preference.syncGitHub ? $('#syncGitHub').attr('checked', 'checked') : $('syncGitHub').removeAttr('checked')
'true' === preference.pullGitHub ? $('#pullGitHub').attr('checked', 'checked') : $('pullGitHub').removeAttr('checked') 'true' === preference.pullGitHub ? $('#pullGitHub').attr('checked', 'checked') : $('pullGitHub').removeAttr('checked')
'true' === preference.showCodeBlockLn ? $('#showCodeBlockLn').attr('checked', 'checked') : $('showCodeBlockLn').removeAttr('checked') 'true' === preference.showCodeBlockLn ? $('#showCodeBlockLn').attr('checked', 'checked') : $('showCodeBlockLn').removeAttr('checked')
'true' === preference.showToC ? $('#showToC').attr('checked', 'checked') : $('showToC').removeAttr('checked')
admin.preference.locale = preference.localeString admin.preference.locale = preference.localeString
...@@ -228,6 +229,7 @@ admin.preference = { ...@@ -228,6 +229,7 @@ admin.preference = {
'syncGitHub': $('#syncGitHub').prop('checked'), 'syncGitHub': $('#syncGitHub').prop('checked'),
'pullGitHub': $('#pullGitHub').prop('checked'), 'pullGitHub': $('#pullGitHub').prop('checked'),
'showCodeBlockLn': $('#showCodeBlockLn').prop('checked'), 'showCodeBlockLn': $('#showCodeBlockLn').prop('checked'),
'showToC': $('#showToC').prop('checked'),
'commentable': $('#commentable').prop('checked'), 'commentable': $('#commentable').prop('checked'),
'customVars': $('#customVars').val(), 'customVars': $('#customVars').val(),
}, },
......
This diff is collapsed.
This diff is collapsed.
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
# #
# Description: Solo language configurations(en_US). # Description: Solo language configurations(en_US).
# Version: 2.37.0.0, Jan 13, 2020 # Version: 2.38.0.0, Jan 24, 2020
# Author: Liang Ding # Author: Liang Ding
# Author: Liyuan Li # Author: Liyuan Li
# Author: Dongxu Wang # Author: Dongxu Wang
# #
showToCLabel=Support Markdown [ToC]:
showCodeBlockLnLabel=Show code block line num: showCodeBlockLnLabel=Show code block line num:
siteURLLabel=Site URL: siteURLLabel=Site URL:
siteGenedLabel=Site generated, target dir is [{dir}] siteGenedLabel=Site generated, target dir is [{dir}]
......
...@@ -18,12 +18,13 @@ ...@@ -18,12 +18,13 @@
# #
# Description: Solo default language configurations(zh_CN). # Description: Solo default language configurations(zh_CN).
# Version: 2.37.0.0, Jan 13, 2020 # Version: 2.38.0.0, Jan 24, 2020
# Author: Liang Ding # Author: Liang Ding
# Author: Liyuan Li # Author: Liyuan Li
# Author: Dongxu Wang # Author: Dongxu Wang
# #
showToCLabel=\u652F\u6301 Markdown [ToC]\uFF1A
showCodeBlockLnLabel=\u4EE3\u7801\u5757\u663E\u793A\u884C\u53F7\uFF1A showCodeBlockLnLabel=\u4EE3\u7801\u5757\u663E\u793A\u884C\u53F7\uFF1A
siteURLLabel=\u7AD9\u70B9\u5730\u5740\uFF1A siteURLLabel=\u7AD9\u70B9\u5730\u5740\uFF1A
siteGenedLabel=\u7AD9\u70B9\u751F\u6210\u5B8C\u6BD5\uFF0C\u8BF7\u67E5\u770B\u76EE\u5F55 [{dir}] siteGenedLabel=\u7AD9\u70B9\u751F\u6210\u5B8C\u6BD5\uFF0C\u8BF7\u67E5\u770B\u76EE\u5F55 [{dir}]
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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