From e77666c4a0cd486fa28ad094d80bb97ec73e87ee Mon Sep 17 00:00:00 2001 From: Vitaly Puzrin Date: Tue, 10 Feb 2015 19:54:46 +0300 Subject: [PATCH] moved normalizeReference to utils, closes #42 --- lib/common/utils.js | 38 +++++++++++++++++++----------- lib/helpers/normalize_reference.js | 11 --------- lib/rules_block/reference.js | 2 +- lib/rules_inline/image.js | 2 +- lib/rules_inline/link.js | 2 +- 5 files changed, 27 insertions(+), 28 deletions(-) delete mode 100644 lib/helpers/normalize_reference.js diff --git a/lib/common/utils.js b/lib/common/utils.js index 2a69999..da99b71 100644 --- a/lib/common/utils.js +++ b/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; diff --git a/lib/helpers/normalize_reference.js b/lib/helpers/normalize_reference.js deleted file mode 100644 index 26b9215..0000000 --- a/lib/helpers/normalize_reference.js +++ /dev/null @@ -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(); -}; diff --git a/lib/rules_block/reference.js b/lib/rules_block/reference.js index 3b30104..471b4d2 100644 --- a/lib/rules_block/reference.js +++ b/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) { diff --git a/lib/rules_inline/image.js b/lib/rules_inline/image.js index 0a6a9bc..d243c31 100644 --- a/lib/rules_inline/image.js +++ b/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) { diff --git a/lib/rules_inline/link.js b/lib/rules_inline/link.js index 524d5cf..6878116 100644 --- a/lib/rules_inline/link.js +++ b/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) {