From 0809260a32c6c6affff10ca4b39e0e29f66b84ab Mon Sep 17 00:00:00 2001 From: Nahlee Naria Khan <95993773+renee-k@users.noreply.github.com> Date: Tue, 9 Jul 2024 19:40:21 -0400 Subject: [PATCH] added another tabular test --- .../libs/unified-latex-plugin-to-xml-like.ts | 11 +- .../tests/unified-latex-to-pretext.test.ts | 131 +++++++++++++++++- 2 files changed, 132 insertions(+), 10 deletions(-) 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-xml-like.ts index 98143fc8..db03e1da 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-xml-like.ts @@ -64,11 +64,10 @@ export const unifiedLatexToXmlLike: Plugin< _environmentReplacements, options?.environmentReplacements || {} ); - const producePretextFragment = Object.assign( - {}, - false, - options?.producePretextFragment || {} - ); + const producePretextFragment = options?.producePretextFragment + ? options?.producePretextFragment + : false; + const isReplaceableMacro = match.createMacroMatcher(macroReplacements); const isReplaceableEnvironment = match.createEnvironmentMatcher( environmentReplacements @@ -136,8 +135,6 @@ export const unifiedLatexToXmlLike: Plugin< ); } }); - - // if (!options.producePretextFragment) { if (!producePretextFragment) { // Wrap in enough tags to ensure a valid pretext document // ... diff --git a/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts b/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts index 0617af2e..8ab05609 100644 --- a/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts +++ b/packages/unified-latex-to-pretext/tests/unified-latex-to-pretext.test.ts @@ -117,7 +117,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { html = process(`a\\href{foo.com}{FOO}b`); expect(normalizeHtml(html)).toEqual( // normalizeHtml(`aFOOb`) - normalizeHtml(`ab`) // ? check diff with href in pretext + normalizeHtml(`aFoob`) ); }); @@ -126,7 +126,8 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { expect(normalizeHtml(html)).toEqual( normalizeHtml( // don't need

tag for first two test cases - `

  1. a

  2. b

` // correct, without class + // `
  1. a

  2. b

` + `
  1. a

  2. b

` ) ); @@ -136,7 +137,8 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); expect(normalizeHtml(html)).toEqual( normalizeHtml( - `
  1. a

  2. b

` // correct, without class + // `
  1. a

  2. b

` + `
  1. a

  2. b

` ) ); @@ -193,6 +195,7 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); }); + // make this more descriptive since adding another test it.skip("Converts tabular environment", () => { html = process(`\\begin{tabular}{l l}a & b\\\\c & d\\end{tabular}`); expect(normalizeHtml(html)).toEqual( @@ -227,6 +230,128 @@ describe("unified-latex-to-pretext:unified-latex-to-pretext", () => { ); }); + // add another tabular test here from PR + + it("Can wrap in

...

tags", () => { + html = process(`a\\par b`); + expect(normalizeHtml(html)).toEqual(normalizeHtml(`

a

b

`)); + + html = process(`a\n\n b`); + expect(normalizeHtml(html)).toEqual(normalizeHtml(`

a

b

`)); + + html = process(`a\n b\n\nc`); + expect(normalizeHtml(html)).toEqual( + normalizeHtml(`

a b

c

`) + ); + html = process(`a\\section{foo} b\n\nc`); + expect(normalizeHtml(html)).toEqual( + normalizeHtml(`

a

foo

b

c

`) + ); + html = process(`a\\section{foo} b\\section{bar}\n\nc`); + expect(normalizeHtml(html)).toEqual( + normalizeHtml( + `

a

foo

b

bar

c

` + ) + ); + html = process(`a\n \\emph{b}\n\nc`); + expect(normalizeHtml(html)).toEqual( + normalizeHtml(`

a b

c

`) + ); + html = process(`a\n b\\begin{foo}x\\end{foo}c\n\nd`); + expect(normalizeHtml(html)).toEqual( + normalizeHtml(`

a b

x

c

d

`) + ); + }); + + // output used inline instead + it.skip("Macros aren't replaced with html code in math mode", () => { + let ast; + + // Custom labels are handled + ast = process(`\\[a\\\\b\\]`); + expect(normalizeHtml(ast)).toEqual( + // normalizeHtml(`
a\\\\b
`) + normalizeHtml(`a\\\\b`) // needs to be wrapped by

+ ); + }); + + it("Ligatures that are nested inside of math mode are not replaced", () => { + let ast; + + // Custom labels are handled + ast = process(`$a\\text{\\#}b$`); + expect(normalizeHtml(ast)).toEqual( + normalizeHtml(`a\\text{\\#}b`) + ); + }); + + it.skip("Pars are broken at display math", () => { + let ast; + + ast = process(`x\n\ny\\[a\\\\b\\]z`); + expect(normalizeHtml(ast)).toEqual( + // normalizeHtml( + // `

x

y

a\\\\b

z

` + // ) + normalizeHtml(`

x

y

a\\\\b

z

`) + ); + }); + it.skip("Converts tabular environment with same column alignments", () => { + html = process(`\\begin{tabular}{l l}a & b\\\\c & d\\end{tabular}`); + expect(normalizeHtml(html)).toEqual( + // normalizeHtml( + // ` + // + // + // + // + // + // + // + // + // + // + //
ab
cd
` + // ) + + // centered tho + // left is default alignment so don't need col here + normalizeHtml( + ` + + a + b + + + c + d + + ` + ) + ); + }); + + it.skip("Converts tabular environment with different column alignments", () => { + html = process(`\\begin{tabular}{r l}a & b\\\\c & d\\end{tabular}`); + expect(normalizeHtml(html)).toEqual( + // note: even though only one col is right aligned, need all cols + normalizeHtml( + ` + + + + a + b + + + c + d + + ` + ) + ); + }); + it("Can wrap in

...

tags", () => { html = process(`a\\par b`); expect(normalizeHtml(html)).toEqual(normalizeHtml(`

a

b

`));