diff --git a/lib/string.js b/lib/string.js index 6e957b8..22c68d7 100644 --- a/lib/string.js +++ b/lib/string.js @@ -396,9 +396,7 @@ exports.hyphenate = function hyphenate(str) { * @api draft */ -exports.slugify = function slugify(str) { - return exports.isString(str) ? exports.dashcase(str) : ''; -}; +exports.slugify = require('helper-slugify'); /** * Reverse the characters in a string. diff --git a/lib/utils/index.js b/lib/utils/index.js index 582a729..60a0481 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -25,6 +25,7 @@ require('make-iterator'); require('object.omit', 'omit'); require('relative'); require('right-align', 'alignRight'); +require('strip-color'); require('titlecase'); require('to-gfm-code-block', 'block'); require('word-wrap', 'wrap'); @@ -51,6 +52,18 @@ utils.isEmpty = function(val) { } }; +/** + * Get the "title" from a markdown link + */ + +utils.getTitle = function(str) { +if (/^\[[^\]]+\]\(/.test(str)) { + var m = /^\[([^\]]+)\]/.exec(str); + if (m) return m[1]; + } + return str; +}; + /** * Returns true if the given `val` is an object. * diff --git a/package.json b/package.json index 9e04e14..1f1ca9a 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "export-files": "^2.1.1", "fs-exists-sync": "^0.1.0", "get-value": "^2.0.6", + "helper-slugify": "^0.2.0", "is-absolute": "^0.2.5", "is-number": "^2.1.0", "is-plain-object": "^2.0.1", @@ -39,6 +40,7 @@ "object.omit": "^2.0.0", "relative": "^3.0.2", "right-align": "^0.1.3", + "strip-color": "^0.1.0", "titlecase": "^1.1.2", "to-gfm-code-block": "^0.1.1", "word-wrap": "^1.1.0" @@ -54,7 +56,7 @@ "markdown-link": "^0.1.1", "mocha": "^2.5.3", "through2": "^2.0.1", - "verb-generate-readme": "^0.1.21" + "verb-generate-readme": "^0.1.26" }, "keywords": [ "compile", @@ -83,9 +85,8 @@ "slugify", "templates", "verb", - "verb-readme-generator", - "word-wrap", - "verb-generate-readme" + "verb-generate-readme", + "word-wrap" ], "related": { "list": [ @@ -105,4 +106,4 @@ "reflinks": true } } -} \ No newline at end of file +} diff --git a/test/string.js b/test/string.js index 3d24cb7..a20302f 100644 --- a/test/string.js +++ b/test/string.js @@ -271,17 +271,19 @@ describe('string helpers', function() { it('should return an empty string when undefined.', function() { assert.equal(template('<%= slugify() %>', imports)(), ''); }); + it('should slugify the characters in a string.', function() { assert.equal(template('<%= slugify("foo bar baz") %>', imports)(), 'foo-bar-baz'); }); + it('should work with hyphens.', function() { assert.equal(template('<%= slugify("foo-bar-baz") %>', imports)(), 'foo-bar-baz'); - assert.equal(template('<%= slugify("-foo bar baz-") %>', imports)(), 'foo-bar-baz'); + assert.equal(template('<%= slugify("-foo bar baz-") %>', imports)(), '-foo-bar-baz-'); }); it('should work with other non-word characters.', function() { - assert.equal(template('<%= slugify("9foo-bar_baz") %>', imports)(), '9foo-bar-baz'); - assert.equal(template('<%= slugify("_foo_bar_baz-") %>', imports)(), 'foo-bar-baz'); + assert.equal(template('<%= slugify("9foo-bar_baz") %>', imports)(), '9foo-bar_baz'); + assert.equal(template('<%= slugify("_foo_bar_baz-") %>', imports)(), '_foo_bar_baz-'); }); });