@zhennann/markdown-it-block
Advanced tools
Comparing version 3.1.2 to 3.1.3
58
index.js
// Process block-level custom containers | ||
// | ||
module.exports = function block_plugin(md, options) { | ||
function blockRender(tokens, idx /* _options, env, self */) { | ||
@@ -49,16 +47,20 @@ // blockTitle | ||
let marker, | ||
len, | ||
params, | ||
nextLine, | ||
mem, | ||
token, | ||
markup, | ||
haveEndMarker = false, | ||
pos = state.bMarks[startLine] + state.tShift[startLine], | ||
max = state.eMarks[startLine]; | ||
len, | ||
params, | ||
nextLine, | ||
mem, | ||
token, | ||
markup, | ||
haveEndMarker = false, | ||
pos = state.bMarks[startLine] + state.tShift[startLine], | ||
max = state.eMarks[startLine]; | ||
// if it's indented more than 3 spaces, it should be a code block | ||
if (state.sCount[startLine] - state.blkIndent >= 4) { return false; } | ||
if (pos + 3 > max) { return false; } | ||
if (state.sCount[startLine] - state.blkIndent >= 4) { | ||
return false; | ||
} | ||
if (pos + 3 > max) { | ||
return false; | ||
} | ||
marker = state.src.charCodeAt(pos); | ||
if (marker !== 0x24/* $ */) { | ||
if (marker !== 0x24 /* $ */) { | ||
return false; | ||
@@ -70,8 +72,14 @@ } | ||
len = pos - mem; | ||
if (len < 3) { return false; } | ||
if (len < 3) { | ||
return false; | ||
} | ||
markup = state.src.slice(mem, pos); | ||
params = state.src.slice(pos, max); | ||
if (params.indexOf(String.fromCharCode(marker)) >= 0) { return false; } | ||
if (params.indexOf(String.fromCharCode(marker)) >= 0) { | ||
return false; | ||
} | ||
// Since start is found, we can report success here in validation mode | ||
if (silent) { return true; } | ||
if (silent) { | ||
return true; | ||
} | ||
// search end of block | ||
@@ -94,3 +102,5 @@ nextLine = startLine; | ||
} | ||
if (state.src.charCodeAt(pos) !== marker) { continue; } | ||
if (state.src.charCodeAt(pos) !== marker) { | ||
continue; | ||
} | ||
if (state.sCount[nextLine] - state.blkIndent >= 4) { | ||
@@ -102,6 +112,10 @@ // closing fence should be indented less than 4 spaces | ||
// closing code fence must be at least as long as the opening one | ||
if (pos - mem < len) { continue; } | ||
if (pos - mem < len) { | ||
continue; | ||
} | ||
// make sure tail has spaces only | ||
pos = state.skipSpaces(pos); | ||
if (pos < max) { continue; } | ||
if (pos < max) { | ||
continue; | ||
} | ||
haveEndMarker = true; | ||
@@ -118,3 +132,3 @@ // found! | ||
token.markup = markup; | ||
token.map = [ startLine, state.line ]; | ||
token.map = [startLine, state.line]; | ||
return true; | ||
@@ -124,5 +138,5 @@ } | ||
md.block.ruler.before('fence', 'cabloy_cms_block', blockRuler, { | ||
alt: [ 'paragraph', 'reference', 'blockquote', 'list' ], | ||
alt: ['paragraph', 'reference', 'blockquote', 'list'], | ||
}); | ||
md.renderer.rules.cabloy_cms_block = blockRender; | ||
}; |
{ | ||
"name": "@zhennann/markdown-it-block", | ||
"version": "3.1.2", | ||
"version": "3.1.3", | ||
"description": "Plugin to create block-level custom tags for markdown-it markdown parser on Cabloy-CMS", | ||
@@ -27,3 +27,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "2d69c0a38865606ad899b3f49d27fe058ba4c5a7" | ||
"gitHead": "c9c1d67ebd79704564347422947e8e837276300d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5958
133