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:
Indented
Some text with white space between the content
NewLine
Some text with \t tab
NewLine
Tab at the end of the line is ignored
NewLine
White space at the end of the line is ignored
NewLine
${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: