from typing import Tuple
import yaml


def _pop_meta(content) -> Tuple[str, dict]:
    """ Extract meta data from a markdown content.

    Meta data section starts with `---` and ends with `---`
    This function expects the meta data in one block, in yaml format.
    """
    header = []
    rest = []
    header_content = False
    for line in content.splitlines():
        if line.startswith('---'):
            header_content = ~header_content
            continue
        if header_content:
            header.append(line)
        else:
            rest.append(line)

    meta = yaml.load('\n'.join(header), yaml.FullLoader)
    if meta is None:
        meta = {}

    return '\n'.join(rest), meta