Hash symbol is cutting off content
martyboggs opened this issue · 4 comments
When I put the "#" symbol in the headmatter, the end of the content gets cut off right before the symbol.
Can you please provide an example that shows the problem? Complete with sample frontmatter and code with options?
Hello, @robertmassaioli, there are some examples of the behaviour with a hash, I guess @martyboggs meant this:
We have a standard structure of the file with front matter:
---
tags: #tag
---
Some text.
With different inputs:
Front matter row | Parsed value | Expected value |
---|---|---|
tags: "#tag #tag2" |
{ "tags": "#tag #tag2" } |
OK |
tags: #tag #tag2 |
{ "tags": null } |
{ "tags": "#tag #tag2" } |
tags: text#tag #tag2 |
{ "tags": "text#tag" } |
{ "tags": "text#tag #tag2" } |
And basic usage:
import matter from 'gray-matter';
const rawText = (await import('file.mdx')).default;
const { content, data } = matter(rawText);
The #
character represents a Comment in YAML: https://yaml.org/spec/1.2/spec.html#id2773032
If you have a string in YAML that contains a #
then I would make sure that it was wrapped in quotes.
Your examples 1 and 3 are expected behaviour for a yaml parser. Even option 2 is legitimate because, with comments removed, it is the same as:
tags:
and is thus parsed to null correctly. There is no issue here.
I'm closing this as not a bug.