diff --git a/mds.js b/mds.js index 4e7b0e9..c91e0e9 100644 --- a/mds.js +++ b/mds.js @@ -153,6 +153,7 @@ export function write(s, chunk) { const last_last_txt_char = s.txt[s.txt.length-2] const last_last_src_char = s.src[s.idx-2] const last_txt_char = s.txt[s.txt.length-1] + const last_src_char = s.src[s.idx-1] const char = s.src[s.idx] const in_token = s.tokens_type[s.tokens_len] @@ -333,12 +334,11 @@ export function write(s, chunk) { add_paragraph(s) flush(s) } - s.tokens_len = Math.min(s.tokens_len, 1) continue } - if ('\n' === s.src[s.idx-1]) { - if ('\n' === s.src[s.idx-2]) { - end_token(s) + if ('\n' === last_src_char) { + if ('\n' === last_last_src_char) { + s.tokens_len = 0 } else { s.renderer.update_node(s.renderer.data, s.tokens_node[s.tokens_len], '\n') } diff --git a/readme.md b/readme.md index d08a919..9a7d0c9 100644 --- a/readme.md +++ b/readme.md @@ -55,7 +55,7 @@ mds.end(stream) - [x] Paragraphs - [x] Line breaks - - [ ] Line breaks don't end emphasis + - [x] Single line breaks don't end tokens - [x] Headers - [x] code block with triple backticks - [x] `inline code` with backticks diff --git a/test.js b/test.js index ba15c9f..cb5daa6 100644 --- a/test.js +++ b/test.js @@ -182,6 +182,27 @@ t.test("Line Breaks", () => { assert.equal(renderer.data.temp_text_node, null) }) +t.test("Line Breaks with Italic", () => { + const renderer = test_renderer() + const parser = mds.parser(renderer) + + mds.write(parser, "*" + content_1 + "\n" + content_2 + "*") + mds.end(parser) + + assert.deepEqual(renderer.data.root, { + type : mds.Token_Type.Root, + children: [{ + type : mds.Token_Type.Paragraph, + children: [{ + type : mds.Token_Type.Italic_Ast, + children: [content_1, "\n", content_2] + }], + }] + }) + assert.equal(renderer.data.temp_text, "") + assert.equal(renderer.data.temp_text_node, null) +}) + t.test("Paragraphs", () => { const renderer = test_renderer() const parser = mds.parser(renderer)