mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +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) {
|
async function testTransform(input: string, output: string) {
|
||||||
expect(
|
expect(
|
||||||
await markdownPipe.transform(input),
|
await markdownPipe.transform(input),
|
||||||
|
@@ -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;
|
||||||
|
Reference in New Issue
Block a user