Browse Source

Dropped custom fences support - overcomplication

pull/24/head
Vitaly Puzrin 10 years ago
parent
commit
d5f43dd9b6
  1. 22
      lib/renderer.js
  2. 20
      test/misc.js

22
lib/renderer.js

@ -9,7 +9,6 @@
var assign = require('./common/utils').assign;
var has = require('./common/utils').has;
var unescapeMd = require('./common/utils').unescapeMd;
var replaceEntities = require('./common/utils').replaceEntities;
var escapeHtml = require('./common/utils').escapeHtml;
@ -38,29 +37,15 @@ rules.code = function (tokens, idx /*, options, env */) {
};
rules.fence = function (tokens, idx, options, env, self) {
rules.fence = function (tokens, idx, options /*, env, self*/) {
var token = tokens[idx];
var langClass = '';
var langPrefix = options.langPrefix;
var langName = '', fenceName;
var langName = '';
var highlighted;
if (token.params) {
//
// ```foo bar
//
// Try custom renderer "foo" first. That will simplify overwrite
// for diagrams, latex, and any other fenced block with custom look
//
fenceName = token.params.split(/\s+/g)[0];
if (has(self.rules.fence_custom, fenceName)) {
return self.rules.fence_custom[fenceName](tokens, idx, options, env, self);
}
langName = escapeHtml(replaceEntities(unescapeMd(fenceName)));
langName = escapeHtml(replaceEntities(unescapeMd(token.params.split(/\s+/g)[0])));
langClass = ' class="' + langPrefix + langName + '"';
}
@ -76,7 +61,6 @@ rules.fence = function (tokens, idx, options, env, self) {
+ '</code></pre>\n';
};
rules.fence_custom = {};
rules.heading_open = function (tokens, idx /*, options, env */) {
return '<h' + tokens[idx].hLevel + '>';

20
test/misc.js

@ -236,23 +236,3 @@ describe('Links validation', function () {
});
});
describe('Custom fences', function () {
it('should render differently overriden rule', function () {
var md = markdownit();
md.renderer.rules.fence_custom.foo = function (tokens, idx /*, options, env */) {
return '<div class="foo">' +
md.utils.escapeHtml(tokens[idx].content) +
'</div>\n';
};
var text = '```foo bar\n' +
'123&45\n' +
'```';
assert.strictEqual(md.render(text), '<div class="foo">123&amp;45\n</div>\n');
});
});

Loading…
Cancel
Save