Skip to content

Commit

Permalink
feat: more compiler updates (#383)
Browse files Browse the repository at this point in the history
## 🧰 Changes

Adds compilers for `html-block` and `readme-glossary-item`.
  • Loading branch information
kellyjosephprice authored Dec 8, 2021
1 parent 623a505 commit 313e905
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions __tests__/flavored-compilers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,41 @@ describe('ReadMe Flavored Blocks', () => {
`);
});

it('Glossary Items', () => {
expect(compile(parse('<<glossary:owl>>'))).toMatchInlineSnapshot(`
"<<glossary:owl>>
"
`);
});

it('Emojis', () => {
expect(compile(parse(':smiley:'))).toMatchInlineSnapshot(`
":smiley:
"
`);
});

it('Html Block', () => {
const text = `
[block:html]
{
"html": ${JSON.stringify(
'<style>\n summary {\n padding-top: 8px;\n outline: none !important;\n user-select: none;\n }\n details[open] + details > summary {\n padding-top: 0;\n }\n details > summary + hr {\n opacity: .66;\n }\n</style>'
)}
}
[/block]
`;
const ast = parse(text);

expect(compile(ast)).toMatchInlineSnapshot(`
"[block:html]
{
\\"html\\": \\"<style>\\\\n summary {\\\\n padding-top: 8px;\\\\n outline: none !important;\\\\n user-select: none;\\\\n }\\\\n details[open] + details > summary {\\\\n padding-top: 0;\\\\n }\\\\n details > summary + hr {\\\\n opacity: .66;\\\\n }\\\\n</style>\\"
}
[/block]
"
`);
});
});

describe('ReadMe Magic Blocks', () => {
Expand Down
6 changes: 6 additions & 0 deletions processor/compile/glossary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function RdmeGlossaryCompiler() {
const { Compiler } = this;
const { visitors } = Compiler.prototype;

visitors['readme-glossary-item'] = node => `<<glossary:${node.data.hProperties.term}>>`;
};
9 changes: 9 additions & 0 deletions processor/compile/html-block.js
Original file line number Diff line number Diff line change
@@ -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]`;
};
};
2 changes: 2 additions & 0 deletions processor/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 313e905

Please sign in to comment.