Skip to content

Commit

Permalink
Added regression test and functionality to not collapse whitespace fo…
Browse files Browse the repository at this point in the history
…r heading tags
  • Loading branch information
johantell committed Sep 7, 2016
1 parent 8b50386 commit c43001c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -213,12 +213,15 @@ function htmlmin (str, options) {
}

if (options.collapseWhitespace) {

var nonCollapsedWhiteSpaceElements = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']

// left trim
if (lastTag) {
text = text.replace(/^[\n\s\t\r]+/im, '')
}

if (lastTag !== 'p' && lastTag) {
if (nonCollapsedWhiteSpaceElements.indexOf(lastTag) == -1 && lastTag) {
text = text.replace(/[\n\s\t\r]+$/im, '')
}

Expand Down
3 changes: 3 additions & 0 deletions test/allSpec.js
Expand Up @@ -103,6 +103,9 @@ describe('htmlmin', function () {
'u'
]
list.forEach(function (el) {
assert.equal(htmlmin('<h2>foo <' + el + '>baz</' + el + '> bar</h2>', {
collapseWhitespace: true
}), '<h2>foo <' + el + '>baz</' + el + '> bar</h2>')
assert.equal(htmlmin('<p>foo <' + el + '>baz</' + el + '> bar</p>', {
collapseWhitespace: true
}), '<p>foo <' + el + '>baz</' + el + '> bar</p>')
Expand Down

0 comments on commit c43001c

Please sign in to comment.