def read_metadata(text, ext):
    """Return the header metadata"""
    ext = '.' + ext.split('.')[-1]
    lines = text.splitlines()

    if ext in ['.md', '.Rmd']:
        comment = ''
    else:
        comment = _SCRIPT_EXTENSIONS.get(ext, {}).get('comment', '#')

    metadata, _, _, _ = header_to_metadata_and_cell(lines, comment, ext)
    if ext in ['.r', '.R'] and not metadata:
        metadata, _, _, _ = header_to_metadata_and_cell(lines, "#'", ext)

    return metadata
Return the header metadata