diff --git a/lib/insert.js b/lib/insert.js index 67f76ed..9b4382e 100644 --- a/lib/insert.js +++ b/lib/insert.js @@ -28,7 +28,7 @@ module.exports = function insert(str, options) { if (m) newlines = m[0]; // does the file have front-matter? - if (/^---/.test(str)) { + if (/^---\n.*\n---\n/.test(str)) { // extract it temporarily so the syntax // doesn't get mistaken for a heading obj = utils.matter(str); diff --git a/package.json b/package.json index 25d988d..90a06c4 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "David Mohl (https://dvcrn.github.io)", "Federico Soave (https://github.com/Feder1co5oave)", "Gary Green (https://github.com/garygreen)", + "Gregory Danielson III (https://gregdan3.dev)", "Jon Schlinkert (http://twitter.com/jonschlinkert)", "Josh Duff (https://tehshrike.github.io)", "Matt Ellis (http://sticklebackplastic.com)", diff --git a/test/test.js b/test/test.js index e93e41b..055e804 100644 --- a/test/test.js +++ b/test/test.js @@ -426,4 +426,9 @@ describe('toc.insert', function() { assert.equal(strip(toc.insert(str, { linkify: true })), read('test/expected/insert.md')); assert.equal(strip(toc.insert(str, { linkify: false })), read('test/expected/insert-no-links.md')); }); + + it('should not mangle a file with an initial horizontal rule', function() { + assert.equal(toc.insert('---\nExample\n'), '---\nExample\n'); + }) + });