diff --git a/scripts/tags/message.js b/scripts/tags/message.js index 8fd945c..3462572 100644 --- a/scripts/tags/message.js +++ b/scripts/tags/message.js @@ -1,25 +1,26 @@ /** * Bulma Message Tag, see {@link https://bulma.io/documentation/components/message/}. - * + * * @param {string} color The color of this message, can not be set. Usable: dark, primary, link, info, success, * warning, danger. * @param {string} icon The icon of this message, can not be set. * @param {string} title The header of this message, can not be set, supported Markdown. * @param {string} size The size of this message, can not be set. Usable: small, medium, large. The default * size is between small and medium. - * + * * @example * {% message color:danger icon:info-circle 'title:Very danger!' size:small %} * **You are in danger.** * {% endmessage %} */ - module.exports = function (hexo) { +module.exports = function(hexo) { hexo.extend.tag.register('message', function(args, content) { let color = 'dark'; let icon = ''; let title = ''; let size = ''; let header = ''; + args.forEach(element => { const key = element.split(':')[0].trim(); const value = element.split(':')[1].trim(); @@ -45,8 +46,9 @@
${hexo.render.renderSync({text: icon + title, engine: 'markdown'})}
- ` + `; } + return `
${header} @@ -56,4 +58,4 @@
`; }, { ends: true }); -} \ No newline at end of file +}; diff --git a/scripts/tags/tabs.js b/scripts/tags/tabs.js index 882aaab..7969285 100644 --- a/scripts/tags/tabs.js +++ b/scripts/tags/tabs.js @@ -1,118 +1,123 @@ /** * Bulma Tabs Tag, see {@link https://bulma.io/documentation/components/tabs/}. - * + * * The format of each item is: [content] . * If each item's content is indented with four spaces or one tab, these indents will be ignored. - * + * * @param {string} id The unique id of this tab, should match: /\w/. * @param {string} behavior The behavior of this tab, can not be set. Usable: centered, right, fullwidth. The * default behavior is to display on the left. * @param {string} size The size of this tab, can not be set. Usable: small, medium, large. The default * size is between small and medium. * @param {string} style The style of this tab, can not be set. Usable: boxed, toggle, toggle-rounded. - * + * * @example * {% tabs behavior:fullwidth size:small style:toggle-rounded %} * This is info. * This is hello. * {% endmessage %} */ - hexo.extend.tag.register('tabs', function(args, content) { - let id = ''; - let behavior = ''; - let size = ''; - let style = ''; - let contentEl = content; - args.forEach(element => { - const key = element.split(':')[0].trim(); - const value = element.split(':')[1].trim(); - if (value !== null && value !== undefined && value !== '') { - switch (key) { - case 'id': - id = value; - break; - case 'behavior': - behavior = ` is-${value}`; - break; - case 'size': - size = ` is-${value}`; - break; - case 'style': - if (value === 'toggle-rounded') { - style = ' is-toggle is-toggle-rounded'; - } else { - style = ` is-${value}`; - } - break; +module.exports = function(hexo) { + hexo.extend.tag.register('tabs', function(args, content) { + let id = ''; + let behavior = ''; + let size = ''; + let style = ''; + + args.forEach(element => { + const key = element.split(':')[0].trim(); + const value = element.split(':')[1].trim(); + if (value !== null && value !== undefined && value !== '') { + switch (key) { + case 'id': + id = value; + break; + case 'behavior': + behavior = ` is-${value}`; + break; + case 'size': + size = ` is-${value}`; + break; + case 'style': + if (value === 'toggle-rounded') { + style = ' is-toggle is-toggle-rounded'; + } else { + style = ` is-${value}`; + } + break; + } } - } - }); + }); - const blockRegExp = /([\s\S]*?)/g; - let match; - let tabsEl = ''; - let contentEl = ''; + const blockRegExp = /([\s\S]*?)/g; + let match; + let tabsEl = ''; + let contentEl = ''; - while((match = blockRegExp.exec(content)) !== null) { - let active = ''; - let hidden = ' is-hidden'; - let icon = ''; - var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, ''); - if (match[1] === 'active') { - active = ' class="is-active"'; - hidden = ''; + while((match = blockRegExp.exec(content)) !== null) { + let active = ''; + let hidden = ' is-hidden'; + let icon = ''; + var contentString = match[5].replace(/^\n?|[ \n\t]*$/g, ''); + + if (match[1] === 'active') { + active = ' class="is-active"'; + hidden = ''; + } + if (match[3] === 'active' && match[3].substring(1) !== '') icon = ``; + if (contentString.match(/^ {4}|^\t{1}/gm) !== null && contentString.match(/^ {4}|^\t{1}/gm).length === contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n'); + + tabsEl += ` +
  • + ${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})} +
  • + `; + + contentEl += ` +
    + ${hexo.render.renderSync({text: contentString, engine: 'markdown'})} +
    + `; } - if (match[3] === 'active' && match[3].substring(1) !== '') icon = ``; - if (contentString.match(/^ {4}|^\t{1}/gm) !== null && contentString.match(/^ {4}|^\t{1}/gm).length === contentString.split('\n').length) contentString = contentString.replace(/^ {4}|^\t{1}/g, '').replace(/\n {4}|\n\t{1}/g, '\n'); - tabsEl += ` -
  • - ${hexo.render.renderSync({text: icon + match[4].substring(2, match[4].length - 1), engine: 'markdown'})} -
  • - `; - contentEl += ` -
    - ${hexo.render.renderSync({text: contentString, engine: 'markdown'})} -
    - `; - } - - return ` -
    -
    - -
    + + return `
    - ${contentEl} +
    +
      + ${tabsEl} +
    +
    +
    + ${contentEl} +
    -
    - `; -}, { ends: true }); + `; + }, { ends: true }); -hexo.extend.injector.register( - "head_end", - ` - - ` -); \ No newline at end of file + + ` + ); +};