Merge "gr-formatted-text - pre block should stop on whitespace line"
diff --git a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
index 0193197..ddca5c5 100644
--- a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
+++ b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.ts
@@ -183,7 +183,9 @@
// include pre or all regular lines but stop at next new line
while (
this._isPreFormat(lines[nextI]) ||
- (this._isRegularLine(lines[nextI]) && lines[nextI].length)
+ (this._isRegularLine(lines[nextI]) &&
+ !this._isWhitespaceLine(lines[nextI]) &&
+ lines[nextI].length)
) {
nextI++;
}
@@ -255,13 +257,17 @@
}
_isPreFormat(line: string) {
- return line && /^[ \t]/.test(line);
+ return line && /^[ \t]/.test(line) && !this._isWhitespaceLine(line);
}
_isList(line: string) {
return line && /^[-*] /.test(line);
}
+ _isWhitespaceLine(line: string) {
+ return line && /^\s+$/.test(line);
+ }
+
_makeLinkedText(content = '', isPre?: boolean) {
const text = document.createElement('gr-linked-text');
text.config = this.config;
diff --git a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.js b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.js
index 3e05f11..8464af7 100644
--- a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.js
+++ b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text_test.js
@@ -297,6 +297,14 @@
assertBlock(result, 1, 'paragraph', 'B');
});
+ test('pre format 5', () => {
+ const comment = ' Q\n <R>\n S\n \nB';
+ const result = element._computeBlocks(comment);
+ assert.lengthOf(result, 2);
+ assertBlock(result, 0, 'pre', ' Q\n <R>\n S');
+ assertBlock(result, 1, 'paragraph', ' \nB');
+ });
+
test('quote 1', () => {
const comment = '> I\'m happy\n > with quotes!\n\nSee above.';
const result = element._computeBlocks(comment);