Refactor getEvents slightly to avoid modifying the MicromarkParseOptions object.

This commit is contained in:
David Anson 2024-10-22 22:03:05 -07:00
parent 38b4ec0c2f
commit d94b78e6bf
2 changed files with 12 additions and 12 deletions

View file

@ -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));