1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Desktop: Fixes #9264: Preserve indentation from plain text when pasting on Rich Text Editor (#9828)

This commit is contained in:
pedr 2024-03-02 12:43:38 -03:00 committed by GitHub
parent 53d5cf55bc
commit ff1f1b190e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 2 deletions

View File

@ -40,6 +40,30 @@ describe('htmlUtils', () => {
'<img onerror="http://downloadmalware.com"/>',
'&lt;img onerror=&quot;http://downloadmalware.com&quot;/&gt;',
],
[
'Some text indented by a tab:\n\tIndented',
'<p>Some text indented by a tab:<br/>&nbsp;&nbsp;&nbsp;&nbsp;Indented</p>',
],
[
'Some text indented by two spaces:\n Indented',
'<p>Some text indented by two spaces:<br/>&nbsp;&nbsp;Indented</p>',
],
[
'Some text with white space between the content\nNewLine',
'<p>Some text with white space between the content<br/>NewLine</p>',
],
[
'Some text with \t tab\nNewLine',
'<p>Some text with \t tab<br/>NewLine</p>',
],
[
'Tab at the end of the line is ignored\t\nNewLine',
'<p>Tab at the end of the line is ignored<br/>NewLine</p>',
],
[
'White space at the end of the line is ignored \nNewLine',
'<p>White space at the end of the line is ignored<br/>NewLine</p>',
],
];
for (const t of testCases) {

View File

@ -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(`<p>${currentLine}</p>`);

View File

@ -219,7 +219,9 @@ export function escapeHtml(s: string) {
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
.replace(/'/g, '&#039;')
.replace(/^ +/g, match => '&nbsp;'.repeat(match.length))
.replace(/^\t+/g, match => '&nbsp;&nbsp;&nbsp;&nbsp;'.repeat(match.length));
}
// keywords can either be a list of strings, or a list of objects with the format: