How to extract YAML block before the cmark text?

I’m using with great satisfaction cmark lib from C++ on Windows.
Now few cmark files have a YAML block at the beginning. I want to extract it and decode them.

Seems this cannot be done in the normal cmark lib processing (no special node) and the first ‘—’ is interpreted as thematic break, so I resorted to split out the yaml block from the string I passed to cmark.

Is there any other alternative?
Is there a clear way to split out the yaml block? (my method seems a little fragile)

Thanks for your help!
mario

You could take a look at my lcmark, which will strip out the YAML metadata for you, parse the contents of the metadata fields using CommonMark, and substitute metadata fields into templates.