From 42cb4c351953896fa337daf505447f066d9dc14c Mon Sep 17 00:00:00 2001 From: Brian Terlson Date: Sat, 8 Aug 2015 16:08:32 -0700 Subject: [PATCH] Fix parse error with consecutive formats --- lib/parser.js | 13 +++++++++---- test/list-cases/code.ecmarkdown | 1 + test/list-cases/code.html | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/parser.js b/lib/parser.js index d6466bb..730eb63 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -121,14 +121,19 @@ module.exports = class Parser { } else if (tok.name === 'text' || tok.name === 'whitespace' || tok.name === 'linebreak') { seg.push(this.parseText(inList, fmtStack)); } else if (isFormatToken(tok)) { - if (fmtStack.indexOf(tok.name) === -1) { - const node = this.parseFormat(tok.name, inList, fmtStack); - seg = seg.concat(node); - } else { + if (fmtStack.indexOf(tok.name) > -1) { // only one format // this format token closes a format on the stack so ends this fragment // parseText handles checking for whether the close format was contextually // valid break; + } else if (fmtStack.length === 0) { + // valid format + const node = this.parseFormat(tok.name, inList, fmtStack); + seg = seg.concat(node); + } else { + // invalid format + pushOrJoin(seg, { name: 'text', contents: tok.contents }); + this._t.next(); } } else if (tok.name === 'comment' || tok.name === 'tag') { seg.push(tok); diff --git a/test/list-cases/code.ecmarkdown b/test/list-cases/code.ecmarkdown index 6d74fe0..1badbb2 100644 --- a/test/list-cases/code.ecmarkdown +++ b/test/list-cases/code.ecmarkdown @@ -3,5 +3,6 @@ 1. The `stream.state` should be `"readable"`. 1. `"strings"` are often in code, sometimes at the beginning. 1. `Code can contain spaces`. +1. Code can have formats in them, like so: `||`, `**`, `__`, and `~~`. 1. Leftover backticks `code`cannot` get left there. 1. If they're balanced though, it works: `perhaps`unanticipated`?`. diff --git a/test/list-cases/code.html b/test/list-cases/code.html index f8015f9..5762d8a 100644 --- a/test/list-cases/code.html +++ b/test/list-cases/code.html @@ -4,6 +4,7 @@
  • The stream.state should be "readable".
  • "strings" are often in code, sometimes at the beginning.
  • Code can contain spaces.
  • +
  • Code can have formats in them, like so: ||, **, __, and ~~.
  • Leftover backticks codecannot` get left there.
  • If they're balanced though, it works: perhapsunanticipated?.