Skip to content

Commit

Permalink
modified plugins to include new boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
renee-k committed Jul 9, 2024
1 parent 24008c6 commit 78a9463
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type PluginOptions = {
* A boolean where if it's true then the output won't be wrapped in the <pretext><article> ... etc. tags.
* If it's false (default), a valid and complete PreTeXt document is returned.
*/
producePretextFragment?: false;
producePretextFragment?: boolean;
};

/**
Expand All @@ -64,6 +64,11 @@ export const unifiedLatexToXmlLike: Plugin<
_environmentReplacements,
options?.environmentReplacements || {}
);
const producePretextFragment = Object.assign(
{},
false,
options?.producePretextFragment || {}
);
const isReplaceableMacro = match.createMacroMatcher(macroReplacements);
const isReplaceableEnvironment = match.createEnvironmentMatcher(
environmentReplacements
Expand Down Expand Up @@ -132,7 +137,8 @@ export const unifiedLatexToXmlLike: Plugin<
}
});

if (!options.producePretextFragment) {
// if (!options.producePretextFragment) {
if (!producePretextFragment) {
// Wrap in enough tags to ensure a valid pretext document
// ...
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect } from "vitest";
import Prettier from "prettier";
import util from "util";
import { processLatexViaUnified } from "@unified-latex/unified-latex";
import { unifiedLatexToPretext, PluginOptions } from "../libs/unified-latex-plugin-to-pretext";
import { unifiedLatexToPretext } from "../libs/unified-latex-plugin-to-pretext";
import { htmlLike } from "@unified-latex/unified-latex-util-html-like";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { match } from "@unified-latex/unified-latex-util-match";
Expand All @@ -29,7 +29,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => {

const process = (value: string) =>
processLatexViaUnified({ macros: { xxx: { signature: "m m" } } })
.use(unifiedLatexToPretext, {producePretextFragment: true })
.use(unifiedLatexToPretext, { producePretextFragment: true })
.use(xmlCompilePlugin)
.processSync({ value }).value as string;

Expand All @@ -40,13 +40,13 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => {
html = process("\\bfseries a\n\nb");
expect(html).toEqual(
// '<p><b class="textbf">a</b></p><p><b class="textbf">b</b></p>'
'<p><em>a</em></p><p><em>b</em></p>' // maybe alert instead, test difference
"<p><em>a</em></p><p><em>b</em></p>" // maybe alert instead, test difference
);

html = process("\\bf a\n\nb");
expect(html).toEqual(
// '<p><b class="textbf">a</b></p><p><b class="textbf">b</b></p>'
'<p><em>a</em></p><p><em>b</em></p>'
"<p><em>a</em></p><p><em>b</em></p>"
);
});

Expand Down Expand Up @@ -346,6 +346,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => {
yyy: (node) =>
htmlLike({ tag: "yyy", content: node.content }),
},
producePretextFragment: true,
})
.use(xmlCompilePlugin)
.processSync({ value }).value as string;
Expand Down Expand Up @@ -387,6 +388,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => {
});
},
},
producePretextFragment: true,
})
.use(xmlCompilePlugin)
.processSync({ value }).value as string;
Expand Down

0 comments on commit 78a9463

Please sign in to comment.