From c3e686663d15b3646be3a920f33ad1bc792965ab Mon Sep 17 00:00:00 2001 From: Jonny Gerig Meyer Date: Thu, 22 Jun 2023 15:28:43 -0400 Subject: [PATCH] update comments --- CONTRIBUTING.md | 7 +++---- source/helpers/components/codeExample.ts | 4 ---- source/helpers/type.ts | 11 ++++++----- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 34edbb2..5f3fc28 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -78,10 +78,9 @@ npm run lint while `render` always parses the partial as a LiquidJS template. - `.md` files are parsed both as Markdown _and_ as LiquidJS templates. - When using Markdown, remember that _indentation and whitespace (e.g newlines) - matter_. Use Markdown selectively, especially in files that include other - non-Markdown partials. - - For example, the `{% codeExample %}` tag renders whitespace that results - in unwanted `

` tags when parsed as Markdown. + matter_. Custom tags attempt to strip leading whitespace from text contents + (based on the whitespace of the first line) to allow for indented code blocks + -- see the `stripIndent` function in `source/helpers/type.ts` for details. ## Deploying diff --git a/source/helpers/components/codeExample.ts b/source/helpers/components/codeExample.ts index d8a5fc2..ceae8a1 100644 --- a/source/helpers/components/codeExample.ts +++ b/source/helpers/components/codeExample.ts @@ -46,10 +46,6 @@ import {stripIndent} from '../type'; * If `syntax` is either `sass` or `scss`, the first section will be * interpreted as that syntax and the second will be interpreted (or * auto-generated) as the CSS output. - * - * Note that this template includes whitespace that renders unwanted extra `

` - * tags when parsed as Markdown. To avoid this, ensure that any usage of - * `{% codeExample %}` is *not* within a Markdown file or block. */ export default async function codeExample( contents: string, diff --git a/source/helpers/type.ts b/source/helpers/type.ts index 072459e..27d6f09 100644 --- a/source/helpers/type.ts +++ b/source/helpers/type.ts @@ -34,15 +34,16 @@ export const getLorem = (type: string, number = 1) => { * @see https://github.com/jamiebuilds/min-indent */ export const stripIndent = (contents: string) => { - // Strip leading whitespace based on line with least leading whitespace - let text = contents; // Find leading whitespace of first line (ignoring initial newlines) - const match = /^[\n\r]*([ \t]*)(?=\S)/.exec(text); + const match = /^[\n\r]*([ \t]*)(?=\S)/.exec(contents); if (match?.[1]?.length) { // Strip leading whitespace based on first line - text = text.replaceAll(new RegExp(`^[ \\t]{${match[1].length}}`, 'gm'), ''); + return contents.replaceAll( + new RegExp(`^[ \\t]{${match[1].length}}`, 'gm'), + '' + ); } - return text; + return contents; }; /**