Skip to content

Commit

Permalink
Fixed Example 272
Browse files Browse the repository at this point in the history
  • Loading branch information
jun-sheaf committed Jun 17, 2020
1 parent 463f49d commit fcfe15f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
5 changes: 3 additions & 2 deletions src/Tokenizer.js
Expand Up @@ -195,12 +195,13 @@ module.exports = class Tokenizer {
let raw = cap[0];
const bull = cap[2];
const isordered = bull.length > 1;
const isparen = bull[bull.length - 1] === ')';

const list = {
type: 'list',
raw,
ordered: isordered,
start: isordered ? +bull : '',
start: isordered ? +bull.slice(0, -1) : '',
loose: false,
items: []
};
Expand Down Expand Up @@ -240,7 +241,7 @@ module.exports = class Tokenizer {
// Backpedal if it does not belong in this list.
if (i !== l - 1) {
b = this.rules.block.bullet.exec(itemMatch[i + 1])[0];
if (bull.length > 1 ? b.length === 1
if (isordered ? b.length === 1 || (!isparen && b[b.length - 1] === ')')
: (b.length > 1 || (this.options.smartLists && b !== bull))) {
addBack = itemMatch.slice(i + 1).join('\n');
list.raw = list.raw.substring(0, list.raw.length - addBack.length);
Expand Down
6 changes: 2 additions & 4 deletions test/specs/commonmark/commonmark.0.29.json
Expand Up @@ -2146,8 +2146,7 @@
"example": 266,
"start_line": 4595,
"end_line": 4606,
"section": "List items",
"shouldFail": true
"section": "List items"
},
{
"markdown": "10) foo\n - bar\n",
Expand Down Expand Up @@ -2197,8 +2196,7 @@
"example": 272,
"start_line": 4909,
"end_line": 4921,
"section": "Lists",
"shouldFail": true
"section": "Lists"
},
{
"markdown": "Foo\n- bar\n- baz\n",
Expand Down
6 changes: 2 additions & 4 deletions test/specs/gfm/commonmark.0.29.json
Expand Up @@ -2146,8 +2146,7 @@
"example": 266,
"start_line": 4595,
"end_line": 4606,
"section": "List items",
"shouldFail": true
"section": "List items"
},
{
"markdown": "10) foo\n - bar\n",
Expand Down Expand Up @@ -2197,8 +2196,7 @@
"example": 272,
"start_line": 4909,
"end_line": 4921,
"section": "Lists",
"shouldFail": true
"section": "Lists"
},
{
"markdown": "Foo\n- bar\n- baz\n",
Expand Down
11 changes: 11 additions & 0 deletions test/specs/new/list_paren_delimiter.html
@@ -0,0 +1,11 @@
<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>

<ol start="2">
<li>two</li>
<li>three</li>
<li>four</li>
</ol>
8 changes: 8 additions & 0 deletions test/specs/new/list_paren_delimiter.md
@@ -0,0 +1,8 @@
1) one
2) two
3) three


2) two
3) three
4) four
33 changes: 25 additions & 8 deletions test/unit/Lexer-spec.js
Expand Up @@ -5,7 +5,7 @@ function expectTokens({ md, options, tokens = [], links = {} }) {
const actual = lexer.lex(md);
const expected = tokens;
expected.links = links;
console.log(JSON.stringify(actual, null, 2));
// console.log(JSON.stringify(actual, null, 2));
expect(actual).toEqual(expected);
}

Expand Down Expand Up @@ -345,27 +345,44 @@ a | b
md: `
1. item 1
2. item 2
3) item 3
4) item 4
`,
tokens: jasmine.arrayContaining([
jasmine.objectContaining({
type: 'list',
raw: '1. item 1\n2. item 2\n3) item 3\n4) item 4\n',
raw: '1. item 1\n2. item 2\n',
ordered: true,
start: 1,
items: [
jasmine.objectContaining({
raw: '1. item 1'
}),
jasmine.objectContaining({
raw: '2. item 2'
}),
raw: '2. item 2\n'
})
]
})
])
});
});

it('ordered with parenthesis', () => {
expectTokens({
md: `
1) item 1
2) item 2
`,
tokens: jasmine.arrayContaining([
jasmine.objectContaining({
type: 'list',
raw: '1) item 1\n2) item 2\n',
ordered: true,
start: 1,
items: [
jasmine.objectContaining({
raw: '3) item 3'
raw: '1) item 1'
}),
jasmine.objectContaining({
raw: '4) item 4\n'
raw: '2) item 2\n'
})
]
})
Expand Down

0 comments on commit fcfe15f

Please sign in to comment.