def process_wikitext(
    text,
    keep_tables = True,
    truncate = False,
):
  """Processes Wikitext to human readable text."""
  if text is None:
    return ""
  if RE_DISAMBIGUATION.search(text):
    return "DISAMBIGUATION"
  # Replace non-breaking spaces
  text = text.replace("&nbsp;", " ")
  # Remove tables
  if not keep_tables:
    text = RE_TABLE.sub("", text)
  # Remove templates
  n = 1
  while n:
    text, n = RE_TEMPLATE.subn("", text)
  # Remove comments
  n = 1
  while n:
    text, n = RE_COMMENT.subn("", text)
  # Remove references
  text = RE_REF.sub("", text)
  # Remove other HTML tags
  text = RE_HTML.sub("", text)
  # Remove elements from the text, e.g., files and images, that may get confused
  # with annotated mentions.
  text = remove_element(text, "File")
  text = remove_element(text, "file")
  text = remove_element(text, "Image")
  text = remove_element(text, "image")
  text = remove_element(text, "Category")
  text = remove_element(text, "category")
  # Remove bolding
  text = text.replace("'''", "")
  # Strip text
  text = text.strip()
  # If truncating return everything before first heading.
  if truncate:
    text = text.split("==")[0]
  return text
Processes Wikitext to human readable text.
language/fruit/wiki_utils.py