jonschlinkert / gray-matter

Smarter YAML front matter parser, used by metalsmith, Gatsby, Netlify, Assemble, mapbox-gl, phenomic, vuejs vitepress, TinaCMS, Shopify Polaris, Ant Design, Astro, hashicorp, garden, slidev, saber, sourcegraph, and many others. Simple to use, and battle tested. Parses YAML by default but can also parse JSON Front Matter, Coffee Front Matter, TOML Front Matter, and has support for custom parsers. Please follow gray-matter's author: https://github.com/jonschlinkert
https://github.com/jonschlinkert
MIT License
3.97k stars 138 forks source link

Is there a max size for a graymatter line? #115

Closed JeremieLitzler closed 3 years ago

JeremieLitzler commented 3 years ago

Hi,

I have found that the following works:

---
title: 'The Responsive Web Design Bootcamp - Course review'
subtitle: 'Learn to build mobile-friendly websites in a complete course using an interactive classroom.'
author: 'Jeremie Litzler'
date: '16 Mar 2020'
hero_image: ../static/images/webresponsive-bootcamp-by-scrimba.png
category: 'Web development, Reviews'
---

But this one doesn't:

---
title: 'The Responsive Web Design Bootcamp - Course review'
subtitle: 'Let's build the future with a mobile-friendly websites in a complete course using an interactive classroom.'
author: 'Jeremie Litzler'
date: '16 Mar 2020'
hero_image: ../static/images/webresponsive-bootcamp-by-scrimba.png
category: 'Web development, Reviews'
---

and it gives out this error: YAMLException: can not read a block mapping entry; a multiline key may not be an implicit key at line 4.

The length of subtitle is the cause.

Is there a maximum line size per line? Or am I using it improperly?

The source is here.

robertmassaioli commented 3 years ago

The problem is that, in the subtitle example, you are using the ' symbol three times on the one line:

---
subtitle: 'Let's'
---

Does this example highlight the problem? The Yaml parser thinks that there are extra characters after the 'Let' that it does not know how to handle.

The correct way to write your example is:

---
title: The Responsive Web Design Bootcamp - Course review
subtitle: Let's build the future with a mobile\-friendly websites in a complete course using an interactive classroom.
author: Jeremie Litzler
date: 16 Mar 2020
hero_image: "../static/images/webresponsive-bootcamp-by-scrimba.png"
category: Web development, Reviews

Hope that helps. To validate this yourself, I sometimes find that it helps to convert your YAML to JSON, write it correctly in JSON, and then convert it back to YAML. This tool helps: https://www.json2yaml.com/

JeremieLitzler commented 3 years ago

Thanks @robertmassaioli !

I shall follow your advance from then on.

Cheers!