Skip to content

Commit 5f924fb

Browse files
author
Davide Negretti
committed
[DSC-745] Keep HTML and XML as plain text
1 parent 95db842 commit 5f924fb

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/longtext/longtext.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="{{field.styleValue}}">
33
<ds-truncatable [id]="truncableId">
44
<ds-truncatable-part [id]="truncableId" [minLines]="3">
5-
<div [innerHTML]="formatText(metadataValue.value)"></div>
5+
<div [innerHTML]="formatText(metadataValue.value)" data-test="formatted-text"></div>
66
</ds-truncatable-part>
77
</ds-truncatable>
88
</div>

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/longtext/longtext.component.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('LongtextComponent', () => {
1515
let fixture: ComponentFixture<LongtextComponent>;
1616

1717
const metadataValue = Object.assign(new MetadataValue(), {
18-
'value': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.',
18+
'value': '<b>Lorem Ipsum</b> is simply dummy text of the printing and typesetting industry.\nLorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.\nIt has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.\nIt was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.',
1919
'language': null,
2020
'authority': null,
2121
'confidence': -1,
@@ -75,9 +75,12 @@ describe('LongtextComponent', () => {
7575
});
7676

7777
it('check metadata rendering', (done) => {
78-
const spanValueFound = fixture.debugElement.queryAll(By.css('ds-truncatable-part'));
79-
expect(spanValueFound.length).toBe(1);
80-
expect(spanValueFound[0].nativeElement.textContent).toContain(metadataValue.value);
78+
const formattedText = fixture.debugElement.query(By.css('[data-test="formatted-text"]')).nativeElement.innerHTML;
79+
const breaklineCount = formattedText.match(/<br>/g)?.length;
80+
81+
expect(breaklineCount).toBe(3);
82+
expect(formattedText).toContain('&lt;b&gt;Lorem Ipsum&lt;/b&gt;');
83+
8184
done();
8285
});
8386

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/rendering-type-value.model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export abstract class RenderingTypeValueModelComponent extends RenderingTypeMode
3939
*/
4040
formatText(text: string): string {
4141
const newlineRegex = /\n/g;
42-
return text.replace('>', '&gt;').replace('<', '&lt;').replace(newlineRegex, '<br>');
42+
return text.replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(newlineRegex, '<br>');
4343
}
4444

4545
}

0 commit comments

Comments
 (0)