code: def merge_spans(blocks):
      merged_blocks = []
      for page in blocks:
          page_blocks = []
          for blocknum, block in enumerate(page.blocks):
              block_lines = []
              block_types = []
              for linenum, line in enumerate(block.lines):
                  line_text = ""
                  if len(line.spans) == 0:
                      continue
                  fonts = []
                  for i, span in enumerate(line.spans):
                      font = span.font.lower()
                      next_font = None
                      next_idx = 1
                      while len(line.spans) > i + next_idx:
                          next_span = line.spans[i + next_idx]
                          next_font = next_span.font.lower()
                          next_idx += 1
                          if len(next_span.text.strip()) > 2:
                              break
  
                      fonts.append(font)
                      block_types.append(span.block_type)
                      span_text = span.text
  
                      # Don't bold or italicize very short sequences
                      # Avoid bolding first and last sequence so lines can be joined properly
                      if (
                          len(span_text) > 3
                          and 0 < i < len(line.spans) - 1
                      ):
                          if "ital" in font and (
                              not next_font or "ital" not in next_font
                          ):
                              span_text = surround_text(span_text, "*")
                          elif "bold" in font and (
                              not next_font or "bold" not in next_font
                          ):
                              span_text = surround_text(span_text, "**")
                      line_text += span_text
                  block_lines.append(
                      MergedLine(
                          text=line_text, fonts=fonts, bbox=line.bbox
                      )
                  )
              if len(block_lines) > 0:
                  page_blocks.append(
                      MergedBlock(
                          lines=block_lines,
                          pnum=block.pnum,
                          bbox=block.bbox,
                          block_types=block_types,
                      )
                  )
          merged_blocks.append(page_blocks)
  
      return merged_blocks
  
file_path: pdf-to-markdown/marker/markdown.py
imports: from marker.schema import MergedLine, MergedBlock, FullyMergedBlock, Page
  import re
  from typing import List
label_desc: Use image node_id 2 for calling a global function with example usage: merge_spans(blocks) and returns: merged_blocks