If you are only interested in the initial question, you can use the SnakeYaml loadAll method:
Object yamlFrontMatter(Yaml yaml, InputStream in) { return yaml.loadAll().iterator().next(); }
SnakeYaml will only read the first structure of the yaml (front) and ignore the final non-yaml text.
Unfortunately, SnakeYaml does not have an elegant way to display the remaining text, so if you want to analyze both the front and the body at the same time, there is no advantage in this approach: - (
source share