Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes ordered list ")" delimiter #1704

Merged
merged 12 commits into from Jun 17, 2020
2 changes: 1 addition & 1 deletion src/Tokenizer.js
Expand Up @@ -225,7 +225,7 @@ module.exports = class Tokenizer {
// Remove the list item's bullet
// so it is seen as the next token.
space = item.length;
item = item.replace(/^ *([*+-]|\d+\.) */, '');
item = item.replace(/^ *([*+-]|\d+(?:\.|\))) */, '');
jun-sheaf marked this conversation as resolved.
Show resolved Hide resolved

// Outdent whatever the
// list item contains. Hacky.
Expand Down
2 changes: 1 addition & 1 deletion src/rules.js
Expand Up @@ -42,7 +42,7 @@ block.def = edit(block.def)
.replace('title', block._title)
.getRegex();

block.bullet = /(?:[*+-]|\d{1,9}\.)/;
block.bullet = /(?:[*+-]|\d{1,9}(?:\.|\)))/;
jun-sheaf marked this conversation as resolved.
Show resolved Hide resolved
block.item = /^( *)(bull) ?[^\n]*(?:\n(?!\1bull ?)[^\n]*)*/;
block.item = edit(block.item, 'gm')
.replace(/bull/g, block.bullet)
Expand Down
14 changes: 11 additions & 3 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,19 +345,27 @@ a | b
md: `
1. item 1
2. item 2
3) item 3
4) item 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unit test actually goes against the spec example 272. marked should start a new list if the bullet or ordered list delimiter is changed.

I'm ok with not fixing that spec example in this PR but can you create an integration test instead of changing the unit test. You can create a new .md file and .html file in /test/specs/new/

something like:

list_paren_delimiter.md

1) one
2) two
3) three


2) two
3) three
4) four

list_paren_delimiter.html

<ol>
<li>one</li>
<li>two</li>
<li>three</li>
</ol>

<ol start="2">
<li>two</li>
<li>three</li>
<li>four</li>
</ol>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made changes to accommodate ex.272. I am not too sure what the shouldFail keyword means in the CM tests, but some of them had to be removed. In any case, the fixes work well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the shouldFail is there so we can track which spec tests are passing and which are failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So shouldFail means shouldNotFailButDoesFail?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly 😁👍

`,
tokens: jasmine.arrayContaining([
jasmine.objectContaining({
type: 'list',
raw: '1. item 1\n2. item 2\n',
raw: '1. item 1\n2. item 2\n3) item 3\n4) item 4\n',
ordered: true,
start: 1,
items: [
jasmine.objectContaining({
raw: '1. item 1'
}),
jasmine.objectContaining({
raw: '2. item 2\n'
raw: '2. item 2'
}),
jasmine.objectContaining({
raw: '3) item 3'
}),
jasmine.objectContaining({
raw: '4) item 4\n'
})
]
})
Expand Down