From 23e26402550bf6102a7b71c803b735e38f03f318 Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Mon, 23 May 2022 14:15:31 -0700 Subject: [PATCH] feat: add yaml compiler --- __tests__/flavored-compilers/yaml.test.js | 22 ++++++++++++++++++++++ processor/compile/index.js | 1 + processor/compile/yaml.js | 8 ++++++++ 3 files changed, 31 insertions(+) create mode 100644 __tests__/flavored-compilers/yaml.test.js create mode 100644 processor/compile/yaml.js diff --git a/__tests__/flavored-compilers/yaml.test.js b/__tests__/flavored-compilers/yaml.test.js new file mode 100644 index 000000000..877f1f03b --- /dev/null +++ b/__tests__/flavored-compilers/yaml.test.js @@ -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! +`); + }); +}); diff --git a/processor/compile/index.js b/processor/compile/index.js index 1ae2e9f50..8910c1a76 100644 --- a/processor/compile/index.js +++ b/processor/compile/index.js @@ -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'; diff --git a/processor/compile/yaml.js b/processor/compile/yaml.js new file mode 100644 index 000000000..e493b80ca --- /dev/null +++ b/processor/compile/yaml.js @@ -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---`; + }; +};