code: def markdown_to_text(markdown_string):
      # Remove <!-- --> lines in Markdown
      markdown_string = re.sub(r"<\!--(.*?)-->", "", markdown_string)
  
      # md -> html -> text since BeautifulSoup can extract text cleanly
      html = markdown(markdown_string)
  
      # Extract text
      soup = BeautifulSoup(html, "html.parser")
      text = "".join(soup.findAll(string=True))
  
      # Remove [][] in Markdown
      text = re.sub(r"\[(.*?)\]\[(.*?)\]", "\\1", text)
  
      # Remove {: } in Markdown
      text = re.sub(r"\{:(.*?)\}", "", text)
  
      # Remove {. } in Markdown
      text = re.sub(r"\{.(.*?)\}", "", text)
  
      # Remove a single line `sh` in Markdown
      text = re.sub(r"(?m)^sh$", "", text)
  
      # Remove a single line ````sh` in Markdown
      # text = re.sub(r'(?m)^```sh$', '', text)
  
      # Remove code snippets
      text = re.sub(r"<pre>(.*?)</pre>", "\\1", text)
      text = re.sub(r"<code>(.*?)</code>", "\\1", text)
      text = re.sub(r"(?m)<var>(.*?)</var>", "\\1", text)
      text = re.sub(
          r"(^|)(Important|Note|Caution|Tip|Warning|Important|Key Point|Key Term):\s?",
          "",
          text,
      )
      text = re.sub(
          r"(^|)(Objective|Success|Beta|Preview|Deprecated):\s?",
          "",
          text,
      )
      text = re.sub(r"(Project|Book):(.*)\n", "", text)
      text = text.strip() + "\n"
      return text
  
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 2 for calling a global function with example usage: markdown_to_text(markdown_string) and returns: text