Browse Source

moved normalizeReference to utils, closes #42

pull/52/head
Vitaly Puzrin 10 years ago
parent
commit
e77666c4a0
  1. 10
      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

10
lib/common/utils.js

@ -278,6 +278,15 @@ 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.assign = assign;
@ -294,6 +303,7 @@ exports.isWhiteSpace = isWhiteSpace;
exports.isMdAsciiPunct = isMdAsciiPunct; exports.isMdAsciiPunct = isMdAsciiPunct;
exports.isPunctChar = isPunctChar; exports.isPunctChar = isPunctChar;
exports.escapeRE = escapeRE; exports.escapeRE = escapeRE;
exports.normalizeReference = normalizeReference;
// for testing only // for testing only
exports.fixBrokenSurrogates = fixBrokenSurrogates; 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 parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title'); 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) { 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 parseLinkLabel = require('../helpers/parse_link_label');
var parseLinkDestination = require('../helpers/parse_link_destination'); var parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title'); 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) { module.exports = function image(state, silent) {

2
lib/rules_inline/link.js

@ -5,7 +5,7 @@
var parseLinkLabel = require('../helpers/parse_link_label'); var parseLinkLabel = require('../helpers/parse_link_label');
var parseLinkDestination = require('../helpers/parse_link_destination'); var parseLinkDestination = require('../helpers/parse_link_destination');
var parseLinkTitle = require('../helpers/parse_link_title'); 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) { module.exports = function link(state, silent) {

Loading…
Cancel
Save