mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
[DURACOM-240] Improve markdown pipe in order to check for empty values
This commit is contained in:
@@ -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) {
|
||||
expect(
|
||||
await markdownPipe.transform(input),
|
||||
|
@@ -11,6 +11,7 @@ import {
|
||||
} from '@angular/platform-browser';
|
||||
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { isEmpty } from '../empty.util';
|
||||
|
||||
const markdownItLoader = async () => (await import('markdown-it')).default;
|
||||
type LazyMarkdownIt = ReturnType<typeof markdownItLoader>;
|
||||
@@ -60,8 +61,8 @@ export class MarkdownPipe implements PipeTransform {
|
||||
) {
|
||||
}
|
||||
|
||||
async transform(value: string): Promise<SafeHtml> {
|
||||
if (!environment.markdown.enabled) {
|
||||
async transform(value: string, forcePreview = false): Promise<SafeHtml> {
|
||||
if (isEmpty(value) || (!environment.markdown.enabled && !forcePreview)) {
|
||||
return value;
|
||||
}
|
||||
const MarkdownIt = await this.markdownIt;
|
||||
|
Reference in New Issue
Block a user