Skip to content

Commit

Permalink
fix yihui/litedown#25: should keep fragmenting the element when the c…
Browse files Browse the repository at this point in the history
…lone is empty but not the only element on the page
  • Loading branch information
yihui committed Sep 11, 2024
1 parent b942982 commit ad271a6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions js/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@
if (el.tagName === 'DIV' && nChild(el) === 1) {
fragment(el.firstElementChild, el2, el, box_cur);
}
const prev = el2.previousElementSibling;
// keep moving el's first item to el2 until page height > H
if (['UL', 'BLOCKQUOTE'].indexOf(el.tagName) > -1 && nChild(el) > 1) while (true) {
const item = el.firstChild;
if (!item) break;
el2.append(item);
if (box_cur.scrollHeight > H) {
// move item back to el if the clone el2 is not the only element on page or has more than one child
(el2.previousElementSibling || nChild(el2) > 1) && el.insertBefore(item, el.firstChild);
(prev || nChild(el2) > 1) && el.insertBefore(item, el.firstChild);
break;
}
}
// if the clone is empty, remove it, otherwise keep fragmenting the remaining el
removeBlank(el2) || fragment(container ? parent : el);
if (!removeBlank(el2) || prev) fragment(container ? parent : el);
}

// use data-short-title of a header if exists, and fall back to inner text
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xiee/utils",
"version": "1.13.31",
"version": "1.13.32",
"description": "Miscellaneous tools and utilities to manipulate HTML pages",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down

0 comments on commit ad271a6

Please sign in to comment.