Skip to content

Commit

Permalink
fixed all new PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
renee-k committed Aug 15, 2024
1 parent d5b50f9 commit c359495
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function enumerateFactory(parentTag = "ol") {
}

/**
*
* Remove the env environment by returning the content in env only.
*/
function removeEnv(env: Ast.Environment, info: VisitInfo, file?: VFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getArgsContent } from "@unified-latex/unified-latex-util-arguments";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { VisitInfo } from "@unified-latex/unified-latex-util-visit";
import { VFile } from "unified-lint-rule/lib";
import { makeWarningMessage, emptyStringWithWarning } from "./utils";
import { makeWarningMessage, emptyStringWithWarningFactory } from "./utils";

/**
* Factory function that generates html-like macros that wrap their contents.
Expand Down Expand Up @@ -88,13 +88,11 @@ export const macroReplacements: Record<
"em",
`Warning: There is no equivalent tag for \"underline\", \"em\" was used as a replacement.`
),
mbox: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"mbox\", an empty Ast.String was used as a replacement.`,
"macro-subs"
mbox: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"mbox\", an empty Ast.String was used as a replacement.`
),
phantom: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"phantom\", an empty Ast.String was used as a replacement.`,
"macro-subs"
phantom: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"phantom\", an empty Ast.String was used as a replacement.`
),
appendix: createHeading("appendix"),
url: (node) => {
Expand Down Expand Up @@ -130,33 +128,27 @@ export const macroReplacements: Record<
content: args[1] || [],
});
},
"\\": emptyStringWithWarning(
`Warning: There is no equivalent tag for \"\\\", an empty Ast.String was used as a replacement.`,
"macro-subs"
"\\": emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"\\\", an empty Ast.String was used as a replacement.`
),
vspace: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"vspace\", an empty Ast.String was used as a replacement.`,
"macro-subs"
vspace: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"vspace\", an empty Ast.String was used as a replacement.`
),
hspace: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"hspace\", an empty Ast.String was used as a replacement.`,
"macro-subs"
hspace: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"hspace\", an empty Ast.String was used as a replacement.`
),
textcolor: factory(
"em",
`Warning: There is no equivalent tag for \"textcolor\", \"em\" was used as a replacement.`
),
textsize: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"textsize\", an empty Ast.String was used as a replacement.`,
"macro-subs"
textsize: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"textsize\", an empty Ast.String was used as a replacement.`
),
makebox: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"makebox\", an empty Ast.String was used as a replacement.`,
"macro-subs"
), // remove for now
noindent: emptyStringWithWarning(
`Warning: There is no equivalent tag for \"noindent\", an empty Ast.String was used as a replacement.`,
"macro-subs"
makebox: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"makebox\", an empty Ast.String was used as a replacement.`
),
noindent: emptyStringWithWarningFactory(
`Warning: There is no equivalent tag for \"noindent\", an empty Ast.String was used as a replacement.`
),
includegraphics: (node) => {
const args = getArgsContent(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { VFileMessage } from "vfile-message";
export function makeWarningMessage(
node: Ast.Node,
message: string,
sourceFile: string
warningType: string
): VFileMessage {
const newMessage = new VFileMessage(message, node);

newMessage.source = `unified-latex-to-pretext:${sourceFile}`;
newMessage.source = `unified-latex-to-pretext:${warningType}`;

return newMessage;
}
Expand All @@ -23,22 +23,21 @@ export function makeWarningMessage(
* Create an empty Ast.String node, adding a warning message from
* the source file into the VFile.
*/
export function emptyStringWithWarning(
warningMessage: string,
sourceFile: string
export function emptyStringWithWarningFactory(
warningMessage: string
): (node: Ast.Node, info: VisitInfo, file?: VFile) => Ast.String {
return (node, info, file) => {
// add a warning message
if (file) {
const message = makeWarningMessage(
node,
warningMessage,
sourceFile
"macro-subs"
);
file.message(
message,
message.position,
`unified-latex-to-pretext:${sourceFile}`
`unified-latex-to-pretext:macro-subs`
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,16 @@ export function toPretextWithLoggerFactory(
// create a title tag containing the division macro's title arg
const title = getArgsContent(node)[0];

if (!title) {
logger(
`Warning: No title was given, so an empty title tag was used.`,
node
);
}

const titleTag = x("title", title?.flatMap(toPretext));

if (divisionName && title) {
if (divisionName) {
return x(divisionName, [
titleTag,
...node.content.flatMap(toPretext),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type PluginOptions = {
*
* Note: this plugin only wraps paragraphs in `p` tags if there are multiple paragraphs. Otherwise it omits the <p> tags.
*/
export const unifiedLatexToXmlLike: Plugin<
export const unifiedLatexToPretextLike: Plugin<
PluginOptions[],
Ast.Root,
Hast.Root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { match } from "@unified-latex/unified-latex-util-match";
import { EXIT, visit } from "@unified-latex/unified-latex-util-visit";
import { toPretextWithLoggerFactory } from "./pretext-subs/to-pretext";
import {
unifiedLatexToXmlLike,
unifiedLatexToPretextLike,
PluginOptions as HtmlLikePluginOptions,
} from "./unified-latex-plugin-to-xml-like";
} from "./unified-latex-plugin-to-pretext-like";
import { expandUserDefinedMacros } from "./pre-conversion-subs/expand-user-defined-macros";

export type PluginOptions = HtmlLikePluginOptions & {
Expand Down Expand Up @@ -58,7 +58,7 @@ export const unifiedLatexToPretext: Plugin<
// since we don't want to wrap content outside of \begin{document}...\end{document} with <pretext>...</pretext>
tree.content = content;

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

// This should happen right before converting to PreTeXt because macros like `\&` should
// be expanded via html rules first (and not turned into their corresponding ligature directly)
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 { processLatexViaUnified } from "@unified-latex/unified-latex";
import { VFile } from "vfile";
import util from "util";
import { unifiedLatexToXmlLike } from "../libs/unified-latex-plugin-to-xml-like";
import { unifiedLatexToPretextLike } from "../libs/unified-latex-plugin-to-pretext-like";
import { htmlLike } from "@unified-latex/unified-latex-util-html-like";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";

Expand All @@ -18,7 +18,7 @@ describe("unified-latex-to-pretext:unified-latex-to-xml-like", () => {
let file: VFile;
const process = (value: string) =>
processLatexViaUnified()
.use(unifiedLatexToXmlLike, { producePretextFragment: true })
.use(unifiedLatexToPretextLike, { producePretextFragment: true })
.processSync({ value });

it("wrap pars and streaming commands", () => {
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("unified-latex-to-pretext:unified-latex-to-xml-like", () => {
it("can accept custom replacers", () => {
const process = (value: string) =>
processLatexViaUnified({ macros: { xxx: { signature: "m m" } } })
.use(unifiedLatexToXmlLike, {
.use(unifiedLatexToPretextLike, {
macroReplacements: {
xxx: (node) =>
htmlLike({
Expand Down

0 comments on commit c359495

Please sign in to comment.