From d94b78e6bfd20b061b1856a70faedd16a7b4d17a Mon Sep 17 00:00:00 2001 From: David Anson Date: Tue, 22 Oct 2024 22:03:05 -0700 Subject: [PATCH] Refactor getEvents slightly to avoid modifying the MicromarkParseOptions object. --- demo/markdownlint-browser.js | 12 ++++++------ helpers/micromark-parse.cjs | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/demo/markdownlint-browser.js b/demo/markdownlint-browser.js index e41416622..6d810f7eb 100644 --- a/demo/markdownlint-browser.js +++ b/demo/markdownlint-browser.js @@ -1023,15 +1023,15 @@ function getEvents( markdown, micromarkParseOptions = {} ) { - // Customize options object to add useful extensions - micromarkParseOptions.extensions = micromarkParseOptions.extensions || []; - micromarkParseOptions.extensions.push( + // Customize extensions list to add useful extensions + const extensions = [ micromark.directive(), micromark.gfmAutolinkLiteral(), micromark.gfmFootnote(), micromark.gfmTable(), - micromark.math() - ); + micromark.math(), + ...(micromarkParseOptions.extensions || []) + ]; // // Shim labelEnd to identify undefined link labels /** @type {Event[][]} */ @@ -1153,7 +1153,7 @@ function getEvents( // Use micromark to parse document into Events const encoding = undefined; const eol = true; - const parseContext = micromark.parse(micromarkParseOptions); + const parseContext = micromark.parse({ ...micromarkParseOptions, extensions }); const chunks = micromark.preprocess()(markdown, encoding, eol); const events = micromark.postprocess(parseContext.document().write(chunks)); diff --git a/helpers/micromark-parse.cjs b/helpers/micromark-parse.cjs index 62ce20369..0ca3373ed 100644 --- a/helpers/micromark-parse.cjs +++ b/helpers/micromark-parse.cjs @@ -32,15 +32,15 @@ function getEvents( markdown, micromarkParseOptions = {} ) { - // Customize options object to add useful extensions - micromarkParseOptions.extensions = micromarkParseOptions.extensions || []; - micromarkParseOptions.extensions.push( + // Customize extensions list to add useful extensions + const extensions = [ micromark.directive(), micromark.gfmAutolinkLiteral(), micromark.gfmFootnote(), micromark.gfmTable(), - micromark.math() - ); + micromark.math(), + ...(micromarkParseOptions.extensions || []) + ]; // // Shim labelEnd to identify undefined link labels /** @type {Event[][]} */ @@ -162,7 +162,7 @@ function getEvents( // Use micromark to parse document into Events const encoding = undefined; const eol = true; - const parseContext = micromark.parse(micromarkParseOptions); + const parseContext = micromark.parse({ ...micromarkParseOptions, extensions }); const chunks = micromark.preprocess()(markdown, encoding, eol); const events = micromark.postprocess(parseContext.document().write(chunks));