Projects Blog

Escaping special characters in a markdown frontmatter in Astro

Recently, I ran into an issue while utilizing Astro with Content Collections where I needed to escape some special characters.

In my case, I wanted to add a dots character (:) in the frontmatter YAML title of a markdown file.

If we simply add the dots like this:

title: Markdown frontmatter title: using dots

We will get the following error:

InvalidContentEntryFrontmatterError
Content entry frontmatter does not match schema

We are going to see several solutions.

Using quotes

The easiest solution is just to quote the title content.

title: 'Markdown frontmatter title: using dots'

Block scalar styles

But also, we can use these two YAML block styles:

title: >
Markdown frontmatter title: using dots
title: |
Markdown frontmatter title: using dots

I hope you found this article useful.

Happy coding! 🚀

Related posts