arve0 / markdown-it-header-sections

similar to pandoc's --section-divs for markdown-it
19 stars 15 forks source link

markdown-it-header-sections causes infinite loop in parsing incorrect order of headers #3

Closed co3k closed 9 years ago

co3k commented 9 years ago

try the following test case by executing npm test then you will see the FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory.

diff --git a/test.js b/test.js
index 11940ee..db746ed 100644
--- a/test.js
+++ b/test.js
@@ -103,5 +103,27 @@ describe('markdown-it-header-sections', function(){
     var res = md.render(src);
     assert.equal(expected, res);
   });
+  it('should parse incorrect order of headers', function(){
+    var src = multiline.stripIndent(function(){/*
+      #### Header 4
+      Text.
+      ### Header 3
+      Hello!
+    */});
+    var expected = multiline.stripIndent(function(){/*
+      <section>
+      <h4>Header 4</h4>
+      <p>Text.</p>
+      <section>
+      <h3>Header 3</h3>
+      <p>Hello!</p>
+      </section>
+      </section>
+
+    */});
+    md.use(headerSections);
+    var res = md.render(src);
+    assert.equal(expected, res);
+  });

 });