|
|
@ -11,12 +11,12 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
// options should override preset
|
|
|
|
var md = markdownit('commonmark', { html: false }); |
|
|
|
const md = markdownit('commonmark', { html: false }); |
|
|
|
assert.strictEqual(md.render('<!-- -->'), '<p><!-- --></p>\n'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('configure coverage', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
// conditions coverage
|
|
|
|
md.configure({}); |
|
|
@ -28,11 +28,11 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('plugin', function () { |
|
|
|
var succeeded = false; |
|
|
|
let succeeded = false; |
|
|
|
|
|
|
|
function plugin(slf, opts) { if (opts === 'bar') { succeeded = true; } } |
|
|
|
|
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.use(plugin, 'foo'); |
|
|
|
assert.strictEqual(succeeded, false); |
|
|
@ -41,7 +41,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('highlight', function () { |
|
|
|
var md = markdownit({ |
|
|
|
const md = markdownit({ |
|
|
|
highlight: function (str) { |
|
|
|
return '<pre><code>==' + str + '==</code></pre>'; |
|
|
|
} |
|
|
@ -51,7 +51,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('highlight escape by default', function () { |
|
|
|
var md = markdownit({ |
|
|
|
const md = markdownit({ |
|
|
|
highlight: function () { |
|
|
|
return ''; |
|
|
|
} |
|
|
@ -61,7 +61,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('highlight arguments', function () { |
|
|
|
var md = markdownit({ |
|
|
|
const md = markdownit({ |
|
|
|
highlight: function (str, lang, attrs) { |
|
|
|
assert.strictEqual(lang, 'a'); |
|
|
|
assert.strictEqual(attrs, 'b c d'); |
|
|
@ -73,7 +73,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('force hardbreaks', function () { |
|
|
|
var md = markdownit({ breaks: true }); |
|
|
|
const md = markdownit({ breaks: true }); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('a\nb'), '<p>a<br>\nb</p>\n'); |
|
|
|
md.set({ xhtmlOut: true }); |
|
|
@ -81,7 +81,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('xhtmlOut enabled', function () { |
|
|
|
var md = markdownit({ xhtmlOut: true }); |
|
|
|
const md = markdownit({ xhtmlOut: true }); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('---'), '<hr />\n'); |
|
|
|
assert.strictEqual(md.render('![]()'), '<p><img src="" alt="" /></p>\n'); |
|
|
@ -89,7 +89,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('xhtmlOut disabled', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('---'), '<hr>\n'); |
|
|
|
assert.strictEqual(md.render('![]()'), '<p><img src="" alt=""></p>\n'); |
|
|
@ -97,9 +97,9 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('bulk enable/disable rules in different chains', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
var was = { |
|
|
|
const was = { |
|
|
|
core: md.core.ruler.getRules('').length, |
|
|
|
block: md.block.ruler.getRules('').length, |
|
|
|
inline: md.inline.ruler.getRules('').length |
|
|
@ -108,7 +108,7 @@ describe('API', function () { |
|
|
|
// Disable 2 rule in each chain & compare result
|
|
|
|
md.disable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]); |
|
|
|
|
|
|
|
var now = { |
|
|
|
const now = { |
|
|
|
core: md.core.ruler.getRules('').length + 2, |
|
|
|
block: md.block.ruler.getRules('').length + 2, |
|
|
|
inline: md.inline.ruler.getRules('').length + 2 |
|
|
@ -119,7 +119,7 @@ describe('API', function () { |
|
|
|
// Enable the same rules back
|
|
|
|
md.enable([ 'block', 'inline', 'code', 'fence', 'emphasis', 'entity' ]); |
|
|
|
|
|
|
|
var back = { |
|
|
|
const back = { |
|
|
|
core: md.core.ruler.getRules('').length, |
|
|
|
block: md.block.ruler.getRules('').length, |
|
|
|
inline: md.inline.ruler.getRules('').length |
|
|
@ -129,7 +129,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('bulk enable/disable with errors control', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.throws(function () { |
|
|
|
md.enable([ 'link', 'code', 'invalid' ]); |
|
|
@ -146,7 +146,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('bulk enable/disable should understand strings', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.disable('emphasis'); |
|
|
|
assert(md.renderInline('_foo_'), '_foo_'); |
|
|
@ -156,7 +156,7 @@ describe('API', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('input type check', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.throws( |
|
|
|
function () { md.render(null); }, |
|
|
@ -170,7 +170,7 @@ describe('API', function () { |
|
|
|
describe('Plugins', function () { |
|
|
|
|
|
|
|
it('should not loop infinitely if all rules are disabled', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.inline.ruler.enableOnly([]); |
|
|
|
md.inline.ruler2.enableOnly([]); |
|
|
@ -180,7 +180,7 @@ describe('Plugins', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not loop infinitely if inline rule doesn\'t increment pos', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.inline.ruler.after('text', 'custom', function (state/*, silent*/) { |
|
|
|
if (state.src.charCodeAt(state.pos) !== 0x40/* @ */) return false; |
|
|
@ -192,10 +192,10 @@ describe('Plugins', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('should not loop infinitely if block rule doesn\'t increment pos', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.block.ruler.before('paragraph', 'custom', function (state, startLine/*, endLine, silent*/) { |
|
|
|
var pos = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
|
const pos = state.bMarks[startLine] + state.tShift[startLine]; |
|
|
|
if (state.src.charCodeAt(pos) !== 0x40/* @ */) return false; |
|
|
|
return true; |
|
|
|
}, { alt: [ 'paragraph' ] }); |
|
|
@ -209,13 +209,13 @@ describe('Plugins', function () { |
|
|
|
describe('Misc', function () { |
|
|
|
|
|
|
|
it('Should replace NULL characters', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('foo\u0000bar'), '<p>foo\uFFFDbar</p>\n'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should correctly parse strings without tailing \\n', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('123'), '<p>123</p>\n'); |
|
|
|
assert.strictEqual(md.render('123\n'), '<p>123</p>\n'); |
|
|
@ -225,19 +225,19 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should quickly exit on empty string', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.render(''), ''); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should parse inlines only', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.renderInline('a *b* c'), 'a <em>b</em> c'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Renderer should have pluggable inline and block rules', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
md.renderer.rules.em_open = function () { return '<it>'; }; |
|
|
|
md.renderer.rules.em_close = function () { return '</it>'; }; |
|
|
@ -248,7 +248,7 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Zero preset should disable everything', function () { |
|
|
|
var md = markdownit('zero'); |
|
|
|
const md = markdownit('zero'); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('___foo___'), '<p>___foo___</p>\n'); |
|
|
|
assert.strictEqual(md.renderInline('___foo___'), '___foo___'); |
|
|
@ -260,13 +260,13 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should correctly check block termination rules when those are disabled (#13)', function () { |
|
|
|
var md = markdownit('zero'); |
|
|
|
const md = markdownit('zero'); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('foo\nbar'), '<p>foo\nbar</p>\n'); |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should render link target attr', function () { |
|
|
|
var md = markdownit() |
|
|
|
const md = markdownit() |
|
|
|
.use(forInline, 'target', 'link_open', function (tokens, idx) { |
|
|
|
tokens[idx].attrs.push([ 'target', '_blank' ]); |
|
|
|
}); |
|
|
@ -275,7 +275,7 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should normalize CR to LF', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual( |
|
|
|
md.render('# test\r\r - hello\r - world\r'), |
|
|
@ -284,7 +284,7 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should normalize CR+LF to LF', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual( |
|
|
|
md.render('# test\r\n\r\n - hello\r\n - world\r\n'), |
|
|
@ -293,7 +293,7 @@ describe('Misc', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Should escape surrogate pairs (coverage)', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
assert.strictEqual(md.render('\\\uD835\uDC9C'), '<p>\\\uD835\uDC9C</p>\n'); |
|
|
|
assert.strictEqual(md.render('\\\uD835x'), '<p>\\\uD835x</p>\n'); |
|
|
@ -305,7 +305,7 @@ describe('Misc', function () { |
|
|
|
describe('Url normalization', function () { |
|
|
|
|
|
|
|
it('Should be overridable', function () { |
|
|
|
var md = markdownit({ linkify: true }); |
|
|
|
const md = markdownit({ linkify: true }); |
|
|
|
|
|
|
|
md.normalizeLink = function (url) { |
|
|
|
assert(url.match(/example\.com/), 'wrong url passed'); |
|
|
@ -330,7 +330,7 @@ describe('Url normalization', function () { |
|
|
|
describe('Links validation', function () { |
|
|
|
|
|
|
|
it('Override validator, disable everything', function () { |
|
|
|
var md = markdownit({ linkify: true }); |
|
|
|
const md = markdownit({ linkify: true }); |
|
|
|
|
|
|
|
md.validateLink = function () { return false; }; |
|
|
|
|
|
|
@ -348,7 +348,7 @@ describe('Links validation', function () { |
|
|
|
describe('maxNesting', function () { |
|
|
|
|
|
|
|
it('Block parser should not nest above limit', function () { |
|
|
|
var md = markdownit({ maxNesting: 2 }); |
|
|
|
const md = markdownit({ maxNesting: 2 }); |
|
|
|
assert.strictEqual( |
|
|
|
md.render('>foo\n>>bar\n>>>baz'), |
|
|
|
'<blockquote>\n<p>foo</p>\n<blockquote></blockquote>\n</blockquote>\n' |
|
|
@ -356,7 +356,7 @@ describe('maxNesting', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Inline parser should not nest above limit', function () { |
|
|
|
var md = markdownit({ maxNesting: 1 }); |
|
|
|
const md = markdownit({ maxNesting: 1 }); |
|
|
|
assert.strictEqual( |
|
|
|
md.render('[`foo`]()'), |
|
|
|
'<p><a href="">`foo`</a></p>\n' |
|
|
@ -364,7 +364,7 @@ describe('maxNesting', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('Inline nesting coverage', function () { |
|
|
|
var md = markdownit({ maxNesting: 2 }); |
|
|
|
const md = markdownit({ maxNesting: 2 }); |
|
|
|
assert.strictEqual( |
|
|
|
md.render('[[[[[[[[[[[[[[[[[[foo]()'), |
|
|
|
'<p>[[[[[[[[[[[[[[[[[[foo]()</p>\n' |
|
|
@ -375,7 +375,7 @@ describe('maxNesting', function () { |
|
|
|
|
|
|
|
|
|
|
|
describe('smartquotes', function () { |
|
|
|
var md = markdownit({ |
|
|
|
const md = markdownit({ |
|
|
|
typographer: true, |
|
|
|
|
|
|
|
// all strings have different length to make sure
|
|
|
@ -408,14 +408,14 @@ describe('smartquotes', function () { |
|
|
|
|
|
|
|
|
|
|
|
describe('Ordered list info', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
function type_filter(tokens, type) { |
|
|
|
return tokens.filter(function (t) { return t.type === type; }); |
|
|
|
} |
|
|
|
|
|
|
|
it('Should mark ordered list item tokens with info', function () { |
|
|
|
var tokens = md.parse('1. Foo\n2. Bar\n20. Fuzz'); |
|
|
|
let tokens = md.parse('1. Foo\n2. Bar\n20. Fuzz'); |
|
|
|
assert.strictEqual(type_filter(tokens, 'ordered_list_open').length, 1); |
|
|
|
tokens = type_filter(tokens, 'list_item_open'); |
|
|
|
assert.strictEqual(tokens.length, 3); |
|
|
@ -444,10 +444,10 @@ describe('Ordered list info', function () { |
|
|
|
|
|
|
|
describe('Token attributes', function () { |
|
|
|
it('.attrJoin', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
var tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
const tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
|
|
|
|
t.attrJoin('class', 'foo'); |
|
|
|
t.attrJoin('class', 'bar'); |
|
|
@ -459,10 +459,10 @@ describe('Token attributes', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('.attrSet', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
var tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
const tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
|
|
|
|
t.attrSet('class', 'foo'); |
|
|
|
|
|
|
@ -480,10 +480,10 @@ describe('Token attributes', function () { |
|
|
|
}); |
|
|
|
|
|
|
|
it('.attrGet', function () { |
|
|
|
var md = markdownit(); |
|
|
|
const md = markdownit(); |
|
|
|
|
|
|
|
var tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
const tokens = md.parse('```'), |
|
|
|
t = tokens[0]; |
|
|
|
|
|
|
|
assert.strictEqual(t.attrGet('myattr'), null); |
|
|
|
|
|
|
|