import yaml


def extract(mdtext):
  """
  Extract a yaml text blob from markdown text and parse the blob.

  Returns a tuple (yaml_obj, markdown_text)
  """
  lines = mdtext.split("\n")
  n = 0
  ylines = []
  mlines = []
  for line in lines:
    if (line == "---"):
      n = n + 1
    else:
      if n == 1:
        ylines.append(line)
      else:
        mlines.append(line)
  yamltext = "\n".join(ylines)
  obj = yaml.load(yamltext, Loader=yaml.SafeLoader)
  return (obj, "\n".join(mlines))