[fix] fix md codeblock

This commit is contained in:
xaoxuu 2022-11-19 22:23:55 +08:00
parent 80e6e749cc
commit ea97f0f6cd
4 changed files with 18 additions and 20 deletions

View File

@ -19,13 +19,13 @@ hexo.extend.tag.register('folders', function(args, content) {
el += ' ' + hexo.args.joinTags(args, ['color']).join(' ');
el += '>';
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
var arr = content.split(/<!--\s*folder (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
arr.forEach((item, i) => {
if (item.startsWith('folder ')) {
if (i % 2 == 0) {
nodes.push({
header: item.substring(7)
header: item
});
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1];
@ -42,7 +42,7 @@ hexo.extend.tag.register('folders', function(args, content) {
el += '<summary><span>' + (node.header || '') + '</span></summary>';
// content
el += '<div class="body">';
el += hexo.render.renderSync({text: node.body, engine: 'markdown'}).split('\n').join('');
el += hexo.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('');
el += '</div></details>';
});
}

View File

@ -6,15 +6,15 @@
var tab_index = 0;
module.exports = ctx => function(args, content) {
module.exports = ctx => function(args, content = '') {
var el = '';
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
var arr = content.split(/<!--\s*tab (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length < 1) {
return el;
}
var tabs = [];
arr.forEach((item, i) => {
if (item.startsWith('tab ')) {
if (i % 2 == 0) {
tabs.push({
header: item
});
@ -35,14 +35,12 @@ module.exports = ctx => function(args, content) {
let tabId = 0;
let tabNav = '';
let tabContent = '';
tabs.forEach((tab, i) => {
let caption = tab.header.substring(4);
let content = ctx.render.renderSync({ text: tab.body, engine: 'markdown' }).trim();
let content = ctx.render.renderSync({ text: (tab.body || ''), engine: 'markdown' }).trim();
const abbr = tabName + ' ' + ++tabId;
const href = abbr.toLowerCase().split(' ').join('-');
const isActive = (tabActive > 0 && tabActive === tabId) || (tabActive === 0 && tabId === 1) ? ' active' : '';
tabNav += `<li class="tab${isActive}"><a href="#${href}">${caption || abbr}</a></li>`;
tabNav += `<li class="tab${isActive}"><a href="#${href}">${tab.header || abbr}</a></li>`;
tabContent += `<div class="tab-pane${isActive}" id="${href}">${content}</div>`;
});

View File

@ -3,9 +3,9 @@
* 格式与官方标签插件一致使用空格分隔中括号内的是可选参数中括号不需要写出来
*
* {% split [style:block/card] %}
* <!-- cell -->
* <!-- cell left -->
* left body
* <!-- cell -->
* <!-- cell right -->
* right body
* {% endsplit %}
*/
@ -19,13 +19,13 @@ hexo.extend.tag.register('split', function(args, content) {
el += ' ' + hexo.args.joinTags(args, ['bg']).join(' ');
el += '>';
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
var arr = content.split(/<!--\s*cell (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
arr.forEach((item, i) => {
if (item == 'cell') {
if (i % 2 == 0) {
nodes.push({
header: ''
header: item
});
} else if (nodes.length > 0) {
var node = nodes[nodes.length-1];
@ -38,7 +38,7 @@ hexo.extend.tag.register('split', function(args, content) {
});
nodes.forEach((node, i) => {
el += '<div class="cell" index="' + (i) + '">';
el += hexo.render.renderSync({text: node.body, engine: 'markdown'}).split('\n').join('');
el += hexo.render.renderSync({text: (node.body || ''), engine: 'markdown'}).split('\n').join('');
el += '</div>';
});
}

View File

@ -49,11 +49,11 @@ function postTimeline(args, content) {
el += '<div class="tag-plugin timeline">';
}
var arr = content.split(/<!--\s*(.*?)\s*-->/g).filter(item => item.trim().length > 0)
var arr = content.split(/<!--\s*node (.*?)\s*-->/g).filter(item => item.trim().length > 0)
if (arr.length > 0) {
var nodes = [];
arr.forEach((item, i) => {
if (item.startsWith('node ')) {
if (i % 2 == 0) {
nodes.push({
header: item
});
@ -68,7 +68,7 @@ function postTimeline(args, content) {
});
nodes.forEach((node, i) => {
el += '<div class="timenode" index="' + (i) + '">';
el += layoutNodeTitle(node.header.substring(5));
el += layoutNodeTitle(node.header);
el += layoutNodeContent(node.body);
el += '</div>';
});