def parse(text, encoding='<STR_LIT:utf-8>', handler=None, **defaults):
<EOL>text = u(text, encoding).strip()<EOL>metadata = defaults.copy()<EOL>handler = handler or detect_format(text, handlers)<EOL>if handler is None:<EOL><INDENT>return metadata, text<EOL><DEDENT>try:<EOL><INDENT>fm, content = handler.split(text)<EOL><DEDENT>except ValueError:<EOL><INDENT>return metadata, text<EOL><DEDENT>fm = handler.load(fm)<EOL>if isinstance(fm, dict):<EOL><INDENT>metadata.update(fm)<EOL><DEDENT>return metadata, content.strip()<EOL>
Parse text with frontmatter, return metadata and content.
Pass in optional metadata defaults as keyword args.

If frontmatter is not found, returns an empty metadata dictionary
(or defaults) and original text content.

::

    >>> with open('tests/hello-world.markdown') as f:
    ...     metadata, content = frontmatter.parse(f.read())
    >>> print(metadata['title'])
    Hello, world!