diff --git a/packages/lib/htmlUtils.test.ts b/packages/lib/htmlUtils.test.ts index 2de678d9a..cb9efde29 100644 --- a/packages/lib/htmlUtils.test.ts +++ b/packages/lib/htmlUtils.test.ts @@ -40,6 +40,30 @@ describe('htmlUtils', () => { '', '<img onerror="http://downloadmalware.com"/>', ], + [ + 'Some text indented by a tab:\n\tIndented', + '

Some text indented by a tab:
    Indented

', + ], + [ + 'Some text indented by two spaces:\n Indented', + '

Some text indented by two spaces:
  Indented

', + ], + [ + 'Some text with white space between the content\nNewLine', + '

Some text with white space between the content
NewLine

', + ], + [ + 'Some text with \t tab\nNewLine', + '

Some text with \t tab
NewLine

', + ], + [ + 'Tab at the end of the line is ignored\t\nNewLine', + '

Tab at the end of the line is ignored
NewLine

', + ], + [ + 'White space at the end of the line is ignored \nNewLine', + '

White space at the end of the line is ignored
NewLine

', + ], ]; for (const t of testCases) { diff --git a/packages/lib/htmlUtils.ts b/packages/lib/htmlUtils.ts index e367b3256..63f96eb7d 100644 --- a/packages/lib/htmlUtils.ts +++ b/packages/lib/htmlUtils.ts @@ -188,7 +188,7 @@ export function plainTextToHtml(plainText: string): string { let currentLine = ''; for (let line of lines) { - line = line.trim(); + line = line.trimEnd(); if (!line) { if (currentLine) { step1.push(`

${currentLine}

`); diff --git a/packages/lib/string-utils.ts b/packages/lib/string-utils.ts index 00837bc46..419d6c30d 100644 --- a/packages/lib/string-utils.ts +++ b/packages/lib/string-utils.ts @@ -219,7 +219,9 @@ export function escapeHtml(s: string) { .replace(//g, '>') .replace(/"/g, '"') - .replace(/'/g, '''); + .replace(/'/g, ''') + .replace(/^ +/g, match => ' '.repeat(match.length)) + .replace(/^\t+/g, match => '    '.repeat(match.length)); } // keywords can either be a list of strings, or a list of objects with the format: