├── .gitignore ├── .travis.yml ├── .vscode └── launch.json ├── LICENSE ├── index.js ├── package-lock.json ├── package.json ├── readme.md └── test ├── fixtures └── admonition.txt ├── markdown-it-admonition.js └── mocha.opts /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - '7' 5 | - '8' 6 | - '9' 7 | os: 8 | - linux 9 | # - osx 10 | # - windows 11 | jobs: 12 | include: 13 | - stage: Test 14 | script: npm test -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "type": "node", 9 | "request": "launch", 10 | "name": "Mocha All", 11 | "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", 12 | "args": [ 13 | "--timeout", 14 | "999999", 15 | "--colors", 16 | "${workspaceFolder}/test" 17 | ], 18 | "console": "integratedTerminal", 19 | "internalConsoleOptions": "neverOpen" 20 | }, 21 | { 22 | "type": "node", 23 | "request": "launch", 24 | "name": "Mocha Current File", 25 | "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", 26 | "args": [ 27 | "--timeout", 28 | "999999", 29 | "--colors", 30 | "${file}" 31 | ], 32 | "console": "integratedTerminal", 33 | "internalConsoleOptions": "neverOpen" 34 | }] 35 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 docarys 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | 4 | module.exports = function admonitionPlugin(md, options) { 5 | 6 | options = options || {}; 7 | 8 | var minMarkers = 3, 9 | markerStr = options.marker || "!", 10 | markerChar = markerStr.charCodeAt(0), 11 | markerLen = markerStr.length, 12 | validate = validateDefault, 13 | render = renderDefault, 14 | type = "", 15 | title = null, 16 | types = options.types || ["note", "abstract", "info", "tip", "success", "question", "warning", "failure", "danger", "bug", "example", "quote"]; 17 | 18 | function renderDefault(tokens, idx, _options, env, self) { 19 | 20 | var token = tokens[idx]; 21 | 22 | if (token.type === "admonition_open") { 23 | tokens[idx].attrPush([ "class", "admonition " + token.info ]); 24 | } 25 | 26 | else if (token.type === "admonition_title_open") { 27 | tokens[idx].attrPush([ "class", "admonition-title"]); 28 | } 29 | 30 | return self.renderToken(tokens, idx, _options, env, self); 31 | } 32 | 33 | function validateDefault(params){ 34 | var array = params.trim().split(" ", 2); 35 | title = ""; 36 | type = array[0]; 37 | if (array.length > 1) { 38 | title = params.substring(type.length + 2); 39 | } 40 | 41 | if ( title === "" || !title ) { 42 | title = type; 43 | } 44 | 45 | return types.includes(type); 46 | } 47 | 48 | function admonition(state, startLine, endLine, silent) { 49 | var pos, nextLine, markerCount, markup, params, token, 50 | oldParent, oldLineMax, 51 | autoClosed = false, 52 | start = state.bMarks[startLine] + state.tShift[startLine], 53 | max = state.eMarks[startLine]; 54 | 55 | // Check out the first character quickly, 56 | // this should filter out most of non-containers 57 | // 58 | if (markerChar !== state.src.charCodeAt(start)) { return false; } 59 | 60 | // Check out the rest of the marker string 61 | // 62 | for (pos = start + 1; pos <= max; pos++) { 63 | if (markerStr[(pos - start) % markerLen] !== state.src[pos]) { 64 | break; 65 | } 66 | } 67 | 68 | markerCount = Math.floor((pos - start) / markerLen); 69 | if (markerCount < minMarkers) { return false; } 70 | pos -= (pos - start) % markerLen; 71 | 72 | markup = state.src.slice(start, pos); 73 | params = state.src.slice(pos, max); 74 | if (!validate(params)) { return false; } 75 | 76 | // Since start is found, we can report success here in validation mode 77 | // 78 | if (silent) { return true; } 79 | 80 | // Search for the end of the block 81 | // 82 | nextLine = startLine; 83 | 84 | for (;;) { 85 | nextLine++; 86 | if (nextLine >= endLine) { 87 | // unclosed block should be autoclosed by end of document. 88 | // also block seems to be autoclosed by end of parent 89 | break; 90 | } 91 | 92 | start = state.bMarks[nextLine] + state.tShift[nextLine]; 93 | max = state.eMarks[nextLine]; 94 | 95 | if (start < max && state.sCount[nextLine] < state.blkIndent) { 96 | // non-empty line with negative indent should stop the list: 97 | // - ``` 98 | // test 99 | break; 100 | } 101 | 102 | if (markerChar !== state.src.charCodeAt(start)) { continue; } 103 | 104 | if (state.sCount[nextLine] - state.blkIndent >= 4) { 105 | // closing fence should be indented less than 4 spaces 106 | continue; 107 | } 108 | 109 | for (pos = start + 1; pos <= max; pos++) { 110 | if (markerStr[(pos - start) % markerLen] !== state.src[pos]) { 111 | break; 112 | } 113 | } 114 | 115 | // closing adminition fence must be at least as long as the opening one 116 | if (Math.floor((pos - start) / markerLen) < markerCount) { continue; } 117 | 118 | // make sure tail has spaces only 119 | pos -= (pos - start) % markerLen; 120 | pos = state.skipSpaces(pos); 121 | 122 | if (pos < max) { continue; } 123 | 124 | // found! 125 | autoClosed = true; 126 | break; 127 | } 128 | 129 | oldParent = state.parentType; 130 | oldLineMax = state.lineMax; 131 | state.parentType = "admonition"; 132 | 133 | // this will prevent lazy continuations from ever going past our end marker 134 | state.lineMax = nextLine; 135 | 136 | token = state.push("admonition_open", "div", 1); 137 | token.markup = markup; 138 | token.block = true; 139 | token.info = type; 140 | token.map = [ startLine, nextLine ]; 141 | 142 | // admonition title 143 | token = state.push("admonition_title_open", "p", 1); 144 | token.markup = markup + " " + type; 145 | token.map = [ startLine, nextLine ]; 146 | 147 | token = state.push("inline", "", 0); 148 | token.content = title; 149 | token.map = [ startLine, state.line - 1 ]; 150 | token.children = []; 151 | 152 | token = state.push("admonition_title_close", "p", -1); 153 | token.markup = markup + " " + type; 154 | 155 | state.md.block.tokenize(state, startLine + 1, nextLine); 156 | 157 | token = state.push("admonition_close", "div", -1); 158 | token.markup = state.src.slice(start, pos); 159 | token.block = true; 160 | 161 | state.parentType = oldParent; 162 | state.lineMax = oldLineMax; 163 | state.line = nextLine + (autoClosed ? 1 : 0); 164 | 165 | return true; 166 | } 167 | 168 | md.block.ruler.before("code", "admonition", admonition, { 169 | alt: ["paragraph", "reference", "blockquote", "list" ] 170 | }); 171 | md.renderer.rules["admonition_open"] = render; 172 | md.renderer.rules["admonition_title_open"] = render; 173 | md.renderer.rules["admonition_title_close"] = render; 174 | md.renderer.rules["admonition_close"] = render; 175 | }; -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-it-admonition", 3 | "version": "1.0.3", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "argparse": { 8 | "version": "1.0.10", 9 | "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", 10 | "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", 11 | "dev": true, 12 | "requires": { 13 | "sprintf-js": "1.0.3" 14 | } 15 | }, 16 | "assertion-error": { 17 | "version": "1.0.0", 18 | "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.0.tgz", 19 | "integrity": "sha1-x/hUOP3UZrx8oWq5DIFRN5el0js=", 20 | "dev": true 21 | }, 22 | "balanced-match": { 23 | "version": "1.0.0", 24 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 25 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", 26 | "dev": true 27 | }, 28 | "brace-expansion": { 29 | "version": "1.1.11", 30 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 31 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 32 | "dev": true, 33 | "requires": { 34 | "balanced-match": "1.0.0", 35 | "concat-map": "0.0.1" 36 | } 37 | }, 38 | "browser-stdout": { 39 | "version": "1.3.1", 40 | "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", 41 | "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", 42 | "dev": true 43 | }, 44 | "chai": { 45 | "version": "1.10.0", 46 | "resolved": "https://registry.npmjs.org/chai/-/chai-1.10.0.tgz", 47 | "integrity": "sha1-5AMcyHZURhp1lD5aNatG6vOcHrk=", 48 | "dev": true, 49 | "requires": { 50 | "assertion-error": "1.0.0", 51 | "deep-eql": "0.1.3" 52 | } 53 | }, 54 | "commander": { 55 | "version": "2.15.1", 56 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.15.1.tgz", 57 | "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==", 58 | "dev": true 59 | }, 60 | "concat-map": { 61 | "version": "0.0.1", 62 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 63 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", 64 | "dev": true 65 | }, 66 | "debug": { 67 | "version": "3.1.0", 68 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 69 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 70 | "dev": true, 71 | "requires": { 72 | "ms": "2.0.0" 73 | } 74 | }, 75 | "deep-eql": { 76 | "version": "0.1.3", 77 | "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", 78 | "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", 79 | "dev": true, 80 | "requires": { 81 | "type-detect": "0.1.1" 82 | } 83 | }, 84 | "diff": { 85 | "version": "3.5.0", 86 | "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", 87 | "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", 88 | "dev": true 89 | }, 90 | "entities": { 91 | "version": "1.1.1", 92 | "resolved": "https://registry.npmjs.org/entities/-/entities-1.1.1.tgz", 93 | "integrity": "sha1-blwtClYhtdra7O+AuQ7ftc13cvA=", 94 | "dev": true 95 | }, 96 | "escape-string-regexp": { 97 | "version": "1.0.5", 98 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", 99 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", 100 | "dev": true 101 | }, 102 | "esprima": { 103 | "version": "2.0.0", 104 | "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.0.0.tgz", 105 | "integrity": "sha1-YJrFwmZ+rlQztB657OziMxtBSY8=", 106 | "dev": true 107 | }, 108 | "fs.realpath": { 109 | "version": "1.0.0", 110 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 111 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", 112 | "dev": true 113 | }, 114 | "glob": { 115 | "version": "7.1.2", 116 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 117 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", 118 | "dev": true, 119 | "requires": { 120 | "fs.realpath": "1.0.0", 121 | "inflight": "1.0.6", 122 | "inherits": "2.0.3", 123 | "minimatch": "3.0.4", 124 | "once": "1.4.0", 125 | "path-is-absolute": "1.0.1" 126 | } 127 | }, 128 | "growl": { 129 | "version": "1.10.5", 130 | "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", 131 | "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", 132 | "dev": true 133 | }, 134 | "has-flag": { 135 | "version": "3.0.0", 136 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", 137 | "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", 138 | "dev": true 139 | }, 140 | "he": { 141 | "version": "1.1.1", 142 | "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", 143 | "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", 144 | "dev": true 145 | }, 146 | "inflight": { 147 | "version": "1.0.6", 148 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 149 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 150 | "dev": true, 151 | "requires": { 152 | "once": "1.4.0", 153 | "wrappy": "1.0.2" 154 | } 155 | }, 156 | "inherits": { 157 | "version": "2.0.3", 158 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 159 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", 160 | "dev": true 161 | }, 162 | "js-yaml": { 163 | "version": "3.2.7", 164 | "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.2.7.tgz", 165 | "integrity": "sha1-ECeQ8mXZhv6VpNDyp5Lnp72Ibuw=", 166 | "dev": true, 167 | "requires": { 168 | "argparse": "1.0.10", 169 | "esprima": "2.0.0" 170 | } 171 | }, 172 | "linkify-it": { 173 | "version": "2.0.3", 174 | "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz", 175 | "integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=", 176 | "dev": true, 177 | "requires": { 178 | "uc.micro": "1.0.5" 179 | } 180 | }, 181 | "lodash": { 182 | "version": "2.4.2", 183 | "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz", 184 | "integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=", 185 | "dev": true 186 | }, 187 | "markdown-it": { 188 | "version": "8.4.1", 189 | "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.1.tgz", 190 | "integrity": "sha512-CzzqSSNkFRUf9vlWvhK1awpJreMRqdCrBvZ8DIoDWTOkESMIF741UPAhuAmbyWmdiFPA6WARNhnu2M6Nrhwa+A==", 191 | "dev": true, 192 | "requires": { 193 | "argparse": "1.0.10", 194 | "entities": "1.1.1", 195 | "linkify-it": "2.0.3", 196 | "mdurl": "1.0.1", 197 | "uc.micro": "1.0.5" 198 | } 199 | }, 200 | "markdown-it-testgen": { 201 | "version": "0.1.4", 202 | "resolved": "https://registry.npmjs.org/markdown-it-testgen/-/markdown-it-testgen-0.1.4.tgz", 203 | "integrity": "sha1-/NE5ibR2tRP+XUCBGK8JC1S2pGw=", 204 | "dev": true, 205 | "requires": { 206 | "chai": "1.10.0", 207 | "js-yaml": "3.2.7", 208 | "lodash": "2.4.2" 209 | } 210 | }, 211 | "mdurl": { 212 | "version": "1.0.1", 213 | "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", 214 | "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=", 215 | "dev": true 216 | }, 217 | "minimatch": { 218 | "version": "3.0.4", 219 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 220 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 221 | "dev": true, 222 | "requires": { 223 | "brace-expansion": "1.1.11" 224 | } 225 | }, 226 | "minimist": { 227 | "version": "0.0.8", 228 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", 229 | "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", 230 | "dev": true 231 | }, 232 | "mkdirp": { 233 | "version": "0.5.1", 234 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", 235 | "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", 236 | "dev": true, 237 | "requires": { 238 | "minimist": "0.0.8" 239 | } 240 | }, 241 | "mocha": { 242 | "version": "5.2.0", 243 | "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", 244 | "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", 245 | "dev": true, 246 | "requires": { 247 | "browser-stdout": "1.3.1", 248 | "commander": "2.15.1", 249 | "debug": "3.1.0", 250 | "diff": "3.5.0", 251 | "escape-string-regexp": "1.0.5", 252 | "glob": "7.1.2", 253 | "growl": "1.10.5", 254 | "he": "1.1.1", 255 | "minimatch": "3.0.4", 256 | "mkdirp": "0.5.1", 257 | "supports-color": "5.4.0" 258 | } 259 | }, 260 | "ms": { 261 | "version": "2.0.0", 262 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 263 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", 264 | "dev": true 265 | }, 266 | "once": { 267 | "version": "1.4.0", 268 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 269 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 270 | "dev": true, 271 | "requires": { 272 | "wrappy": "1.0.2" 273 | } 274 | }, 275 | "path-is-absolute": { 276 | "version": "1.0.1", 277 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 278 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", 279 | "dev": true 280 | }, 281 | "sprintf-js": { 282 | "version": "1.0.3", 283 | "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", 284 | "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", 285 | "dev": true 286 | }, 287 | "supports-color": { 288 | "version": "5.4.0", 289 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", 290 | "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", 291 | "dev": true, 292 | "requires": { 293 | "has-flag": "3.0.0" 294 | } 295 | }, 296 | "type-detect": { 297 | "version": "0.1.1", 298 | "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", 299 | "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", 300 | "dev": true 301 | }, 302 | "uc.micro": { 303 | "version": "1.0.5", 304 | "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.5.tgz", 305 | "integrity": "sha512-JoLI4g5zv5qNyT09f4YAvEZIIV1oOjqnewYg5D38dkQljIzpPT296dbIGvKro3digYI1bkb7W6EP1y4uDlmzLg==", 306 | "dev": true 307 | }, 308 | "wrappy": { 309 | "version": "1.0.2", 310 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 311 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 312 | "dev": true 313 | } 314 | } 315 | } 316 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "markdown-it-admonition", 3 | "version": "1.0.4", 4 | "description": "Markdown-it admonition plugin", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/docarys/markdown-it-admonition.git" 12 | }, 13 | "keywords": [ 14 | "markdown-it", 15 | "admonition" 16 | ], 17 | "author": "Sergio Sisternes ", 18 | "files": [ 19 | "readme.md", 20 | "LICENSE", 21 | "index.js" 22 | ], 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/docarys/markdown-it-admonition/issues" 26 | }, 27 | "homepage": "https://github.com/docarys/markdown-it-admonition#readme", 28 | "devDependencies": { 29 | "markdown-it": "^8.4.1", 30 | "markdown-it-testgen": "^0.1.4", 31 | "mocha": "^5.2.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | [![Travis][travis-image]][travis-link] 2 | [![npm][npm-image]][npm-link] 3 | 4 | 5 | [travis-image]: https://travis-ci.org/docarys/markdown-it-admonition.svg?branch=master 6 | [travis-link]: https://travis-ci.org/docarys/markdown-it-admonition 7 | [npm-image]: https://img.shields.io/npm/dt/markdown-it-admonition.svg 8 | [npm-link]: https://www.npmjs.com/package/markdown-it-admonition 9 | 10 | # Admonition plug-in 11 | 12 | A simple admonition plugin for markdown-it 13 | 14 | ## Usage 15 | 16 | To use this plugin, simply: 17 | 18 | ```bash 19 | npm install markdown-it-admonition --save 20 | ``` 21 | 22 | ```js 23 | var markdown = require("markdown-it")({html: true}) 24 | .use(require("markdown-it-admonition")); 25 | ``` 26 | 27 | ```md 28 | !!! note This is the admonition title 29 | This is the admonition body 30 | !!! 31 | ```` 32 | 33 | This will output the following HTML 34 | 35 | ```html 36 |
37 |

