diff --git a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/break-on-boundaries.ts b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/break-on-boundaries.ts index 6b8f4c25..5237e678 100644 --- a/packages/unified-latex-to-pretext/libs/pre-conversion-subs/break-on-boundaries.ts +++ b/packages/unified-latex-to-pretext/libs/pre-conversion-subs/break-on-boundaries.ts @@ -6,13 +6,13 @@ import { anyMacro, match, } from "@unified-latex/unified-latex-util-match"; -import { printRaw } from "@unified-latex/unified-latex-util-print-raw"; import { replaceNode } from "@unified-latex/unified-latex-util-replace"; import { splitOnMacro, unsplitOnMacro, } from "@unified-latex/unified-latex-util-split"; import { visit } from "@unified-latex/unified-latex-util-visit"; +import { VFileMessage } from "vfile-message"; /** * All the divisions, where each item is {division macro, mapped environment}. @@ -35,7 +35,6 @@ const isDivisionMacro = match.createMacroMatcher( // check if an environment is a newly created environment const isMappedEnviron = match.createEnvironmentMatcher( - // doesn't seem to work divisions.map((x) => x.mappedEnviron) ); @@ -43,9 +42,9 @@ const isMappedEnviron = match.createEnvironmentMatcher( * Breaks up division macros into environments. Returns a list of warning messages * for any groups that were removed. */ -export function breakOnBoundaries(ast: Ast.Ast): { messages: string[] } { +export function breakOnBoundaries(ast: Ast.Ast): { messages: VFileMessage[] } { // messages for any groups removed - const messagesLst: { messages: string[] } = { messages: [] }; + const messagesLst: { messages: VFileMessage[] } = { messages: [] }; replaceNode(ast, (node) => { if (match.group(node)) { @@ -55,11 +54,28 @@ export function breakOnBoundaries(ast: Ast.Ast): { messages: string[] } { return anyMacro(child) && isDivisionMacro(child); }) ) { - messagesLst.messages.push( - `Warning: hoisted out of a group, which might break the LaTeX code. { group: ${printRaw( - node - )} }` + const message = new VFileMessage( + "Warning: hoisted out of a group, which might break the LaTeX code.", + { + line: node.position?.start.line, + column: node.position?.start.column, + position: { + start: { line: node.position?.start.line, column: node.position?.start.column }, + end: { line: node.position?.end.line, column: node.position?.end.column } + }, + source: 'LatexConversion' + } ); + // line: null, + // column: null, + // position: { + // start: { line: null, column: null }, + // end: { line: null, column: null } + // }, + // source: null, + // ruleId: null + + messagesLst.messages.push(message); return node.content; } @@ -95,6 +111,8 @@ export function breakOnBoundaries(ast: Ast.Ast): { messages: string[] } { } }); + console.log(messagesLst.messages); + return messagesLst; } diff --git a/packages/unified-latex-to-pretext/tests/break-on-boundaries.test.ts b/packages/unified-latex-to-pretext/tests/break-on-boundaries.test.ts index 0a88394a..69a16ae9 100644 --- a/packages/unified-latex-to-pretext/tests/break-on-boundaries.test.ts +++ b/packages/unified-latex-to-pretext/tests/break-on-boundaries.test.ts @@ -66,7 +66,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ messages: [] }); + expect(breakOnBoundaries(ast).messages.length).toEqual(0); expect(printRaw(ast)).toEqual( String.raw`\begin{center}\begin{_part}[name]Hi, this is a part` + @@ -84,12 +84,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ - messages: [ - String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` + - String.raw`{ group: {\paragraph{Intro}Introduction.\begin{center}\subparagraph{Conclusion}Conclusion.\end{center}} }`, - ], - }); + expect(breakOnBoundaries(ast).messages.length).toEqual(1); expect(printRaw(ast)).toEqual( String.raw`\begin{document}\begin{_chapter}[Chap]\begin{_paragraph}[Intro]Introduction.` + @@ -106,14 +101,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ - messages: [ - String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` + - String.raw`{ group: {\subsection{Intro}description.\subsubsection{body}more text.{\subparagraph{Conclusion}Conclusion.}} }`, - String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` + - String.raw`{ group: {\subparagraph{Conclusion}Conclusion.} }`, - ], - }); + expect(breakOnBoundaries(ast).messages.length).toEqual(2); expect(printRaw(ast)).toEqual( String.raw`\begin{_part}[part1]\begin{_subsection}[Intro]description.` + @@ -130,14 +118,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ - messages: [ - String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` + - String.raw`{ group: {\subsection{Intro}\subsubsection{body}{$\mathbb{N}$\subparagraph{Conclusion}{no divisions 1}Conclusion.}} }`, - String.raw`Warning: hoisted out of a group, which might break the LaTeX code. ` + - String.raw`{ group: {$\mathbb{N}$\subparagraph{Conclusion}{no divisions 1}Conclusion.} }`, - ], - }); + expect(breakOnBoundaries(ast).messages.length).toEqual(2); expect(printRaw(ast)).toEqual( String.raw`\begin{_part}[part1]\begin{_subsection}[Intro]\begin{_subsubsection}[body]` + @@ -152,7 +133,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ messages: [] }); + expect(breakOnBoundaries(ast).messages.length).toEqual(0); expect(printRaw(ast)).toEqual( String.raw`\begin{_chapter}[$x = \frac{1}{2}$]Chapter 1` + @@ -167,7 +148,7 @@ describe("unified-latex-to-pretext:break-on-boundaries", () => { const parser = getParser(); const ast = parser.parse(value); - expect(breakOnBoundaries(ast)).toEqual({ messages: [] }); + expect(breakOnBoundaries(ast).messages.length).toEqual(0); expect(printRaw(ast)).toEqual( String.raw`\begin{_subsubsection}[first]subsection 1 ` +