def _reconstruct_spans(orig_span: dict, links: List[Link]) -> List[Span]:
    """
    Reconstructs the spans by breaking them up into smaller spans based on the links.
    """
    spans: List[Span] = []
    span: Span = None
    link_bboxes = [Bbox(link['bbox']) for link in links]

    for char in orig_span['chars']:
        char_bbox = Bbox(char['bbox'].bbox)
        intersections: List[Tuple[float, Link]] = []
        for i, link_bbox in enumerate(link_bboxes):
            if char_bbox.area > 0:
                area = link_bbox.intersection_area(char_bbox)
            else:
                area = link_bbox.intersection_area(Bbox(char['bbox'].bbox, ensure_nonzero_area=True))
            if area > 0:
                intersections.append((area, links[i]))

        current_url = ''
        if intersections:
            intersections.sort(key=lambda x: x[0], reverse=True)
            current_url = intersections[0][1]['url']

        if not span or current_url != span['url']:
            span = {
                "bbox": char_bbox,
                "text": char["char"],
                "rotation": char["rotation"],
                "font": char["font"],
                "char_start_idx": char["char_idx"],
                "char_end_idx": char["char_idx"],
                "chars": [char],
                "url": current_url,
            }
            spans.append(span)
        else:
            span['text'] += char['char']
            span['char_end_idx'] = char['char_idx']
            span['bbox'] = span['bbox'].merge(char_bbox)
            span['chars'].append(char)

    return spans

    Reconstructs the spans by breaking them up into smaller spans based on the links.
    
pdftext/pdf/links.py