fix: loose list items are loose (#2672)
This commit is contained in:
parent
bd9a11484a
commit
df4eb0e090
@ -315,25 +315,19 @@ export class Tokenizer {
|
||||
for (i = 0; i < l; i++) {
|
||||
this.lexer.state.top = false;
|
||||
list.items[i].tokens = this.lexer.blockTokens(list.items[i].text, []);
|
||||
const spacers = list.items[i].tokens.filter(t => t.type === 'space');
|
||||
const hasMultipleLineBreaks = spacers.every(t => {
|
||||
const chars = t.raw.split('');
|
||||
let lineBreaks = 0;
|
||||
for (const char of chars) {
|
||||
if (char === '\n') {
|
||||
lineBreaks += 1;
|
||||
}
|
||||
if (lineBreaks > 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
if (!list.loose) {
|
||||
// Check if list should be loose
|
||||
const spacers = list.items[i].tokens.filter(t => t.type === 'space');
|
||||
const hasMultipleLineBreaks = spacers.length > 0 && spacers.some(t => /\n.*\n/.test(t.raw));
|
||||
|
||||
if (!list.loose && spacers.length && hasMultipleLineBreaks) {
|
||||
// Having a single line break doesn't mean a list is loose. A single line break is terminating the last list item
|
||||
list.loose = true;
|
||||
list.loose = hasMultipleLineBreaks;
|
||||
}
|
||||
}
|
||||
|
||||
// Set all items to loose if list is loose
|
||||
if (list.loose) {
|
||||
for (i = 0; i < l; i++) {
|
||||
list.items[i].loose = true;
|
||||
}
|
||||
}
|
||||
|
9
test/specs/new/list_loose.html
Normal file
9
test/specs/new/list_loose.html
Normal file
@ -0,0 +1,9 @@
|
||||
<ul>
|
||||
<li>
|
||||
<p>item 1</p>
|
||||
</li>
|
||||
<li>
|
||||
<p>item 2</p>
|
||||
<p>still item 2</p>
|
||||
</li>
|
||||
</ul>
|
5
test/specs/new/list_loose.md
Normal file
5
test/specs/new/list_loose.md
Normal file
@ -0,0 +1,5 @@
|
||||
- item 1
|
||||
-
|
||||
item 2
|
||||
|
||||
still item 2
|
@ -605,10 +605,49 @@ paragraph
|
||||
loose: true,
|
||||
items: [
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 1\n\n'
|
||||
raw: '- item 1\n\n',
|
||||
loose: true
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 2'
|
||||
raw: '- item 2',
|
||||
loose: true
|
||||
})
|
||||
]
|
||||
})
|
||||
])
|
||||
});
|
||||
});
|
||||
|
||||
it('end loose', () => {
|
||||
expectTokens({
|
||||
md: `
|
||||
- item 1
|
||||
- item 2
|
||||
|
||||
item 2a
|
||||
- item 3
|
||||
`,
|
||||
tokens: jasmine.arrayContaining([
|
||||
jasmine.objectContaining({
|
||||
type: 'space',
|
||||
raw: '\n'
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
type: 'list',
|
||||
raw: '- item 1\n- item 2\n\n item 2a\n- item 3\n',
|
||||
loose: true,
|
||||
items: [
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 1\n',
|
||||
loose: true
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 2\n\n item 2a\n',
|
||||
loose: true
|
||||
}),
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 3',
|
||||
loose: true
|
||||
})
|
||||
]
|
||||
})
|
||||
@ -634,6 +673,7 @@ paragraph
|
||||
items: [
|
||||
jasmine.objectContaining({
|
||||
raw: '- item 1\n - item 2',
|
||||
loose: false,
|
||||
tokens: jasmine.arrayContaining([
|
||||
jasmine.objectContaining({
|
||||
raw: 'item 1\n'
|
||||
|
Loading…
x
Reference in New Issue
Block a user