Skip to content

Commit

Permalink
feat: add yaml compiler (#509)
Browse files Browse the repository at this point in the history
## 🧰 Changes

Adds a compiler for frontmatter.

If you try to save a doc in the editor with frontmatter, the save currently fails! Something like the following:

```
---
title: Getting started
---

Coming content
```
  • Loading branch information
kellyjosephprice authored May 23, 2022
1 parent 53865bd commit ac238d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions __tests__/flavored-compilers/yaml.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { mdast, md } from '../../index';

describe('yaml compiler', () => {
it('correctly writes out yaml', () => {
const txt = `
---
title: This is test
author: A frontmatter test
---
Document content!
`;

expect(md(mdast(txt))).toBe(`---
title: This is test
author: A frontmatter test
---
Document content!
`);
});
});
1 change: 1 addition & 0 deletions processor/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export { default as rdmePinCompiler } from './pin';
export { default as rdmeVarCompiler } from './var';
export { default as tableCompiler } from './table';
export { default as tableHeadCompiler } from './table-head';
export { default as yamlCompiler } from './yaml';
8 changes: 8 additions & 0 deletions processor/compile/yaml.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = function YamlCompiler() {
const { Compiler } = this;
const { visitors } = Compiler.prototype;

visitors.yaml = function compile(node) {
return `---\n${node.value}\n---`;
};
};

0 comments on commit ac238d1

Please sign in to comment.