Browse Source

Moved array element subst to utils

pull/14/head
Vitaly Puzrin 10 years ago
parent
commit
4a34e7b742
  1. 6
      lib/common/utils.js
  2. 4
      lib/index.js
  3. 5
      lib/rules_core/abbr2.js
  4. 5
      lib/rules_core/linkify.js

6
lib/common/utils.js

@ -124,6 +124,11 @@ function escapeHtml(str) {
////////////////////////////////////////////////////////////////////////////////
function arrayReplaceAt(src, pos, newElements) {
return [].concat(src.slice(0, pos), newElements, src.slice(pos + 1));
}
exports.assign = assign;
exports.isString = isString;
exports.has = has;
@ -132,3 +137,4 @@ exports.isValidEntityCode = isValidEntityCode;
exports.fromCodePoint = fromCodePoint;
exports.replaceEntities = replaceEntities;
exports.escapeHtml = escapeHtml;
exports.arrayReplaceAt = arrayReplaceAt;

4
lib/index.js

@ -3,6 +3,7 @@
'use strict';
var utils = require('./common/utils');
var assign = require('./common/utils').assign;
var isString = require('./common/utils').isString;
var Renderer = require('./renderer');
@ -51,6 +52,9 @@ function MarkdownIt(presetName, options) {
this.renderer = new Renderer();
this.ruler = new Ruler();
// Expose utils for easy acces from plugins
this.utils = utils;
this.options = {};
this.configure(config[presetName]);

5
lib/rules_core/abbr2.js

@ -3,6 +3,9 @@
'use strict';
var arrayReplaceAt = require('../common/utils').arrayReplaceAt;
var PUNCT_CHARS = ' \n()[]\'".,!?-';
@ -82,7 +85,7 @@ module.exports = function abbr2(state) {
}
// replace current node
blockTokens[j].children = tokens = [].concat(tokens.slice(0, i), nodes, tokens.slice(i + 1));
blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes);
}
}
};

5
lib/rules_core/linkify.js

@ -5,7 +5,8 @@
'use strict';
var Autolinker = require('autolinker');
var Autolinker = require('autolinker');
var arrayReplaceAt = require('../common/utils').arrayReplaceAt;
var LINK_SCAN_RE = /www|@|\:\/\//;
@ -154,7 +155,7 @@ module.exports = function linkify(state) {
}
// replace current node
blockTokens[j].children = tokens = [].concat(tokens.slice(0, i), nodes, tokens.slice(i + 1));
blockTokens[j].children = tokens = arrayReplaceAt(tokens, i, nodes);
}
}
}

Loading…
Cancel
Save