Skip to content

Commit

Permalink
Fixed bug with double-escaping in code-span.
Browse files Browse the repository at this point in the history
Updated tests
  • Loading branch information
Toliak committed Aug 4, 2023
1 parent c42b3d3 commit be4032d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
4 changes: 2 additions & 2 deletions printers/latex/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion printers/latex/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export function getLatexRotatedPicture(
\\section{\\uppercase{Приложение ${data.index}}}
\\sectionbutitiscentered{${data.title}}
\\begin{center}
\\includegraphics[height=13.8cm]{${data.filepath}}
\\end{center}
Expand Down
14 changes: 7 additions & 7 deletions printers/latex/src/string/escapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ export const defaultEscapes: LatexPrinterConfigurationEscapeData[] = [
inLink: true,
replacer: '\\$1',
},
{
chars: ['%', '_', '#', '&', '\\$'],
inText: true,
inCodeSpan: true,
inLink: true,
replacer: '\\$1{}',
},
{
chars: ['{', '}'],
inText: false,
inCodeSpan: true,
inLink: false,
replacer: '\\$1',
},
{
chars: ['%', '_', '#', '&', '\\$'],
inText: true,
inCodeSpan: true,
inLink: true,
replacer: '\\$1{}',
},
{
chars: ['~'],
inText: false,
Expand Down
27 changes: 16 additions & 11 deletions printers/latex/test/printer/__snapshots__/printer.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ See application А.
`;

exports[`CodeSpan Monospace 1`] = `
"CodeSpan \\\\texttt{text \\\\& text}.
"CodeSpan \\\\texttt{text \\\\&{} text}.
"
`;

exports[`CodeSpan Quote 1`] = `
"CodeSpan <<text \\\\& text>>.
"CodeSpan <<text \\\\&{} text>>.
"
`;
exports[`Escapes Default escapes 1`] = `
"\\\\section{\\\\uppercase{Header}}
https://testing.url/com?some=thing\\\\&wtf\\\\#xdxdxd
https://testing.url/com?some=thing\\\\&{}wtf\\\\#{}xdxdxd
The \\"{}definition\\"{} increased by 1\\\\% (more text more text).
The \\"{}definition\\"{} increased by 1\\\\%{} (more text more text).
"
`;
Expand Down Expand Up @@ -225,7 +225,12 @@ Code from reference 1 describes image from reference 2.
`;
exports[`complex latex CodeSpan dereplacement 1`] = `
"<<\\"{}sample \\\\& text\\"{}>>
"<<\\"{}sample \\\\&{} text\\"{}>>
"
`;
exports[`complex latex CodeSpan dereplacement underscore 1`] = `
"<<sample\\\\_{}text>>
"
`;
Expand Down Expand Up @@ -308,7 +313,7 @@ exports[`complex latex Text with escapes ("<" should be correct also) 1`] = `
`;
exports[`complex latex Text with percents 1`] = `
"Text with 10\\\\% number.
"Text with 10\\\\%{} number.
"
`;
Expand Down Expand Up @@ -690,7 +695,7 @@ exports[`simple md to latex docs printer Subheader + List + Code Span 1`] = `
\\\\hspace{2.5cm}-\\\\,700
\\\\hspace{1.25cm}2)\\\\,<<Code\\\\_span>>
\\\\hspace{1.25cm}2)\\\\,<<Code\\\\_{}span>>
\\\\hspace{0cm}в)\\\\,Z
"
Expand Down Expand Up @@ -733,17 +738,17 @@ exports[`simple md to latex docs printer bold and italic 1`] = `
`;
exports[`url variants Bold url 1`] = `
"\\\\textbf{https://example.com/index\\\\_page.html?asd=asdasd\\\\&gege=gegege\\\\#header}
"\\\\textbf{https://example.com/index\\\\_{}page.html?asd=asdasd\\\\&{}gege=gegege\\\\#{}header}
"
`;
exports[`url variants Default url 1`] = `
"https://example.com/index\\\\_page.html?asd=asdasd\\\\&gege=gegege\\\\#header
"https://example.com/index\\\\_{}page.html?asd=asdasd\\\\&{}gege=gegege\\\\#{}header
"
`;
exports[`url variants Italic url 1`] = `
"\\\\textit{https://example.com/index\\\\_page.html?asd=asdasd\\\\&gege=gegege\\\\#header}
"\\\\textit{https://example.com/index\\\\_{}page.html?asd=asdasd\\\\&{}gege=gegege\\\\#{}header}
"
`;
Expand All @@ -753,6 +758,6 @@ exports[`url variants No escape & code url 1`] = `
`;
exports[`url variants Underlined url 1`] = `
"\\\\underline{https://example.com/index\\\\_page.html?asd=asdasd\\\\&gege=gegege\\\\#header}
"\\\\underline{https://example.com/index\\\\_{}page.html?asd=asdasd\\\\&{}gege=gegege\\\\#{}header}
"
`;
7 changes: 7 additions & 0 deletions printers/latex/test/printer/printer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ Discriminant Analysis, is related to Jenks optimization method.
expect(result.result).toMatchSnapshot();
});

test('CodeSpan dereplacement underscore', () => {
const result = processingChain('`sample_text`');

expect(result.diagnostic).toHaveLength(0);
expect(result.result).toMatchSnapshot();
});

test('Inline latex math dereplacement', () => {
const result = processingChain(`
$\`a > b < c\`$
Expand Down

0 comments on commit be4032d

Please sign in to comment.