<commit_before>import elToStr from './utils/elementToString';
import Book from './Book';
import Page from './Page';

const SHOULD_DEBUG_TEXT = false;

const last = arr => arr[arr.length - 1];

// TODO: only do this if not double sided?
const clonePath = (origPath) => {
  const newPath = [];
  for (let i = origPath.length - 1; i >= 0; i -= 1) {
    const original = origPath[i];
    const clone = original.cloneNode(false); // shallow
    clone.innerHTML = '';
    clone.classList.add('bindery-continuation');
    if (clone.id) {
      // console.warn(`Bindery: Added a break to ${elToStr(clone)},
      // so "${clone.id}" is no longer a unique ID.`);
    }
    if (i < origPath.length - 1) clone.appendChild(newPath[i + 1]);
    newPath[i] = clone;
  }
  return newPath;
};

const reorderPages = (pages, makeNewPage) => {
  const orderedPages = pages;

  // TODO: this ignores the cover page, assuming its on the right
  for (let i = 1; i < orderedPages.length - 1; i += 2) {<commit_msg>Continue numbering when splitting <ol><commit_after>import elToStr from './utils/elementToString';
import Book from './Book';
import Page from './Page';

const SHOULD_DEBUG_TEXT = false;

const last = arr => arr[arr.length - 1];

// TODO: only do this if not double sided?
const clonePath = (origPath) => {
  const newPath = [];
  for (let i = origPath.length - 1; i >= 0; i -= 1) {
    const original = origPath[i];
    const clone = original.cloneNode(false); // shallow
    clone.innerHTML = '';
    clone.classList.add('bindery-continuation');
    if (clone.id) {
      // console.warn(`Bindery: Added a break to ${elToStr(clone)},
      // so "${clone.id}" is no longer a unique ID.`);
    }
    if (clone.tagName === 'OL') {
      // restart numbering
      let prevStart = 1;
      if (original.hasAttribute('start')) {
        prevStart = parseInt(original.getAttribute('start'), 10);
      }
      const prevCount = original.children.length;
      const newStart = prevStart + prevCount;
      clone.setAttribute('start', newStart);
    }
    if (i < origPath.length - 1) clone.appendChild(newPath[i + 1]);
    newPath[i] = clone;
  }
  return newPath;
};

const reorderPages = (pages, makeNewPage) => {
  const orderedPages = pages;

  // TODO: this ignores the cover page, assuming its on the right
  for (let i = 1; i < orderedPages.length - 1; i += 2) {
{'fraction_non_alphanumeric': 0.149830220713073, 'fraction_numerical': 0.008913412563667233, 'mean_word_length': 3.008503401360544, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5675338', 'n_tokens_mistral': 770, 'n_tokens_neox': 748, 'n_words': 234}