From 5c82fa941ffd8335bba0af586503f642728e4ee4 Mon Sep 17 00:00:00 2001 From: Grigorii Horos Date: Sun, 12 May 2024 03:23:38 +0300 Subject: [PATCH] Upgrade deps --- example/alert.md | 14 +++++++ index.js | 95 +++++++++++++++++++++++++++++++++++++++++++++++- package.json | 10 ++--- 3 files changed, 113 insertions(+), 6 deletions(-) create mode 100644 example/alert.md diff --git a/example/alert.md b/example/alert.md new file mode 100644 index 0000000..4d7daa2 --- /dev/null +++ b/example/alert.md @@ -0,0 +1,14 @@ +> [!NOTE] +> Highlights information that users should take into account, even when skimming. + +> [!TIP] +> Optional information to help a user be more successful. + +> [!IMPORTANT] +> Crucial information necessary for users to succeed. + +> [!WARNING] +> Critical content demanding immediate user attention due to potential risks. + +> [!CAUTION] +> Negative potential consequences of an action. diff --git a/index.js b/index.js index cb02518..fadc603 100644 --- a/index.js +++ b/index.js @@ -28,7 +28,100 @@ const md = markdownit({ .use(markdownItSub) .use(markdownItTaskList) .use(alert, { - deep: true, + deep: false, + + openRender(tokens, index, options, environment, self) { + const token = tokens[index]; + + let color = null; + + // Case token.markup in ['important', 'note', 'tip', 'warning', 'caution'] + switch (token?.markup) { + case 'important': { + color = 'red'; + + break; + } + case 'note': { + color = 'blue'; + + break; + } + case 'tip': { + color = 'green'; + + break; + } + case 'warning': { + color = 'yellow'; + + break; + } + case 'caution': { + color = 'yellow light'; + + break; + } + default: { + color = 'blue'; + } + } + + return `
`; + }, + + closeRender(tokens, index, options, environment, self) { + return '
'; + }, + titleRender: (tokens, index) => { + const token = tokens[index]; + + // console.log(token) + + let color = null; + let icon = null; + + switch (token?.markup) { + case 'important': { + color = 'red'; + icon = '•'; + + break; + } + case 'note': { + color = 'blue'; + icon = '•'; + + break; + } + case 'tip': { + color = 'green'; + icon = '•'; + + break; + } + case 'warning': { + color = 'yellow'; + icon = '•'; + + break; + } + case 'caution': { + color = 'yellow light'; + icon = '•'; + + break; + } + default: { + color = 'blue'; + icon = '•'; + } + } + + return `

${ + token.content[0].toUpperCase() + token.content.slice(1).toLowerCase() + }

\n`; + }, }); md.renderer.rules.footnote_anchor = () => ''; diff --git a/package.json b/package.json index a3a3648..602c573 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,10 @@ "markdown": "bin/markdown.js", "md": "bin/markdown.js" }, + "engines": { + "node": ">=16.0.0", + "npm": ">=7.0.0" + }, "scripts": { "test": "echo \"Error: no test specified\" && exit 0", "fix": "eslint --quiet --fix *.js bin/*.js .eslintrc.cjs --ignore-pattern '!.eslintrc.js'" @@ -19,7 +23,7 @@ "dependencies": { "@mdit/plugin-alert": "^0.10.1", "@types/marked": "^6.0.0", - "cli-html": "^4.1.0", + "cli-html": "^4.2.0", "concat-stream": "^2.0.0", "markdown-it": "^14.1.0", "markdown-it-abbr": "^2.0.0", @@ -50,10 +54,6 @@ "eslint-plugin-unicorn": "^53.0.0", "eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0" }, - "engines": { - "node": ">=16.0.0", - "npm": ">=7.0.0" - }, "author": "Grigorii Horos ", "license": "GPL-3.0-or-later", "repository": {