Skip to content

Commit

Permalink
fix: Don't convert dates and times that aren't quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
akabekobeko committed Jun 27, 2021
1 parent 449fa46 commit 4adef06
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/vfm.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ It also outputs `<script>` for processing MathJax if `math` is enabled and the m

Frontmatter is a way of defining metadata in Markdown (file) units. Write YAML at the beginning of the file.

I'm using [js-yaml](https://www.npmjs.com/package/js-yaml) for parse in YAML. Schema is [JSON_SCHEMA](https://yaml.org/spec/1.2/spec.html#id2803231).

**VFM**

```yaml
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Element } from 'hast';
import { load as yaml } from 'js-yaml';
import { JSON_SCHEMA, load as yaml } from 'js-yaml';
import { FrontmatterContent, Literal } from 'mdast';
import toString from 'mdast-util-to-string';
import stringify from 'rehype-stringify';
Expand Down Expand Up @@ -101,7 +101,7 @@ const readTitleFromHeading = (tree: Node) => {
*/
const mdast = () => (tree: Node, file: MetadataVFile) => {
visit<FrontmatterContent>(tree, ['yaml'], (node) => {
const value = yaml(node.value);
const value = yaml(node.value, { schema: JSON_SCHEMA });
if (typeof value === 'object') {
file.data = {
...file.data,
Expand Down
20 changes: 20 additions & 0 deletions tests/metadata.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,23 @@ link:
`;
expect(received).toBe(expected);
});

it('Do not convert date and time', () => {
const md = `---
date: 2021-06-27
date2: "2021-06-27"
---`;
const received = stringify(md, { style: ['sample2.css', 'sample3.css'] });
const expected = `<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="date" content="2021-06-27">
<meta name="date2" content="2021-06-27">
</head>
<body></body>
</html>
`;
expect(received).toBe(expected);
});

0 comments on commit 4adef06

Please sign in to comment.