Browse Source

moved normalizeReference to utils, closes #42

pull/52/head
Vitaly Puzrin 10 years ago
parent
commit
e77666c4a0
  1. 38
      lib/common/utils.js
  2. 11
      lib/helpers/normalize_reference.js
  3. 2
      lib/rules_block/reference.js
  4. 2
      lib/rules_inline/image.js
  5. 2
      lib/rules_inline/link.js

38
lib/common/utils.js

@ -278,22 +278,32 @@ function isMdAsciiPunct(ch) {
}
}
// Hepler to unify [reference labels].
//
function normalizeReference(str) {
// use .toUpperCase() instead of .toLowerCase()
// here to avoid a conflict with Object.prototype
// members (most notably, `__proto__`)
return str.trim().replace(/\s+/g, ' ').toUpperCase();
}
////////////////////////////////////////////////////////////////////////////////
exports.assign = assign;
exports.isString = isString;
exports.has = has;
exports.unescapeMd = unescapeMd;
exports.isValidEntityCode = isValidEntityCode;
exports.fromCodePoint = fromCodePoint;
exports.replaceEntities = replaceEntities;
exports.escapeHtml = escapeHtml;
exports.arrayReplaceAt = arrayReplaceAt;
exports.normalizeLink = normalizeLink;
exports.isWhiteSpace = isWhiteSpace;
exports.isMdAsciiPunct = isMdAsciiPunct;
exports.isPunctChar = isPunctChar;
exports.escapeRE = escapeRE;
exports.assign = assign;
exports.isString = isString;
exports.has = has;
exports.unescapeMd = unescapeMd;
exports.isValidEntityCode = isValidEntityCode;
exports.fromCodePoint = fromCodePoint;
exports.replaceEntities = replaceEntities;
exports.escapeHtml = escapeHtml;
exports.arrayReplaceAt = arrayReplaceAt;
exports.normalizeLink = normalizeLink;
exports.isWhiteSpace = isWhiteSpace;
exports.isMdAsciiPunct = isMdAsciiPunct;
exports.isPunctChar = isPunctChar;
exports.escapeRE = escapeRE;
exports.normalizeReference = normalizeReference;
// for testing only
exports.fixBrokenSurrogates = fixBrokenSurrogates;

11
lib/helpers/normalize_reference.js

@ -1,11 +0,0 @@
'use strict';
// Hepler to [reference labels]. No better place for this code :)
// It's only for refs/links and should not be exported anywhere.
module.exports = function normalizeReference(str) {
// use .toUpperCase() instead of .toLowerCase()
// here to avoid a conflict with Object.prototype
// members (most notably, `__proto__`)
return str.trim().replace(/\s+/g, ' ').toUpperCase();
};

2
lib/rules_block/reference.js

@ -3,7 +3,7 @@
var parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title');
var normalizeReference = require('../helpers/normalize_reference');
var normalizeReference = require('../common/utils').normalizeReference;
module.exports = function reference(state, startLine, _endLine, silent) {

2
lib/rules_inline/image.js

@ -5,7 +5,7 @@
var parseLinkLabel = require('../helpers/parse_link_label');
var parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title');
var normalizeReference = require('../helpers/normalize_reference');
var normalizeReference = require('../common/utils').normalizeReference;
module.exports = function image(state, silent) {

2
lib/rules_inline/link.js

@ -5,7 +5,7 @@
var parseLinkLabel = require('../helpers/parse_link_label');
var parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title');
var normalizeReference = require('../helpers/normalize_reference');
var normalizeReference = require('../common/utils').normalizeReference;
module.exports = function link(state, silent) {

Loading…
Cancel
Save