Skip to content

Commit

Permalink
Fix parse error with consecutive formats
Browse files Browse the repository at this point in the history
  • Loading branch information
bterlson authored and domenic committed Aug 10, 2015
1 parent 3a844ba commit 42cb4c3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test/list-cases/code.ecmarkdown
Original file line number Diff line number Diff line change
Expand Up @@ -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`?`.
1 change: 1 addition & 0 deletions test/list-cases/code.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<li>The <code>stream.state</code> should be <code>"readable"</code>.</li>
<li><code>"strings"</code> are often in code, sometimes at the beginning.</li>
<li><code>Code can contain spaces</code>.</li>
<li>Code can have formats in them, like so: <code>||</code>, <code>**</code>, <code>__</code>, and <code>~~</code>.</li>
<li>Leftover backticks <code>code</code>cannot` get left there.</li>
<li>If they're balanced though, it works: <code>perhaps</code>unanticipated<code>?</code>.</li>
</ol>

0 comments on commit 42cb4c3

Please sign in to comment.