diff --git a/lib/renderer.js b/lib/renderer.js index 6a9e524..d19b954 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -40,14 +40,17 @@ default_rules.fence = function (tokens, idx, options, env, slf) { var token = tokens[idx], info = token.info ? unescapeAll(token.info).trim() : '', langName = '', - highlighted, i, tmpAttrs, tmpToken; + langAttrs = '', + highlighted, i, arr, tmpAttrs, tmpToken; if (info) { - langName = info.split(/\s+/g)[0]; + arr = info.split(/(\s+)/g); + langName = arr[0]; + langAttrs = arr.slice(2).join(''); } if (options.highlight) { - highlighted = options.highlight(token.content, langName) || escapeHtml(token.content); + highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content); } else { highlighted = escapeHtml(token.content); } diff --git a/test/misc.js b/test/misc.js index c933afa..e71ad35 100644 --- a/test/misc.js +++ b/test/misc.js @@ -62,6 +62,18 @@ describe('API', function () { assert.strictEqual(md.render('```\n&\n```'), '
&\n
\n');
});
+ it('highlight arguments', function () {
+ var md = markdownit({
+ highlight: function (str, lang, attrs) {
+ assert.strictEqual(lang, 'a');
+ assert.strictEqual(attrs, 'b c d');
+ return '==' + str + '==
';
+ }
+ });
+
+ assert.strictEqual(md.render('``` a b c d \nhl\n```'), '==hl\n==
\n');
+ });
+
it('force hardbreaks', function () {
var md = markdownit({ breaks: true });