diff --git a/lib/rules/no-heading-content-indent.js b/lib/rules/no-heading-content-indent.js index f2845cc1..684346a5 100644 --- a/lib/rules/no-heading-content-indent.js +++ b/lib/rules/no-heading-content-indent.js @@ -65,6 +65,7 @@ function noHeadingContentIndent(ast, file, preferred, done) { var diff; var word; var index; + var char; if (position.generated(node)) { return; @@ -73,9 +74,16 @@ function noHeadingContentIndent(ast, file, preferred, done) { if (type === 'atx' || type === 'atx-closed') { initial = start(node); index = initial.offset; + char = contents.charAt(index); - while (contents.charAt(index) !== '#') { + while (char && char !== '#') { index++; + char = contents.charAt(index); + } + + /* CR/LF bug: wooorm/remark#195. */ + if (!char) { + return; } index = depth + (index - initial.offset); diff --git a/test/fixtures/carriage-returns.md b/test/fixtures/carriage-returns.md new file mode 100644 index 00000000..3209051c --- /dev/null +++ b/test/fixtures/carriage-returns.md @@ -0,0 +1,6 @@ +--- +title: "Example # " +--- +# Establishing an example # + +Description. diff --git a/test/index.js b/test/index.js index dd3b42a5..44c79166 100644 --- a/test/index.js +++ b/test/index.js @@ -219,6 +219,12 @@ describe('remark-lint', function () { 'maximum-line-length-valid.md:22:40: Line must be at most 20 characters' ]); }); + + it('should work with carriage returns', function () { + dequal(process('carriage-returns.md').map(String), [ + 'carriage-returns.md:5:1-5:28: Missing blank line before block node' + ]); + }); }); /*