Comparing version 1.6.4 to 1.7.0
@@ -145,11 +145,21 @@ var Mehdown; | ||
Mehdown.header = function(suffix) { | ||
function toSlug(value) { | ||
return value | ||
.toLowerCase() | ||
.replace(/[^\w ]+/g, '') | ||
.replace(/ +/g, '-') | ||
.replace(/^-*/, '') | ||
.replace(/-*$/, ''); | ||
} | ||
return function(header) { | ||
var text = header.replace(/<h\d[^>]*>([^<]+)<\/h\d>/, '$1'); | ||
text = text.replace(/\s+/g, '-'); | ||
text = toSlug(text); | ||
if (suffix) { | ||
suffix = toSlug(suffix); | ||
text = text + '-' + suffix; | ||
} | ||
return header.replace(/<h\d/, '$& id="' + text.toLowerCase() + '"'); | ||
return header.replace(/<h\d/, '$& id="' + text + '"'); | ||
}; | ||
@@ -156,0 +166,0 @@ }; |
@@ -13,3 +13,3 @@ { | ||
}, | ||
"version": "1.6.4" | ||
"version": "1.7.0" | ||
} |
@@ -71,2 +71,22 @@ var assert = require('assert'); | ||
}); | ||
it('handle header text with non alpha-numeric characters', function() { | ||
var text = mehdown.parse('<h1>What.is!meh?</h1>', { suffix: '0.1!2?f..e!!d??' }); | ||
assert.equal(text, '<h1 id="whatismeh-012fed">What.is!meh?</h1>'); | ||
}); | ||
it('handle header text with multiple spaces', function() { | ||
var text = mehdown.parse('<h1>What. is ! meh ?</h1>', { suffix: '0. 1! 2?f. . e! !d? ?' }); | ||
assert.equal(text, '<h1 id="what-is-meh-0-1-2f-e-d">What. is ! meh ?</h1>'); | ||
}); | ||
it('hanlde suffix with non alpha-numeric characters', function() { | ||
var text = mehdown.parse('<h1>a- -b?c</h1>', { suffix: '!@#$%^&*()=+`~,./;\'<>?:"[]{}|' }); | ||
assert.equal(text, '<h1 id="a-bc-">a- -b?c</h1>'); | ||
}); | ||
it('collapse multiple hyphens', function() { | ||
var text = mehdown.parse('<h1>-- - What - - is --- - - meh - - -</h1>', { suffix: '!@#$%^&*()=+`~,./;\'<>?:"[]{}|' }); | ||
assert.equal(text, '<h1 id="what-is-meh-">-- - What - - is --- - - meh - - -</h1>'); | ||
}); | ||
}); | ||
@@ -73,0 +93,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36718
8
376