Commit ff05459e authored by Liang Ding's avatar Liang Ding

Markdown 支持 [ToC] #52

parent 2e7b6690
......@@ -66,7 +66,7 @@ public class ToCPlugin extends NotInteractivePlugin {
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://www.annpeter.cn">Ann Peter</a>
* @author <a href="http://vanessa.b3log.org">Vanessa</a>
* @version 2.0.0.0, Jul 29, 2019
* @version 2.0.0.1, Jan 24, 2020
* @since 0.6.7
*/
class ToCEventHandler extends AbstractEventListener<JSONObject> {
......@@ -90,7 +90,7 @@ class ToCEventHandler extends AbstractEventListener<JSONObject> {
final Element element = hs.get(i);
final String tagName = element.tagName().toLowerCase();
final String text = element.text();
final String id = "b3_solo_" + tagName + "_" + i;
final String id = "toc_" + tagName + "_" + i;
element.attr("id", id);
final JSONObject li = new JSONObject().
put("className", "toc__" + tagName).
......
......@@ -125,7 +125,7 @@ window.Skin = {
})
}
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]')
var $articleTocs = $('.vditor-reset [id^=toc_h]')
var $articleToc = $('.article__toc')
$articleToc.find('a').click(function (event) {
......
......@@ -59,7 +59,7 @@ window.Skin = {
initArticle: function () {
page.share()
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]')
var $articleTocs = $('.vditor-reset [id^=toc_h]')
var $articleToc = $('.article__toc')
var $articleProgress = $('.article__progress')
......
......@@ -162,7 +162,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var jque
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _js_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../js/common */ \"./src/main/resources/js/common.js\");\n/*\r\n * Solo - A small and beautiful blogging system written in Java.\r\n * Copyright (c) 2010-present, b3log.org\r\n *\r\n * This program is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU Affero General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU Affero General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Affero General Public License\r\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\r\n */\r\n/**\r\n * @fileoverview util and every page should be used.\r\n *\r\n * @author <a href=\"http://vanessa.b3log.org\">Liyuan Li</a>\r\n * @version 1.0.0.0, Jan 18, 2019\r\n */\r\n\r\n\r\n\r\nwindow.utilOptions = {\r\n cmtCountCB: (element, cnt) => {\r\n if (cnt > 0) {\r\n element.parentElement.style.display = 'inline'\r\n element.parentElement.nextElementSibling.style.display = 'none'\r\n }\r\n },\r\n}\r\n/**\r\n * @description 皮肤脚本\r\n * @static\r\n */\r\nwindow.Skin = {\r\n init: function () {\r\n if (Label.staticSite) {\r\n return\r\n }\r\n Util.initPjax()\r\n },\r\n _positionToc: function ($articleToc) {\r\n if ($articleToc.length === 1) {\r\n if ($(window).width() > 876) {\r\n $('.post__toc').\r\n css('left', $('.article .item__content').offset().left +\r\n $('.article .item__content').outerWidth() - 80)\r\n } else {\r\n $('.post__toc a').click(function () {\r\n $('.post__toc').hide()\r\n })\r\n }\r\n }\r\n },\r\n initArticle: function () {\r\n page.share()\r\n\r\n var $articleTocs = $('.vditor-reset [id^=b3_solo_h]')\r\n var $articleToc = $('.article__toc')\r\n var $articleProgress = $('.article__progress')\r\n\r\n Skin._positionToc($articleToc)\r\n\r\n $articleToc.find('a').click(function (event) {\r\n var id = $(this).attr('href')\r\n window.location.hash = id\r\n $(window).scrollTop($(id).offset().top - 60)\r\n event.preventDefault()\r\n event.stopPropagation()\r\n return false\r\n })\r\n\r\n $(window).unbind('scroll').scroll(function (event) {\r\n if ($articleProgress.length === 0) {\r\n return false\r\n }\r\n\r\n $articleProgress.attr('value', parseInt($(window).scrollTop())).\r\n attr('max', parseInt($('body').outerHeight() -\r\n $(window).height()))\r\n\r\n if ($(window).scrollTop() > 236) {\r\n $('.article__top').css('top', 0)\r\n } else {\r\n $('.article__top').css('top', -61)\r\n }\r\n\r\n if ($('.article__toc li').length === 0) {\r\n return false\r\n }\r\n\r\n if ($(window).width() > 876) {\r\n if ($(window).scrollTop() > 975 && $(window).scrollTop() <\r\n $('.article').outerHeight() + 100) {\r\n $('.post__toc').show()\r\n } else {\r\n $('.post__toc').hide()\r\n }\r\n }\r\n\r\n // 界面各种图片加载会导致帖子目录定位\r\n var toc = []\r\n $articleTocs.each(function (i) {\r\n toc.push({\r\n id: this.id,\r\n offsetTop: $(this).offset().top,\r\n })\r\n })\r\n\r\n // 当前目录样式\r\n var scrollTop = $(window).scrollTop()\r\n for (var i = 0, iMax = toc.length; i < iMax; i++) {\r\n if (scrollTop < toc[i].offsetTop - 61) {\r\n $articleToc.find('li').removeClass('current')\r\n var index = i > 0 ? i - 1 : 0\r\n $articleToc.find('a[href=\"#' + toc[index].id + '\"]').\r\n parent().\r\n addClass('current')\r\n break\r\n }\r\n }\r\n if (scrollTop >= toc[toc.length - 1].offsetTop - 61) {\r\n $articleToc.find('li').removeClass('current')\r\n $articleToc.find('li:last').addClass('current')\r\n }\r\n })\r\n\r\n $(window).scroll()\r\n\r\n $(window).resize(function () {\r\n Skin._positionToc($articleToc)\r\n })\r\n },\r\n}\r\nSkin.init()\r\n\n\n//# sourceURL=webpack:///./src/main/resources/skins/Casper/js/common.js?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _js_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../js/common */ \"./src/main/resources/js/common.js\");\n/*\r\n * Solo - A small and beautiful blogging system written in Java.\r\n * Copyright (c) 2010-present, b3log.org\r\n *\r\n * This program is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU Affero General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU Affero General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Affero General Public License\r\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\r\n */\r\n/**\r\n * @fileoverview util and every page should be used.\r\n *\r\n * @author <a href=\"http://vanessa.b3log.org\">Liyuan Li</a>\r\n * @version 1.0.0.0, Jan 18, 2019\r\n */\r\n\r\n\r\n\r\nwindow.utilOptions = {\r\n cmtCountCB: (element, cnt) => {\r\n if (cnt > 0) {\r\n element.parentElement.style.display = 'inline'\r\n element.parentElement.nextElementSibling.style.display = 'none'\r\n }\r\n },\r\n}\r\n/**\r\n * @description 皮肤脚本\r\n * @static\r\n */\r\nwindow.Skin = {\r\n init: function () {\r\n if (Label.staticSite) {\r\n return\r\n }\r\n Util.initPjax()\r\n },\r\n _positionToc: function ($articleToc) {\r\n if ($articleToc.length === 1) {\r\n if ($(window).width() > 876) {\r\n $('.post__toc').\r\n css('left', $('.article .item__content').offset().left +\r\n $('.article .item__content').outerWidth() - 80)\r\n } else {\r\n $('.post__toc a').click(function () {\r\n $('.post__toc').hide()\r\n })\r\n }\r\n }\r\n },\r\n initArticle: function () {\r\n page.share()\r\n\r\n var $articleTocs = $('.vditor-reset [id^=toc_h]')\r\n var $articleToc = $('.article__toc')\r\n var $articleProgress = $('.article__progress')\r\n\r\n Skin._positionToc($articleToc)\r\n\r\n $articleToc.find('a').click(function (event) {\r\n var id = $(this).attr('href')\r\n window.location.hash = id\r\n $(window).scrollTop($(id).offset().top - 60)\r\n event.preventDefault()\r\n event.stopPropagation()\r\n return false\r\n })\r\n\r\n $(window).unbind('scroll').scroll(function (event) {\r\n if ($articleProgress.length === 0) {\r\n return false\r\n }\r\n\r\n $articleProgress.attr('value', parseInt($(window).scrollTop())).\r\n attr('max', parseInt($('body').outerHeight() -\r\n $(window).height()))\r\n\r\n if ($(window).scrollTop() > 236) {\r\n $('.article__top').css('top', 0)\r\n } else {\r\n $('.article__top').css('top', -61)\r\n }\r\n\r\n if ($('.article__toc li').length === 0) {\r\n return false\r\n }\r\n\r\n if ($(window).width() > 876) {\r\n if ($(window).scrollTop() > 975 && $(window).scrollTop() <\r\n $('.article').outerHeight() + 100) {\r\n $('.post__toc').show()\r\n } else {\r\n $('.post__toc').hide()\r\n }\r\n }\r\n\r\n // 界面各种图片加载会导致帖子目录定位\r\n var toc = []\r\n $articleTocs.each(function (i) {\r\n toc.push({\r\n id: this.id,\r\n offsetTop: $(this).offset().top,\r\n })\r\n })\r\n\r\n // 当前目录样式\r\n var scrollTop = $(window).scrollTop()\r\n for (var i = 0, iMax = toc.length; i < iMax; i++) {\r\n if (scrollTop < toc[i].offsetTop - 61) {\r\n $articleToc.find('li').removeClass('current')\r\n var index = i > 0 ? i - 1 : 0\r\n $articleToc.find('a[href=\"#' + toc[index].id + '\"]').\r\n parent().\r\n addClass('current')\r\n break\r\n }\r\n }\r\n if (scrollTop >= toc[toc.length - 1].offsetTop - 61) {\r\n $articleToc.find('li').removeClass('current')\r\n $articleToc.find('li:last').addClass('current')\r\n }\r\n })\r\n\r\n $(window).scroll()\r\n\r\n $(window).resize(function () {\r\n Skin._positionToc($articleToc)\r\n })\r\n },\r\n}\r\nSkin.init()\r\n\n\n//# sourceURL=webpack:///./src/main/resources/skins/Casper/js/common.js?");
/***/ })
......
......@@ -83,7 +83,7 @@ window.Skin = {
$('.post__toc').
css('left', $('.post').offset().left + $('.post').outerWidth())
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]'),
var $articleTocs = $('.vditor-reset [id^=toc_h]'),
$articleToc = $('.article__toc')
$(window).unbind('scroll').scroll(function (event) {
......
......@@ -100,7 +100,7 @@ window.NexT = {
}
},
initToc: function () {
var $articleTocs = $('.vditor-reset [id^=b3_solo_h]'),
var $articleTocs = $('.vditor-reset [id^=toc_h]'),
$articleToc = $('.article__toc');
$(window).scroll(function (event) {
......
......@@ -162,7 +162,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var jque
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _js_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../js/common */ \"./src/main/resources/js/common.js\");\n/*\r\n * Solo - A small and beautiful blogging system written in Java.\r\n * Copyright (c) 2010-present, b3log.org\r\n *\r\n * This program is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU Affero General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU Affero General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Affero General Public License\r\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\r\n */\r\n/**\r\n * @fileoverview util and every page should be used.\r\n *\r\n * @author <a href=\"http://vanessa.b3log.org\">Liyuan Li</a>\r\n * @version 1.0.0.0, Jan 18, 2019\r\n */\r\n\r\n\r\n/**\r\n * @description next 皮肤脚本\r\n * @static\r\n */\r\nwindow.NexT = {\r\n init: function () {\r\n $('.sidebar-toggle').click(function () {\r\n var $sidebar = $('.sidebar');\r\n if ($(this).hasClass('sidebar-active')) {\r\n $(this).removeClass('sidebar-active');\r\n\r\n $('body').animate({\r\n 'padding-right': 0\r\n });\r\n $sidebar.animate({\r\n right: -320\r\n });\r\n $sidebar.find('section').css('opacity', 0);\r\n } else {\r\n $(this).addClass('sidebar-active');\r\n $('body').animate({\r\n 'padding-right': 320\r\n });\r\n $sidebar.animate({\r\n right: 0\r\n }, function () {\r\n $sidebar.find('section:first').animate({\r\n 'opacity': 1\r\n });\r\n });\r\n }\r\n });\r\n\r\n $('.site-nav-toggle').click(function () {\r\n $('.site-nav').slideToggle();\r\n });\r\n\r\n $(document).ready(function () {\r\n setTimeout(function () {\r\n // logo animate\r\n $('.logo-wrap').css('opacity', 1);\r\n $('.logo-line-before i').animate({\r\n 'left': '0'\r\n }, function () {\r\n $('.site-title').css('opacity', 1).animate({\r\n 'top': 0\r\n }, function () {\r\n $('.menu').css('opacity', 1).animate({\r\n 'margin-top': '15px'\r\n });\r\n $('.main').css('opacity', 1).animate({\r\n 'top': '0'\r\n }, function () {\r\n // 当有文章页面有目录时,回调不放这里,侧边栏就会一片空白\r\n if ($('.article__toc li').length > 0 && $(window).width() > 1000) {\r\n $('.sidebar-toggle').click();\r\n }\r\n });\r\n });\r\n\r\n\r\n });\r\n\r\n $('.logo-line-after i').animate({\r\n 'right': '0'\r\n });\r\n }, 500);\r\n });\r\n },\r\n initArticle: function () {\r\n if ($('.article__toc li').length > 0 && $(window).width() > 1000) {\r\n // add color to sidebar menu\r\n $('.sidebar-toggle').addClass('has-toc');\r\n this.initToc();\r\n }\r\n },\r\n initToc: function () {\r\n var $articleTocs = $('.vditor-reset [id^=b3_solo_h]'),\r\n $articleToc = $('.article__toc');\r\n\r\n $(window).scroll(function (event) {\r\n if ($('.article__toc li').length === 0) {\r\n return false;\r\n }\r\n\r\n // 界面各种图片加载会导致帖子目录定位\r\n var toc = [];\r\n $articleTocs.each(function (i) {\r\n toc.push({\r\n id: this.id,\r\n offsetTop: this.offsetTop\r\n });\r\n });\r\n\r\n // 当前目录样式\r\n var scrollTop = $(window).scrollTop();\r\n for (var i = 0, iMax = toc.length; i < iMax; i++) {\r\n if (scrollTop < toc[i].offsetTop + 200) {\r\n $articleToc.find('li').removeClass('current');\r\n var index = i > 0 ? i - 1 : 0;\r\n $articleToc.find('a[href=\"#' + toc[index].id + '\"]').parent().addClass('current');\r\n break;\r\n }\r\n }\r\n if (scrollTop >= toc[toc.length - 1].offsetTop + 200) {\r\n $articleToc.find('li').removeClass('current');\r\n $articleToc.find('li:last').addClass('current');\r\n }\r\n });\r\n\r\n $(window).scroll();\r\n }\r\n};\r\nNexT.init();\r\n\n\n//# sourceURL=webpack:///./src/main/resources/skins/next/js/common.js?");
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _js_common__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../../js/common */ \"./src/main/resources/js/common.js\");\n/*\r\n * Solo - A small and beautiful blogging system written in Java.\r\n * Copyright (c) 2010-present, b3log.org\r\n *\r\n * This program is free software: you can redistribute it and/or modify\r\n * it under the terms of the GNU Affero General Public License as published by\r\n * the Free Software Foundation, either version 3 of the License, or\r\n * (at your option) any later version.\r\n *\r\n * This program is distributed in the hope that it will be useful,\r\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\r\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r\n * GNU Affero General Public License for more details.\r\n *\r\n * You should have received a copy of the GNU Affero General Public License\r\n * along with this program. If not, see <https://www.gnu.org/licenses/>.\r\n */\r\n/**\r\n * @fileoverview util and every page should be used.\r\n *\r\n * @author <a href=\"http://vanessa.b3log.org\">Liyuan Li</a>\r\n * @version 1.0.0.0, Jan 18, 2019\r\n */\r\n\r\n\r\n/**\r\n * @description next 皮肤脚本\r\n * @static\r\n */\r\nwindow.NexT = {\r\n init: function () {\r\n $('.sidebar-toggle').click(function () {\r\n var $sidebar = $('.sidebar');\r\n if ($(this).hasClass('sidebar-active')) {\r\n $(this).removeClass('sidebar-active');\r\n\r\n $('body').animate({\r\n 'padding-right': 0\r\n });\r\n $sidebar.animate({\r\n right: -320\r\n });\r\n $sidebar.find('section').css('opacity', 0);\r\n } else {\r\n $(this).addClass('sidebar-active');\r\n $('body').animate({\r\n 'padding-right': 320\r\n });\r\n $sidebar.animate({\r\n right: 0\r\n }, function () {\r\n $sidebar.find('section:first').animate({\r\n 'opacity': 1\r\n });\r\n });\r\n }\r\n });\r\n\r\n $('.site-nav-toggle').click(function () {\r\n $('.site-nav').slideToggle();\r\n });\r\n\r\n $(document).ready(function () {\r\n setTimeout(function () {\r\n // logo animate\r\n $('.logo-wrap').css('opacity', 1);\r\n $('.logo-line-before i').animate({\r\n 'left': '0'\r\n }, function () {\r\n $('.site-title').css('opacity', 1).animate({\r\n 'top': 0\r\n }, function () {\r\n $('.menu').css('opacity', 1).animate({\r\n 'margin-top': '15px'\r\n });\r\n $('.main').css('opacity', 1).animate({\r\n 'top': '0'\r\n }, function () {\r\n // 当有文章页面有目录时,回调不放这里,侧边栏就会一片空白\r\n if ($('.article__toc li').length > 0 && $(window).width() > 1000) {\r\n $('.sidebar-toggle').click();\r\n }\r\n });\r\n });\r\n\r\n\r\n });\r\n\r\n $('.logo-line-after i').animate({\r\n 'right': '0'\r\n });\r\n }, 500);\r\n });\r\n },\r\n initArticle: function () {\r\n if ($('.article__toc li').length > 0 && $(window).width() > 1000) {\r\n // add color to sidebar menu\r\n $('.sidebar-toggle').addClass('has-toc');\r\n this.initToc();\r\n }\r\n },\r\n initToc: function () {\r\n var $articleTocs = $('.vditor-reset [id^=toc_h]'),\r\n $articleToc = $('.article__toc');\r\n\r\n $(window).scroll(function (event) {\r\n if ($('.article__toc li').length === 0) {\r\n return false;\r\n }\r\n\r\n // 界面各种图片加载会导致帖子目录定位\r\n var toc = [];\r\n $articleTocs.each(function (i) {\r\n toc.push({\r\n id: this.id,\r\n offsetTop: this.offsetTop\r\n });\r\n });\r\n\r\n // 当前目录样式\r\n var scrollTop = $(window).scrollTop();\r\n for (var i = 0, iMax = toc.length; i < iMax; i++) {\r\n if (scrollTop < toc[i].offsetTop + 200) {\r\n $articleToc.find('li').removeClass('current');\r\n var index = i > 0 ? i - 1 : 0;\r\n $articleToc.find('a[href=\"#' + toc[index].id + '\"]').parent().addClass('current');\r\n break;\r\n }\r\n }\r\n if (scrollTop >= toc[toc.length - 1].offsetTop + 200) {\r\n $articleToc.find('li').removeClass('current');\r\n $articleToc.find('li:last').addClass('current');\r\n }\r\n });\r\n\r\n $(window).scroll();\r\n }\r\n};\r\nNexT.init();\r\n\n\n//# sourceURL=webpack:///./src/main/resources/skins/next/js/common.js?");
/***/ })
......
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