html-truncate
Advanced tools
Comparing version 0.3.0 to 0.3.1
@@ -6,3 +6,3 @@ { | ||
"description": "truncate html text and keep tag safe", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -22,7 +22,9 @@ /** | ||
, KEY_VALUE_REGEX = '(\\w+\\s*=\\s*"[^"]*"\\s*)*' | ||
, SELF_CLOSE_REGEX = '\\s*\\/?\\s*' | ||
, HTML_TAG_REGEX = new RegExp('<\\/?\\w+\\s*' + KEY_VALUE_REGEX + SELF_CLOSE_REGEX + '>') | ||
, IMAGE_TAG_REGEX = new RegExp('<img\\s*' + KEY_VALUE_REGEX + SELF_CLOSE_REGEX + '>') | ||
, IS_CLOSE_REGEX = '\\s*\\/?\\s*' | ||
, CLOSE_REGEX = '\\s*\\/\\s*' | ||
, SELF_CLOSE_REGEX = new RegExp('<\\/?\\w+\\s*' + KEY_VALUE_REGEX + CLOSE_REGEX + '>') | ||
, HTML_TAG_REGEX = new RegExp('<\\/?\\w+\\s*' + KEY_VALUE_REGEX + IS_CLOSE_REGEX + '>') | ||
, IMAGE_TAG_REGEX = new RegExp('<img\\s*' + KEY_VALUE_REGEX + IS_CLOSE_REGEX + '>') | ||
, matches = true | ||
, result, index, tail, tag; | ||
, result, index, tail, tag, selfClose; | ||
@@ -112,12 +114,19 @@ /** | ||
} else { | ||
tag = _getTag(result); | ||
selfClose = SELF_CLOSE_REGEX.exec(result); | ||
if ( ! selfClose) { | ||
tag = _getTag(result); | ||
items.push(tag); | ||
items.push(tag); | ||
} | ||
} | ||
content += result; | ||
if (selfClose) { | ||
content += selfClose[0]; | ||
} else { | ||
content += result; | ||
} | ||
string = string.substring(index + result.length); | ||
} | ||
if (options.ellipsis) { | ||
if (string.length > maxLength && options.ellipsis) { | ||
content += options.ellipsis; | ||
@@ -124,0 +133,0 @@ } |
Sorry, the diff of this file is not supported yet
15482
119