code: def surrounding_sourcepos(elems, start_index, end_index=None):
      """
      Find a sourcepos that ranges from the last line of elems[start_index - 1] to the first line
      of elems[end_index + 1], handling the boundary conditions.
      """
      if end_index is None:
          end_index = start_index
  
      # chosen start element ...
      if start_index == 0:
          # ... is first, so start at its first line
          start = elems[start_index].sourcepos[0]
      else:
          # ... isn't first, so start at the previous element's last line
          start = elems[start_index - 1].sourcepos[1]
  
      # chosen end element ...
      if end_index == len(elems) - 1:
          # ... is last, so end at its last line
          end = elems[end_index].sourcepos[1]
      else:
          # ... isn't last, so end at the next element's first line
          end = elems[end_index + 1].sourcepos[0]
  
      return [start, end]
  
imports: import argparse
  import commonmark
  import nbformat
  import os
  import re
  import subprocess
  import sys
  import textwrap
  from pathlib import Path
label_desc: Use image node_id 16 for calling a global function with example usage: surrounding_sourcepos(elems, start_index, end_index) and returns: list