From 2db58427ddd0b8cdf6babb33d2f0a3de8039c22a Mon Sep 17 00:00:00 2001 From: AleksandrHovhannisyan Date: Thu, 8 Dec 2022 07:55:38 -0500 Subject: [PATCH] Rearrange code --- src/index.js | 65 +--------------------------- src/utils.js | 64 ++++++++++++++++++++++++++- src/{index.test.js => utils.test.js} | 2 +- 3 files changed, 66 insertions(+), 65 deletions(-) rename src/{index.test.js => utils.test.js} (98%) diff --git a/src/index.js b/src/index.js index 6da7d37..544eb71 100644 --- a/src/index.js +++ b/src/index.js @@ -1,65 +1,4 @@ -const escape = require('lodash/escape'); -const minifyHtml = require('@minify-html/node'); -const markdownIt = require('markdown-it'); -const outdent = require('outdent'); -const { parseCode, stringifyAttributes } = require('./utils'); -const clsx = require('clsx'); - -/** - * Higher-order function that takes user configuration options and returns the plugin shortcode. - * @param {import('./typedefs').EleventyPluginCodeDemoOptions} options - */ -const makeCodeDemoShortcode = (options) => { - const sharedIframeAttributes = options.iframeAttributes; - - /** - * @param {string} source The children of this shortcode, as Markdown code blocks. - * @param {string} title The title to set on the iframe. - * @param {Record} props HTML attributes to set on this specific ``; - }; - - return codeDemoShortcode; -}; +const { makeCodeDemoShortcode } = require('./utils'); /** * @param {import('@11ty/eleventy/src/UserConfig')} eleventyConfig @@ -70,4 +9,4 @@ const EleventyPluginCodeDemo = (eleventyConfig, options) => { eleventyConfig.addPairedShortcode(name, makeCodeDemoShortcode({ ...options, name })); }; -module.exports = { makeCodeDemoShortcode, EleventyPluginCodeDemo }; +module.exports = { EleventyPluginCodeDemo }; diff --git a/src/utils.js b/src/utils.js index c1a8ced..6fa6896 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,9 @@ +const escape = require('lodash/escape'); +const minifyHtml = require('@minify-html/node'); +const markdownIt = require('markdown-it'); +const outdent = require('outdent'); +const clsx = require('clsx'); + /** * Given an array of tokens and a type of token to look up, finds all such matching tokens and returns one * big string concatenating all of those tokens' content. @@ -23,4 +29,60 @@ const stringifyAttributes = (attributeMap) => { .join(' '); }; -module.exports = { parseCode, stringifyAttributes }; +/** + * Higher-order function that takes user configuration options and returns the plugin shortcode. + * @param {import('./typedefs').EleventyPluginCodeDemoOptions} options + */ +const makeCodeDemoShortcode = (options) => { + const sharedIframeAttributes = options.iframeAttributes; + + /** + * @param {string} source The children of this shortcode, as Markdown code blocks. + * @param {string} title The title to set on the iframe. + * @param {Record} props HTML attributes to set on this specific ``; + }; + + return codeDemoShortcode; +}; + +module.exports = { makeCodeDemoShortcode }; diff --git a/src/index.test.js b/src/utils.test.js similarity index 98% rename from src/index.test.js rename to src/utils.test.js index 00fda2c..07bd77d 100644 --- a/src/index.test.js +++ b/src/utils.test.js @@ -1,5 +1,5 @@ const { outdent } = require('outdent'); -const { makeCodeDemoShortcode } = require('.'); +const { makeCodeDemoShortcode } = require('./utils'); describe('makeCodeDemoShortcode', () => { it('includes html, css, and js', () => {