deno_std
deno_std copied to clipboard
front_matter returns false possitives
I have the following code to extract front matter data from files:
import { extract, test } from "./deps/front_matter.ts";
if (test(content)) {
const { attrs = {}, body } = extract<Data>(content);
attrs.content = body;
return attrs;
}
The test function returns true with Markdown files with separators like ---. For example.
# Project title
---
This is a description of the project
- **Author:** The DPM Authors
- **Version:** 0.1.0
- **License:** MIT
---
MIT License
And this makes the script to fail:
TypeError: Failed to extract front matter
at extract (https://deno.land/[email protected]/encoding/front_matter.ts:56:9)
To consider that a file content has front matter, the triple dash separator must be at the begining of the content. In this case there's a title before, so the test function should return false.
Steps to Reproduce
- Create a file with markdown content and two separators
---. - Run the
testfunction with this content. - The function returns
true.
- OS: MacOS 12
- deno version: 1.25
- std version: 0.153.0
The bug is actuallly happening, I'm already working on fixing it!
I have added a exclusive validation for the first line for multiline texts like yours, I think that should do the trick
closed by #2801