update comments

This commit is contained in:
Jonny Gerig Meyer 2023-06-22 15:28:43 -04:00
parent 639557c46d
commit c3e686663d
No known key found for this signature in database
3 changed files with 9 additions and 13 deletions

View File

@ -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 `<p>` 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

View File

@ -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 `<p>`
* 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,

View File

@ -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;
};
/**