diff --git a/packages/myst-cli/src/process/mdast.ts b/packages/myst-cli/src/process/mdast.ts index d4708c7af..d3f24f22e 100644 --- a/packages/myst-cli/src/process/mdast.ts +++ b/packages/myst-cli/src/process/mdast.ts @@ -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 | undefined; + if (!frontmatter.abbreviations) { + abbreviations = undefined; + } else { + abbreviations = Object.keys(frontmatter.abbreviations).sort().reverse().reduce( + (obj: Record, 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! @@ -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) => {