Skip to content

Commit

Permalink
Merge pull request #42 from bem-site/BEMINFO-1326
Browse files Browse the repository at this point in the history
Fixed a bug not correctly check whether the file contains html
  • Loading branch information
tavriaforever committed Jul 20, 2015
2 parents 6570e80 + d934dfb commit 554433b
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,14 @@ exports.getStorageConfiguration = function (config, env) {
return _.extend({}, common, config[env]);
};

// this method has been taken from cheerio module code
// https://github.com/cheeriojs/cheerio/blob/master/lib/cheerio.js#L122
/**
* Checks if given string is html string
* @param {String} str (can be markdown or html string)
* @returns {boolean}
*/
exports.isHtml = function (str) {
if (str.charAt(0) === '<' &&
str.charAt(str.length - 1) === '>' &&
str.length >= 3) {
return true;
}

var match = /^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/.exec(str);
return !!(match && match[1]);
var length = str.length;
return str.charAt(0) === '<' && str.charAt(length - 1) === '>' && length >= 3;
};

/**
Expand All @@ -60,7 +52,7 @@ exports.mdToHtml = function (content) {
return md(content, {
gfm: true,
pedantic: false,
sanitize: false,
sanitize: true,
renderer: bmdr.getRenderer()
});
};
Expand Down

0 comments on commit 554433b

Please sign in to comment.