def split_article(text):
  """Splits article into sections, with special logic for dealing with tables."""
  parents = []
  titles = ["INTRODUCTION"]
  contents = []
  prev_depth = 1
  start = 0
  for match in RE_TITLE.finditer(text):
    title = match.group("title").strip()
    depth = len(match.group("equals"))
    if prev_depth:
      pops = prev_depth - depth + 1
      if pops > 0:
        for _ in range(pops):
          try:
            parents.pop()
          except IndexError:
            continue
    parents.append(title)
    title = " - ".join(parents)
    titles.append(title)
    end = match.start()
    content = text[start:end]
    contents.append(content)
    start = match.end()
    prev_depth = depth
  if start:
    content = text[start:end]
    contents.append(content)
  for title, content in zip(titles, contents):
    content, tables = split_tables(content)
    yield title, content.strip(" \n\t")
    for i, table in enumerate(tables):
      for j, row in enumerate(process_table(table)):
        yield f"{title} - Table-{i}-{j}", row.strip(" \n\t")
Splits article into sections, with special logic for dealing with tables.
language/fruit/wiki_utils.py