From c753b3dfbca8c09cd9da7e50e9a1428a99d1fe92 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Sat, 10 Jul 2021 11:12:06 +0800 Subject: [PATCH] note --- scripts/tags/note.js | 23 +++++++++++-------- source/css/_layout/tag-plugins/note.styl | 29 +++++++++++++++++++----- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/scripts/tags/note.js b/scripts/tags/note.js index 4460c2d..5c57c24 100644 --- a/scripts/tags/note.js +++ b/scripts/tags/note.js @@ -1,19 +1,21 @@ /** - * note.js v1 | https://github.com/xaoxuu/hexo-theme-stellar/ + * note.js v1.1 | https://github.com/xaoxuu/hexo-theme-stellar/ * 格式与官方标签插件一致使用空格分隔,中括号内的是可选参数(中括号不需要写出来) * * note: * {% note [color:color] [title] content %} * * noteblock: - * {% noteblock [color:color] title %} + * {% noteblock [color:color] [codeblock:bool] title %} * markdown content * {% endnoteblock %} */ 'use strict'; -function outputNoteBlock(color, title, content) { +function outputNoteBlock(args, content) { + const color = args.color; + const title = args.title; var el = ''; const defaultColor = hexo.theme.config.tag_plugins.note.default_color; if (!color && defaultColor) { @@ -24,6 +26,9 @@ function outputNoteBlock(color, title, content) { if (color && color.length > 0) { el += ' color="' + color + '"'; } + if (args.codeblock !== undefined) { + el += ' codeblock="' + args.codeblock + '"'; + } el += '>'; // title if (title && title.length > 0) { @@ -39,14 +44,14 @@ function outputNoteBlock(color, title, content) { hexo.extend.tag.register('note', function(args) { args = hexo.args.map(args, ['color'], ['title', 'content']); - if (args.content) { - return outputNoteBlock(args.color, args.title, args.content); - } else { - return outputNoteBlock(args.color, '', args.title); + if (args.content === undefined || args.content.length <= 0) { + args.content = args.title; + args.title = ''; } + return outputNoteBlock(args, args.content); }); hexo.extend.tag.register('noteblock', function(args, content) { - args = hexo.args.map(args, ['color'], ['title']); - return outputNoteBlock(args.color, args.title, content); + args = hexo.args.map(args, ['color', 'codeblock'], ['title']); + return outputNoteBlock(args, content); }, {ends: true}); diff --git a/source/css/_layout/tag-plugins/note.styl b/source/css/_layout/tag-plugins/note.styl index a1c0013..e996742 100644 --- a/source/css/_layout/tag-plugins/note.styl +++ b/source/css/_layout/tag-plugins/note.styl @@ -1,20 +1,37 @@ -.md div.note +.md .tag-plugin.note $border-block = 4px position: relative margin-top: 1rem margin-bottom: 1rem - padding: 1rem + padding: 0 1rem border-radius: $border-block font-size: $fs-15 background: var(--theme-bg) border: 1px solid var(--theme) color: var(--text-p1) - div.title + >.title inside-box: $fs-15 - margin-bottom: 0.5rem - div.body + line-height: 1.2 + margin-top: 1rem + >.body inside-box: $fs-14 + line-height: 1.5 + margin-top: .5rem + margin-bottom: 1rem + >.body:only-child + margin: 1rem 0 -.md div.note:not([color]) + +.md .tag-plugin.note:not([color]) .highlight background: var(--block-hover) +.md .tag-plugin.note[codeblock=true] + padding: 0 + >.title, >.body:only-child + margin-top: 0 + >.body + margin-bottom: 0 + .highlight + margin: 0 + border: none + background: none