This is the admonition title

38 |

This is the admonition body

39 |
40 | ``` 41 | 42 | The following adminition types, supported by Docarys, are recognized by this plugin: 43 | 44 | | Type | 45 | | -----------| 46 | | note | 47 | | abstract | 48 | | info | 49 | | tip | 50 | | success | 51 | | question | 52 | | warning | 53 | | failure | 54 | | danger | 55 | | bug | 56 | | example | 57 | | quote" | 58 | 59 | You can customize the types you want to use by passing it as opts. 60 | 61 | > if no title is specified, admonition type will be used as default title. 62 | -------------------------------------------------------------------------------- /test/fixtures/admonition.txt: -------------------------------------------------------------------------------- 1 | #5 Bad admonition title 2 | . 3 | !!! note Note Title 4 | admonition body 5 | !!! 6 | . 7 |
8 |

Note Title

9 |

admonition body

10 |
11 | . -------------------------------------------------------------------------------- /test/markdown-it-admonition.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var generate = require('markdown-it-testgen'); 5 | 6 | describe('markdown-it', function () { 7 | var markdown = require("markdown-it")({html: true}) 8 | .use(require("../index.js")); 9 | 10 | generate(path.join(__dirname, 'fixtures'), markdown); 11 | }); -------------------------------------------------------------------------------- /test/mocha.opts: -------------------------------------------------------------------------------- 1 | -R spec --inline-diffs --------------------------------------------------------------------------------