def remake_page(index, page_groups, context, root_box, html):
    """Return one laid out page without margin boxes.

    Start with the initial values from ``context.page_maker[index]``.
    The resulting values / initial values for the next page are stored in
    the ``page_maker``.

    As the function's name suggests: the plan is not to make all pages
    repeatedly when a missing counter was resolved, but rather re-make the
    single page where the ``content_changed`` happened.

    """
    page_maker = context.page_maker
    resume_at, next_page, right_page, page_state, _ = page_maker[index]

    # PageType for current page, values for page_maker[index + 1].
    # Don't modify actual page_maker[index] values!
    page_state = copy.deepcopy(page_state)
    if next_page['break'] in ('left', 'right'):
        next_page_side = next_page['break']
    elif next_page['break'] in ('recto', 'verso'):
        direction_ltr = root_box.style['direction'] == 'ltr'
        break_verso = next_page['break'] == 'verso'
        next_page_side = 'right' if direction_ltr ^ break_verso else 'left'
    else:
        next_page_side = None
    blank = bool(
        (next_page_side == 'left' and right_page) or
        (next_page_side == 'right' and not right_page) or
        (context.reported_footnotes and resume_at is None))
    name = '' if blank else next_page['page']
    side = 'right' if right_page else 'left'
    _update_page_groups(page_groups, resume_at, next_page, root_box)
    groups = tuple((name, index) for name, index, _ in page_groups)
    page_type = PageType(side, blank, name, index, groups)
    set_page_type_computed_styles(page_type, html, context.style_for)

    context.forced_break = (next_page['break'] != 'any' or next_page['page'])
    context.margin_clearance = False

    # make_page wants a page_number of index + 1
    page_number = index + 1
    page, resume_at, next_page = make_page(
        context, root_box, page_type, resume_at, page_number, page_state)
    assert next_page
    right_page = not right_page

    # Check whether we need to append or update the next page_maker item
    if index + 1 >= len(page_maker):
        # New page
        page_maker_next_changed = True
    else:
        # Check whether something changed
        next_resume_at, next_next_page, next_right_page, next_page_state, _ = (
            page_maker[index + 1])
        page_maker_next_changed = (
            next_resume_at != resume_at or
            next_next_page != next_page or
            next_right_page != right_page or
            next_page_state != page_state)

    if page_maker_next_changed:
        # Reset remake_state
        remake_state = {
            'content_changed': False,
            'pages_wanted': False,
            'anchors': [],
            'content_lookups': [],
        }
        # Setting content_changed to True ensures remake.
        # If resume_at is None (last page) it must be False to prevent endless
        # loops and list index out of range (see #794).
        remake_state['content_changed'] = resume_at is not None
        item = resume_at, next_page, right_page, page_state, remake_state
        if index + 1 >= len(page_maker):
            page_maker.append(item)
        else:
            page_maker[index + 1] = item

    return page, resume_at
Return one laid out page without margin boxes.

Start with the initial values from ``context.page_maker[index]``.
The resulting values / initial values for the next page are stored in
the ``page_maker``.

As the function's name suggests: the plan is not to make all pages
repeatedly when a missing counter was resolved, but rather re-make the
single page where the ``content_changed`` happened.
weasyprint/layout/page.py