import yaml


def compare_markdown_content(file1, file2, compare='both'):
    """Compare Markdown file metadata

    Args:
        file1 (str): first file contents
        file2 (str): second file contents
        compare (str): compare 'meta', 'body' or 'both'

    Returns:
        True if metadata are logically the same, False otherwise
    """

    if '...' in file1:
        meta1, _, body1 = file1.partition('...\n')
    else:
        return False

    if '...' in file2:
        meta2, _, body2 = file2.partition('...\n')
    else:
        return False

    if compare in ['meta', 'both']:
        try:
            meta1 = yaml.safe_load(meta1)
        except yaml.YAMLError:
            print(f'Error in metadata for file 1')
            return False

        try:
            meta2 = yaml.safe_load(meta2)
        except yaml.YAMLError:
            print(f'Error in metadata for file 2')
            return False

        if meta1 != meta2:
            return False

    if compare in ['body', 'both']:
        if body1 != body2:
            return False

    return True