Skip to content

Commit

Permalink
feat: order abbreviations by length
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Jan 8, 2024
1 parent 690f469 commit 774ab3b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/myst-cli/src/process/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,21 @@ export async function transformMdast(
// This needs to come before basic transformations since it may add labels to blocks
liftCodeMetadataToBlock(session, vfile, mdast);

// Order abbreviations by length (longest first)
let abbreviations: Record<string, any> | undefined;
if (!frontmatter.abbreviations) {
abbreviations = undefined;
} else {
abbreviations = Object.keys(frontmatter.abbreviations).sort().reverse().reduce(
(obj: Record<string, any>, key) => {
const src = frontmatter.abbreviations?.[key];
obj[key] = src;
return obj;
},
{}
);
}

const pipe = unified()
.use(reconstructHtmlPlugin) // We need to group and link the HTML first
.use(inlineExpressionsPlugin) // Happens before math and images!
Expand All @@ -182,7 +197,7 @@ export async function transformMdast(
.use(inlineMathSimplificationPlugin)
.use(mathPlugin, { macros: frontmatter.math })
.use(glossaryPlugin, { state }) // This should be before the enumerate plugins
.use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
.use(abbreviationPlugin, { abbreviations: abbreviations })
.use(enumerateTargetsPlugin, { state }) // This should be after math/container transforms
.use(joinGatesPlugin);
session.plugins?.transforms.forEach((t) => {
Expand Down

0 comments on commit 774ab3b

Please sign in to comment.