From c359495e02f6a0468533dca045901aa7a40ad3dc Mon Sep 17 00:00:00 2001 From: Nahlee Naria Khan <95993773+renee-k@users.noreply.github.com> Date: Thu, 15 Aug 2024 15:36:32 -0400 Subject: [PATCH] fixed all new PR comments --- .../pre-conversion-subs/environment-subs.ts | 1 - .../libs/pre-conversion-subs/macro-subs.ts | 44 ++++++++----------- .../libs/pre-conversion-subs/utils.ts | 13 +++--- .../libs/pretext-subs/to-pretext.ts | 9 +++- ...> unified-latex-plugin-to-pretext-like.ts} | 2 +- .../libs/unified-latex-plugin-to-pretext.ts | 6 +-- .../tests/unified-latex-to-xml-like.test.ts | 6 +-- 7 files changed, 39 insertions(+), 42 deletions(-) rename packages/unified-latex-to-pretext/libs/{unified-latex-plugin-to-xml-like.ts => unified-latex-plugin-to-pretext-like.ts} (99%) diff --git a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts index 2d7ed9c..7f6ab9a 100644 --- a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts +++ b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/environment-subs.ts @@ -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) { diff --git a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/macro-subs.ts b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/macro-subs.ts index b36e0b3..93e37f1 100644 --- a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/macro-subs.ts +++ b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/macro-subs.ts @@ -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. @@ -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) => { @@ -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); diff --git a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/utils.ts b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/utils.ts index c8d30d2..5b958af 100644 --- a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/utils.ts +++ b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/utils.ts @@ -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; } @@ -23,9 +23,8 @@ 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 @@ -33,12 +32,12 @@ export function emptyStringWithWarning( const message = makeWarningMessage( node, warningMessage, - sourceFile + "macro-subs" ); file.message( message, message.position, - `unified-latex-to-pretext:${sourceFile}` + `unified-latex-to-pretext:macro-subs` ); } diff --git a/packages/unified-latex-to-pretext/libs/pretext-subs/to-pretext.ts b/packages/unified-latex-to-pretext/libs/pretext-subs/to-pretext.ts index fef0950..a76f553 100644 --- a/packages/unified-latex-to-pretext/libs/pretext-subs/to-pretext.ts +++ b/packages/unified-latex-to-pretext/libs/pretext-subs/to-pretext.ts @@ -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), diff --git a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-xml-like.ts b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext-like.ts similarity index 99% rename from packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-xml-like.ts rename to packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext-like.ts index f45361e..56d51e8 100644 --- a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-xml-like.ts +++ b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext-like.ts @@ -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
tags.
*/
-export const unifiedLatexToXmlLike: Plugin<
+export const unifiedLatexToPretextLike: Plugin<
PluginOptions[],
Ast.Root,
Hast.Root
diff --git a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts
index 134661c..63cba56 100644
--- a/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts
+++ b/packages/unified-latex-to-pretext/libs/unified-latex-plugin-to-pretext.ts
@@ -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 & {
@@ -58,7 +58,7 @@ export const unifiedLatexToPretext: Plugin<
// since we don't want to wrap content outside of \begin{document}...\end{document} with