From 577946503fa877d8626cb04548c381b72162cf45 Mon Sep 17 00:00:00 2001 From: amehime Date: Sun, 27 Sep 2020 23:27:07 +0800 Subject: [PATCH] add collapse --- README.md | 1 - lib/renderer/index.js | 1 - lib/renderer/markdown-it-container/index.js | 31 +++++++++++++++++---- package.json | 3 +- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ed84d3b..e3e8937 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,6 @@ prismjs: - [markdown-it-toc-and-anchor](https://www.npmjs.com/package/markdown-it-toc-and-anchor) - [markdown-it-container](https://www.npmjs.com/package/markdown-it-container) - [markdown-it-multimd-table](https://www.npmjs.com/package/markdown-it-multimd-table) -- [markdown-it-collapsible](https://www.npmjs.com/package/markdown-it-collapsible) - [markdown-it-katex](https://www.npmjs.com/package/@neilsustc/markdown-it-katex) If you want to use katex, you must add this css style to your website: diff --git a/lib/renderer/index.js b/lib/renderer/index.js index 0c6a3b9..e74c6fa 100644 --- a/lib/renderer/index.js +++ b/lib/renderer/index.js @@ -13,7 +13,6 @@ const default_plugins = [ 'markdown-it-sup', 'markdown-it-task-checkbox', 'markdown-it-toc-and-anchor', - 'markdown-it-collapsible', 'markdown-it-pangu', './markdown-it-container', './markdown-it-furigana', diff --git a/lib/renderer/markdown-it-container/index.js b/lib/renderer/markdown-it-container/index.js index 938ad51..64219d9 100644 --- a/lib/renderer/markdown-it-container/index.js +++ b/lib/renderer/markdown-it-container/index.js @@ -4,14 +4,14 @@ module.exports = function (md, options) { md.use(plugin, 'note', { validate: function (params) { - return params.trim().match(/^note\s+(default|primary|success|info|warning|danger)$/); + return params.trim().match(/^(default|primary|success|info|warning|danger)(.*)$/); }, render: function (tokens, idx) { - var m = tokens[idx].info.trim().match(/^note\s+(.*)$/); + var m = tokens[idx].info.trim().match(/^(.*)$/); if (tokens[idx].nesting === 1) { // opening tag - return '
\n'; + return '
\n'; } else { // closing tag @@ -24,11 +24,11 @@ module.exports = function (md, options) { marker: ';', validate: function(params) { - return params.trim().match(/^tab\s+(.*)\|\|(.*)$/); + return params.trim().match(/^(\w+)+(.*)$/); }, render: function (tokens, idx) { - var m = tokens[idx].info.trim().match(/^tab\s+(.*)\|\|(.*)$/); + var m = tokens[idx].info.trim().match(/^(\w+)+(.*)$/); if (tokens[idx].nesting === 1) { // opening tag @@ -40,4 +40,25 @@ module.exports = function (md, options) { } } }); + + md.use(plugin, 'collapse', { + marker: '+', + + validate: function(params) { + return params.match(/^(primary|success|info|warning|danger|\s)(.*)$/); + }, + + render: function (tokens, idx) { + var m = tokens[idx].info.match(/^(primary|success|info|warning|danger|\s)(.*)$/); + + if (tokens[idx].nesting === 1) { + // opening tag + var style = m[1].trim() + return ''+m[2].trim()+'
\n'; + } else { + // closing tag + return '
\n'; + } + } + }); } \ No newline at end of file diff --git a/package.json b/package.json index f688f9e..88e9452 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hexo-renderer-multi-markdown-it", - "version": "0.1.2", + "version": "0.1.3", "description": "A Markdown parser for Hexo and auto Minify HTML, CSS, JS.", "main": "index.js", "repository": "https://github.com/amehime/hexo-renderer-multi-markdown-it.git", @@ -34,7 +34,6 @@ "markdown-it-attrs": "^3.0.2", "markdown-it-bracketed-spans": "^1.0.1", "markdown-it-charts": "^1.0.5", - "markdown-it-collapsible": "^1.0.0", "markdown-it-container": "^2.0.0", "markdown-it-deflist": "^2.0.3", "markdown-it-emoji": "^1.4.0",