Very often, the YAML front matter includes text that will display on a page, like the following:
title: Hello World 🌎
However, the proper YAML would be:
title: Hello World \U0001F4CD
FM currently adds the non-printable character (like an emoji) to the text, which errors out on build since it is not properly formatted YAML
I can understand that FM would not want to modify an existing file, but there is an opportunity to catch non-printable characters when creating/modifying metadata in the Front Matter rail
Author: @BillRaymond
Related to the following Discord thread: https://discord.com/channels/992409023607476224/1085255612939640832
Very often, the YAML front matter includes text that will display on a page, like the following:
title: Hello World 🌎
However, the proper YAML would be:
title: Hello World \U0001F4CD
FM currently adds the non-printable character (like an emoji) to the text, which errors out on build since it is not properly formatted YAML
I can understand that FM would not want to modify an existing file, but there is an opportunity to catch non-printable characters when creating/modifying metadata in the Front Matter rail
Author: @BillRaymond
<!-- github-sync-id:1624980968 -->
Adding the `encodeEmoji` property to the string field. When enabling this property on the field, it encodes all emojis.
Example: `Hello World 🌎` becomes `Hello World \u1F30E`.
Verified against: https://unicodeplus.com/U+1F30E
<!-- github-comment-id:1476073560 -->
Yes @davidsneighbour, but for @BillRaymond it isn't it seems. That is why an extra property is introduced. If your SSG/framework wouldn't support it, you can let FM encode it for you.
Yes @davidsneighbour, but for @BillRaymond it isn't it seems. That is why an extra property is introduced. If your SSG/framework wouldn't support it, you can let FM encode it for you.
<!-- github-comment-id:1476134783 -->
By default, it will keep using Hello World 🌏, only if you need to encode the emoji, you will have to tell FM to do this.
By default, it will keep using `Hello World 🌏`, only if you need to encode the emoji, you will have to tell FM to do this.
<!-- github-comment-id:1476136114 -->
While you can add emojis and other non-printable characters to YAML, they are technically not allowed. See here. Some YAML processors handle this for you, but others do not. In my specific situation, I use Jekyll (also the default for GitHub Pages), which errors out. That is why I requested that FM provide a conversion option.
> Isn't
>
> title: "Hello World 🌏"
>
> possible/valid too?
While you can add emojis and other non-printable characters to YAML, they are technically not allowed. See [here](https://yaml.org/spec/1.2.2/#character-set). Some YAML processors handle this for you, but others do not. In my specific situation, I use Jekyll (also the default for GitHub Pages), which errors out. That is why I requested that FM provide a conversion option.
<!-- github-comment-id:1476631600 -->
Since you are still working on this enhancement, I did some testing on my local machine using Front Matter. I noticed you only sometimes add quotations around strings. However, you need the quotes if you add escape codes to display non-printable characters.
For example:
title: \U0001F30E The title of my post
Outputs:
\U0001F30E The title of my post
But, if you put the title in quotes, you get the non-printable character. For example:
title: "\U0001F30E The title of my post"
Outputs:
🌎 The title of my post
I hope this will help you during your development process.
Since you are still working on this enhancement, I did some testing on my local machine using Front Matter. I noticed you only sometimes add quotations around strings. However, you need the quotes if you add escape codes to display non-printable characters.
For example:
```
title: \U0001F30E The title of my post
```
Outputs:
```
\U0001F30E The title of my post
```
But, if you put the title in quotes, you get the non-printable character. For example:
```
title: "\U0001F30E The title of my post"
```
Outputs:
```
🌎 The title of my post
```
I hope this will help you during your development process.
<!-- github-comment-id:1476943767 -->
I have done some tests, and in my environment, when double quotes are added, it will use a double backslash, which is how it should be to correctly parse the string.
I have done some tests, and in my environment, when double quotes are added, it will use a double backslash, which is how it should be to correctly parse the string.
https://user-images.githubusercontent.com/2900833/226557345-c5af9121-9e85-44e9-8546-3da487597e7c.mov
<!-- github-comment-id:1477466521 -->
In this example, I add the Unicode escape character into the title. FM does not automatically put the title in quotes.
If the YAML is not in quotes, the Unicode is processed as regular text and does not display the non-printable character.
However, if I manually put the title in quotes, the proper non-printable character is processed and displays on the website.
In this example, I add the Unicode escape character into the title. FM does not automatically put the title in quotes.
If the YAML is not in quotes, the Unicode is processed as regular text and does not display the non-printable character.
However, if I manually put the title in quotes, the proper non-printable character is processed and displays on the website.

<!-- github-comment-id:1478810265 -->
Although it makes it work for your use case, it is not valid for a JSON object. We will have to think about how we can get this supported, as the double backslash is the right way to encode it.
Although it makes it work for your use case, it is not valid for a JSON object. We will have to think about how we can get this supported, as the double backslash is the right way to encode it.
<!-- github-comment-id:1479089927 -->
Like I thought, it becomes invalid YAML for the parser:
Like I thought, it becomes invalid YAML for the parser:

<!-- github-comment-id:1479119746 -->
I just did a test on Jekyll, and I can just use 🌎 in the title:
---layout:posttitle:🌎 Welcome to Jekyll!date:2022-04-21 11:44:23 +0200categories:jekyll update---
Can it be related to your theme?
I just did a test on Jekyll, and I can just use `🌎` in the title:

```markdown
---
layout: post
title: 🌎 Welcome to Jekyll!
date: 2022-04-21 11:44:23 +0200
categories: jekyll update
---
```
Can it be related to your theme?
<!-- github-comment-id:1479191896 -->
I do not have a theme (I started from the default Minima, but it does not use anything custom). Was the way I added the emoji a problem? I am unsure about that question, so I will run some tests and remove any plugins I may not use.
This still seems valid to look at since YAML does not support non-printable characters and could cause portability issues.
I do not have a theme (I started from the default Minima, but it does not use anything custom). Was the way I added the emoji a problem? I am unsure about that question, so I will run some tests and remove any plugins I may not use.
This still seems valid to look at since YAML does not support non-printable characters and could cause portability issues.
<!-- github-comment-id:1479908512 -->
It seems that backslashes and YAML is a big topic, most recommend to avoid using backslashes. That said, the only valid way to have a backslash in the JS and Python YAML parser is to use two backslashes when using quotes. This is what the parser will automatically add while parsing.
It seems that backslashes and YAML is a big topic, most recommend to avoid using backslashes. That said, the only valid way to have a backslash in the JS and Python YAML parser is to use two backslashes when using quotes. This is what the parser will automatically add while parsing.
<!-- github-comment-id:1479921983 -->

It is also in the YAML docs.
<!-- github-comment-id:1479926990 -->
Okay, I am sorry I led you astray with the single \. That is what I get for using SO and not digging properly into the YAML docs for that one.
Okay, I am sorry I led you astray with the single `\`. That is what I get for using SO and not digging properly into the YAML docs for that one.
<!-- github-comment-id:1479938764 -->
No worries, I learned something from it as well. I might just keep the setting as is right now, in case anyone else might ever need it.
No worries, I learned something from it as well. I might just keep the setting as is right now, in case anyone else might ever need it.
<!-- github-comment-id:1480052379 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Related to the following Discord thread: https://discord.com/channels/992409023607476224/1085255612939640832
Very often, the YAML front matter includes text that will display on a page, like the following:
title: Hello World 🌎
However, the proper YAML would be:
title: Hello World \U0001F4CD
FM currently adds the non-printable character (like an emoji) to the text, which errors out on build since it is not properly formatted YAML
I can understand that FM would not want to modify an existing file, but there is an opportunity to catch non-printable characters when creating/modifying metadata in the Front Matter rail
Author: @BillRaymond
Adding the
encodeEmojiproperty to the string field. When enabling this property on the field, it encodes all emojis.Example:
Hello World 🌎becomesHello World \u1F30E.Verified against: https://unicodeplus.com/U+1F30E
Isn't
title: "Hello World 🌏"
possible/valid too?
Yes @davidsneighbour, but for @BillRaymond it isn't it seems. That is why an extra property is introduced. If your SSG/framework wouldn't support it, you can let FM encode it for you.
By default, it will keep using
Hello World 🌏, only if you need to encode the emoji, you will have to tell FM to do this.While you can add emojis and other non-printable characters to YAML, they are technically not allowed. See here. Some YAML processors handle this for you, but others do not. In my specific situation, I use Jekyll (also the default for GitHub Pages), which errors out. That is why I requested that FM provide a conversion option.
Thank you!
Since you are still working on this enhancement, I did some testing on my local machine using Front Matter. I noticed you only sometimes add quotations around strings. However, you need the quotes if you add escape codes to display non-printable characters.
For example:
Outputs:
But, if you put the title in quotes, you get the non-printable character. For example:
Outputs:
I hope this will help you during your development process.
Thanks @BillRaymond, it is the YAML parser which decides to add quotes or not, will take a look why and when.
I have done some tests, and in my environment, when double quotes are added, it will use a double backslash, which is how it should be to correctly parse the string.
https://user-images.githubusercontent.com/2900833/226557345-c5af9121-9e85-44e9-8546-3da487597e7c.mov
In this example, I add the Unicode escape character into the title. FM does not automatically put the title in quotes.
If the YAML is not in quotes, the Unicode is processed as regular text and does not display the non-printable character.
However, if I manually put the title in quotes, the proper non-printable character is processed and displays on the website.
Although it makes it work for your use case, it is not valid for a JSON object. We will have to think about how we can get this supported, as the double backslash is the right way to encode it.
Like I thought, it becomes invalid YAML for the parser:
I just did a test on Jekyll, and I can just use
🌎in the title:Can it be related to your theme?
I do not have a theme (I started from the default Minima, but it does not use anything custom). Was the way I added the emoji a problem? I am unsure about that question, so I will run some tests and remove any plugins I may not use.
This still seems valid to look at since YAML does not support non-printable characters and could cause portability issues.
It seems that backslashes and YAML is a big topic, most recommend to avoid using backslashes. That said, the only valid way to have a backslash in the JS and Python YAML parser is to use two backslashes when using quotes. This is what the parser will automatically add while parsing.
Ah, so it still needs to be in quotes, but also use
\\is the proper approach?It is also in the YAML docs.
Okay, I am sorry I led you astray with the single
\. That is what I get for using SO and not digging properly into the YAML docs for that one.No worries, I learned something from it as well. I might just keep the setting as is right now, in case anyone else might ever need it.
Is there a feature in the beta I should be testing, or are you still in development?
All is fine, I keep it in progress, as I still need to document it.