Skip to content

Commit

Permalink
changed structure of to pretext plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
renee-k committed Aug 12, 2024
1 parent 11a5182 commit 5c59985
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
unifiedLatexToXmlLike,
PluginOptions as HtmlLikePluginOptions,
} from "./unified-latex-plugin-to-xml-like";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { expandUserDefinedMacros } from "./pre-conversion-subs/expand-user-defined-macros";

export type PluginOptions = HtmlLikePluginOptions & {
/**
Expand All @@ -34,19 +34,11 @@ export const unifiedLatexToPretext: Plugin<
? options?.producePretextFragment
: false;

// bring expandmacros in here instead
// getting authorinfo would be in here too

unified().use(unifiedLatexToXmlLike, options).run(tree, file);

// This should happen right before converting to HTML because macros like `\&` should
// be expanded via html rules first (and not turned into their corresponding ligature directly)
expandUnicodeLigatures(tree);
// expand user defined macros
expandUserDefinedMacros(tree);

// If there is a \begin{document}...\end{document}, that's the only
// content we want to convert.
// *move this to before xmllike called
// after done do tree.content = content (content in document env)
let content = tree.content;
visit(
tree,
Expand All @@ -65,6 +57,15 @@ export const unifiedLatexToPretext: Plugin<

tree.content = content;

unified().use(unifiedLatexToXmlLike, options).run(tree, file);

// This should happen right before converting to HTML because macros like `\&` should
// be expanded via html rules first (and not turned into their corresponding ligature directly)
expandUnicodeLigatures(tree);

// update content
content = tree.content;

const toHast = toPretextWithLoggerFactory(file.message.bind(file));
let converted = toHast({ type: "root", content });
if (!Array.isArray(converted)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => {
);
html = process(`a\n b\\begin{foo}x\\end{foo}c\n\nd`);
expect(normalizeHtml(html)).toEqual(
normalizeHtml(`<p>a b</p><div>x</div><p>c</p><p>d</p>`)
normalizeHtml(`<p>a b</p><div>x</div><p>c</p><p>d</p>`) // Need to fix, since foo isn't an env in pretext and no div
);
});

Expand Down

0 comments on commit 5c59985

Please sign in to comment.