Skip to content

Commit da8d6b9

Browse files
committed
[UXP-114] Improve markdown pipe in order to check for empty values
1 parent c351edd commit da8d6b9

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/app/shared/utils/markdown.pipe.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ describe('Markdown Pipe', () => {
5454
);
5555
});
5656

57+
it('should render undefined value', async () => {
58+
await testTransform(
59+
undefined,
60+
undefined
61+
);
62+
});
63+
64+
it('should render null value', async () => {
65+
await testTransform(
66+
null,
67+
null
68+
);
69+
});
70+
5771
async function testTransform(input: string, output: string) {
5872
expect(
5973
await markdownPipe.transform(input)

src/app/shared/utils/markdown.pipe.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Inject, InjectionToken, Pipe, PipeTransform, SecurityContext } from '@angular/core';
22
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
3+
34
import { environment } from '../../../environments/environment';
5+
import { isEmpty } from '../empty.util';
46

57
const markdownItLoader = async () => (await import('markdown-it')).default;
68
type LazyMarkdownIt = ReturnType<typeof markdownItLoader>;
@@ -50,7 +52,7 @@ export class MarkdownPipe implements PipeTransform {
5052
}
5153

5254
async transform(value: string, forcePreview = false): Promise<SafeHtml> {
53-
if (!environment.markdown.enabled && !forcePreview) {
55+
if (isEmpty(value) || (!environment.markdown.enabled && !forcePreview)) {
5456
return value;
5557
}
5658
const MarkdownIt = await this.markdownIt;

0 commit comments

Comments
 (0)