Skip to content

Commit

Permalink
Correctly convert mixed lists
Browse files Browse the repository at this point in the history
At the moment, it's possible to construct a "mixed" list of ordered and
bulleted items, eg:

```markdown
  1. One
  2. Two
  - Foo
  - Bar
```

If you create this list in Quill, then cut it and paste it back again,
the bullet items are transformed into ordered items, which is
surprising.

This change updates the list HTML conversion logic to check that the
list is still a continuation of the previous type. If not, it starts a
new list of the correct type.
  • Loading branch information
Alec Gibson committed Apr 15, 2019
1 parent 5e7eb7b commit f23a206
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ function convertListHTML(items, lastIndent, types) {
length,
)}${convertListHTML(rest, indent, types)}`;
}
if (indent === lastIndent) {
const previousType = types[types.length - 1];
if (indent === lastIndent && type === previousType) {
return `</li><li${attribute}>${convertHTML(
child,
offset,
Expand Down
24 changes: 24 additions & 0 deletions test/unit/core/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,30 @@ describe('Editor', function() {
);
});

it('mixed list', function() {
const editor = this.initialize(
Editor,
`
<ol>
<li data-list="ordered">One</li>
<li data-list="ordered">Two</li>
<li data-list="bullet">Foo</li>
<li data-list="bullet">Bar</li>
</ol>
`,
);
expect(editor.getHTML(2, 12)).toEqualHTML(`
<ol>
<li>e</li>
<li>Two</li>
</ol>
<ul>
<li>Foo</li>
<li>Ba</li>
</ul>
`);
});

it('nested list', function() {
const editor = this.initialize(
Editor,
Expand Down

0 comments on commit f23a206

Please sign in to comment.