# How to extract YAML block before the cmark text?

**URL:** <https://talk.commonmark.org/t/how-to-extract-yaml-block-before-the-cmark-text/2160>\
**Category:** Implementation\
**Created:** [July 13, 2016, 2:31pm UTC](https://talk.commonmark.org/t/how-to-extract-yaml-block-before-the-cmark-text/2160 "2016-07-13T14:31:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mvalle](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/mvalle/32/932_2.png) [@mvalle](https://talk.commonmark.org/u/mvalle)\
**Post date:** [July 13, 2016, 2:31pm UTC](https://talk.commonmark.org/t/how-to-extract-yaml-block-before-the-cmark-text/2160/1 "2016-07-13T14:31:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jgm](https://cdn.commonmark.org/user_avatar/talk.commonmark.org/jgm/32/1360_2.png) [@jgm](https://talk.commonmark.org/u/jgm)\
**Post date:** [July 13, 2016, 5:30pm UTC](https://talk.commonmark.org/t/how-to-extract-yaml-block-before-the-cmark-text/2160/2 "2016-07-13T17:30:16Z")

</div>

You could take a look at my [lcmark](https://github.com/jgm/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.
