code: def process_page_and_section_titles(markdown_text):
      updated_markdown = ""
      page_title = ""
      section_title = ""
      subsection_title = ""
      new_line = ""
      metadata = {}
      # Processes the frontmatter in a markdown file
      data = frontmatter.loads(markdown_text)
      if "title" in data:
          page_title = data["title"]
          markdown_text = data.content
          metadata = data.metadata
      if "URL" in data:
          final_url = data["URL"]
          metadata["URL"] = final_url
      for line in markdown_text.split("\n"):
          new_line = ""
          skip_this_line = False
          if line.startswith("#"):
              match = re.search(r"^(\#*)\s+(.*)$", line)
              heading = ""
              captured_title = ""
              if match:
                  heading = match[1]
                  # Remove {: } in devsite Markdown
                  captured_title = re.sub(r"\{:(.*?)\}", "", match[2])
                  # Special case of RFC pages.
                  if re.search(
                      r"^\{\{\s+(.*)\.(.*)\s+\}\}$", captured_title
                  ):
                      heading = ""
                      page_title = "RFC"
                      skip_this_line = True
  
              # Detect Markdown heading levels
              if heading == "#":
                  page_title = captured_title.strip()
                  metadata["title"] = page_title
                  subsection_title = ""
                  section_title = ""
              elif heading == "##":
                  section_title = captured_title.strip()
                  subsection_title = ""
              elif heading == "###":
                  subsection_title = captured_title.strip()
  
              # Convert Markdown headings into plain English
              # (but keep `#` for the `process_document_into_sections()`
              # function to detect these headings for splitting).
              if page_title:
                  new_line = (
                      '# The "'
                      + page_title
                      + '" page includes the following information:\n'
                  )
  
              if section_title:
                  new_line = (
                      '# The "'
                      + page_title
                      + '" page has the "'
                      + section_title
                      + '" section that includes the following information:\n'
                  )
  
              if subsection_title:
                  new_line = (
                      '# On the "'
                      + page_title
                      + '" page, the "'
                      + section_title
                      + '" section has the "'
                      + subsection_title
                      + '" subsection that includes the following information:\n'
                  )
  
          if skip_this_line is False:
              if new_line:
                  updated_markdown += new_line + "\n"
              else:
                  updated_markdown += line + "\n"
      return updated_markdown, metadata
  
file_path: generative-ai-docs/demos/palm/python/docs-agent/scripts/markdown_to_plain_text.py
imports: from markdown import markdown
  from bs4 import BeautifulSoup
  import os
  import re
  import json
  import frontmatter
  import read_config
  import uuid
label_desc: Use image node_id 4 for calling a global function with example usage: process_page_and_section_titles(markdown_text) and returns: updated_markdown,  metadata