').append($children);
$parent.replaceWith($ul);
});
- value = $value.html();
+ value = this.convertLists($value.html());
return value;
+ },
+
+ // hack
+ // https://github.com/quilljs/quill/issues/979
+ convertLists(richtext) {
+ const tempEl = window.document.createElement('div');
+ tempEl.setAttribute('style', 'display: none;');
+ tempEl.innerHTML = richtext;
+ const startLi = '::startli::';
+ const endLi = '::endli::';
+
+ ['ul','ol'].forEach((type) => {
+ const startTag = `::start${type}::`;
+ const endTag = `::end${type}::`;
+
+ // Grab each list, and work on it in turn
+ Array.from(tempEl.querySelectorAll(type)).forEach((outerListEl) => {
+ const listChildren = Array.from(outerListEl.children).filter((el) => el.tagName === 'LI');
+
+ let lastLiLevel = 0;
+ let currentLiLevel = 0;
+ let difference = 0;
+
+ // Now work through each li in this list
+ for (let i = 0; i < listChildren.length; i++) {
+ const currentLi = listChildren[i];
+ lastLiLevel = currentLiLevel;
+ currentLiLevel = this.getListLevel(currentLi);
+ difference = currentLiLevel - lastLiLevel;
+
+ // we only need to add tags if the level is changing
+ if (difference > 0) {
+ currentLi.before((startLi + startTag).repeat(difference));
+ } else if (difference < 0) {
+ currentLi.before((endTag + endLi).repeat(-difference));
+ }
+
+ if (i === listChildren.length - 1) {
+ // last li, account for the fact that it might not be at level 0
+ currentLi.after((endTag + endLi).repeat(currentLiLevel));
+ }
+ }
+ });
+ });
+
+ // Get the content in the element and replace the temporary tags with new ones
+ let newContent = tempEl.innerHTML;
+
+ newContent = newContent.replace(/::startul::/g, '