[DURACOM-240] Improve markdown pipe in order to check for empty values

This commit is contained in:
Giuseppe Digilio
2024-02-21 16:29:36 +01:00
parent 083a904043
commit 81b0d76f1b
2 changed files with 17 additions and 2 deletions

View File

@@ -55,6 +55,20 @@ describe('Markdown Pipe', () => {
); );
}); });
it('should render undefined value', async () => {
await testTransform(
undefined,
undefined,
);
});
it('should render null value', async () => {
await testTransform(
null,
null,
);
});
async function testTransform(input: string, output: string) { async function testTransform(input: string, output: string) {
expect( expect(
await markdownPipe.transform(input), await markdownPipe.transform(input),

View File

@@ -11,6 +11,7 @@ import {
} from '@angular/platform-browser'; } from '@angular/platform-browser';
import { environment } from '../../../environments/environment'; import { environment } from '../../../environments/environment';
import { isEmpty } from '../empty.util';
const markdownItLoader = async () => (await import('markdown-it')).default; const markdownItLoader = async () => (await import('markdown-it')).default;
type LazyMarkdownIt = ReturnType<typeof markdownItLoader>; type LazyMarkdownIt = ReturnType<typeof markdownItLoader>;
@@ -60,8 +61,8 @@ export class MarkdownPipe implements PipeTransform {
) { ) {
} }
async transform(value: string): Promise<SafeHtml> { async transform(value: string, forcePreview = false): Promise<SafeHtml> {
if (!environment.markdown.enabled) { if (isEmpty(value) || (!environment.markdown.enabled && !forcePreview)) {
return value; return value;
} }
const MarkdownIt = await this.markdownIt; const MarkdownIt = await this.markdownIt;