Skip to content

Commit

Permalink
add new line to list item raw
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech committed Feb 22, 2021
1 parent e40d5c4 commit 8612a5d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,18 @@ module.exports = class Tokenizer {
}

// trim item newlines at end
item = rtrim(item, '\n');
if (i === l - 1) {
item = rtrim(item, '\n');
} else {
raw = raw + '\n';
}

// Determine whether item is loose or not.
// Use: /(^|\n)(?! )[^\n]+\n\n(?!\s*$)/
// for discount behavior.
loose = next || /\n\n(?!\s*$)/.test(raw);
if (i !== l - 1) {
next = raw.charAt(raw.length - 1) === '\n';
next = raw.slice(-2) === '\n\n';
if (!loose) loose = next;
}

Expand Down
22 changes: 15 additions & 7 deletions test/unit/Lexer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ a | b
items: [
{
type: 'list_item',
raw: '- item 1',
raw: '- item 1\n',
task: false,
checked: undefined,
loose: false,
Expand Down Expand Up @@ -354,7 +354,7 @@ a | b
start: 1,
items: [
jasmine.objectContaining({
raw: '1. item 1'
raw: '1. item 1\n'
}),
jasmine.objectContaining({
raw: '2. item 2\n'
Expand All @@ -379,7 +379,7 @@ a | b
start: 1,
items: [
jasmine.objectContaining({
raw: '1) item 1'
raw: '1) item 1\n'
}),
jasmine.objectContaining({
raw: '2) item 2\n'
Expand Down Expand Up @@ -408,7 +408,7 @@ paragraph
items: [
{
type: 'list_item',
raw: '- item 1',
raw: '- item 1\n',
task: false,
checked: undefined,
loose: false,
Expand Down Expand Up @@ -464,7 +464,7 @@ paragraph
start: 2,
items: [
jasmine.objectContaining({
raw: '2. item 1'
raw: '2. item 1\n'
}),
jasmine.objectContaining({
raw: '3. item 2\n'
Expand All @@ -486,7 +486,15 @@ paragraph
jasmine.objectContaining({
type: 'list',
raw: '- item 1\n\n- item 2\n',
loose: true
loose: true,
items: [
jasmine.objectContaining({
raw: '- item 1\n\n'
}),
jasmine.objectContaining({
raw: '- item 2\n'
})
]
})
])
});
Expand All @@ -504,7 +512,7 @@ paragraph
raw: '- [ ] item 1\n- [x] item 2\n',
items: [
jasmine.objectContaining({
raw: '- [ ] item 1',
raw: '- [ ] item 1\n',
task: true,
checked: false
}),
Expand Down

0 comments on commit 8612a5d

Please sign in to comment.