From 313e9056e8eb114bc556bc50c163ebafaa6f1bcc Mon Sep 17 00:00:00 2001 From: Kelly Joseph Price Date: Wed, 8 Dec 2021 11:44:42 -0800 Subject: [PATCH] feat: more compiler updates (#383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 🧰 Changes Adds compilers for `html-block` and `readme-glossary-item`. --- __tests__/flavored-compilers.test.js | 29 ++++++++++++++++++++++++++++ processor/compile/glossary.js | 6 ++++++ processor/compile/html-block.js | 9 +++++++++ processor/compile/index.js | 2 ++ 4 files changed, 46 insertions(+) create mode 100644 processor/compile/glossary.js create mode 100644 processor/compile/html-block.js diff --git a/__tests__/flavored-compilers.test.js b/__tests__/flavored-compilers.test.js index ed4e12548..bd4377db6 100644 --- a/__tests__/flavored-compilers.test.js +++ b/__tests__/flavored-compilers.test.js @@ -33,12 +33,41 @@ describe('ReadMe Flavored Blocks', () => { `); }); + it('Glossary Items', () => { + expect(compile(parse('<>'))).toMatchInlineSnapshot(` + "<> + " + `); + }); + it('Emojis', () => { expect(compile(parse(':smiley:'))).toMatchInlineSnapshot(` ":smiley: " `); }); + + it('Html Block', () => { + const text = ` +[block:html] +{ + "html": ${JSON.stringify( + '' + )} +} +[/block] +`; + const ast = parse(text); + + expect(compile(ast)).toMatchInlineSnapshot(` +"[block:html] +{ + \\"html\\": \\"\\" +} +[/block] +" +`); + }); }); describe('ReadMe Magic Blocks', () => { diff --git a/processor/compile/glossary.js b/processor/compile/glossary.js new file mode 100644 index 000000000..415ad60a9 --- /dev/null +++ b/processor/compile/glossary.js @@ -0,0 +1,6 @@ +module.exports = function RdmeGlossaryCompiler() { + const { Compiler } = this; + const { visitors } = Compiler.prototype; + + visitors['readme-glossary-item'] = node => `<>`; +}; diff --git a/processor/compile/html-block.js b/processor/compile/html-block.js new file mode 100644 index 000000000..64e393e3c --- /dev/null +++ b/processor/compile/html-block.js @@ -0,0 +1,9 @@ +module.exports = function () { + const { Compiler } = this; + const { visitors } = Compiler.prototype; + + visitors['html-block'] = node => { + const html = node.data.hProperties.html; + return `[block:html]\n${JSON.stringify({ html }, null, 2)}\n[/block]`; + }; +}; diff --git a/processor/compile/index.js b/processor/compile/index.js index 4640a1d7a..54fdbde80 100644 --- a/processor/compile/index.js +++ b/processor/compile/index.js @@ -5,6 +5,8 @@ export { default as figureCompiler } from './figure'; export { default as codeTabsCompiler } from './code-tabs'; export { default as rdmeEmbedCompiler } from './embed'; export { default as rdmeVarCompiler } from './var'; +export { default as rdmeGlossaryCompiler } from './glossary'; export { default as rdmeCalloutCompiler } from './callout'; export { default as rdmePinCompiler } from './pin'; export { default as imageCompiler } from './image'; +export { default as htmlBlockCompiler } from './html-block';