Skip to content

Commit

Permalink
Refactor getEvents slightly to avoid modifying the MicromarkParseOpti…
Browse files Browse the repository at this point in the history
…ons object.
  • Loading branch information
DavidAnson committed Oct 23, 2024
1 parent 38b4ec0 commit d94b78e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions demo/markdownlint-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]} */
Expand Down Expand Up @@ -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));

Expand Down
12 changes: 6 additions & 6 deletions helpers/micromark-parse.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]} */
Expand Down Expand Up @@ -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));

Expand Down

0 comments on commit d94b78e

Please sign in to comment.