Skip to content

Commit 8800b1e

Browse files
committed
move configs, add extra documentation
1 parent 0824fff commit 8800b1e

11 files changed

Lines changed: 62 additions & 27 deletions

File tree

src/app/item-page/field-components/metadata-values/metadata-values.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ds-metadata-field-wrapper [label]="label | translate">
22
<ng-container *ngFor="let mdValue of mdValues; let last=last;">
3-
<ng-container *ngTemplateOutlet="(renderMarkdown ? markdown : simple); context: {value: mdValue.value, classes: 'dont-break-out preserve-line-breaks'}">
3+
<ng-container *ngTemplateOutlet="(env.markdown.enabled && this.enableMarkdown ? markdown : simple); context: {value: mdValue.value, classes: 'dont-break-out preserve-line-breaks'}">
44
</ng-container>
55
<span class="separator" *ngIf="!last" [innerHTML]="separator"></span>
66
</ng-container>

src/app/item-page/field-components/metadata-values/metadata-values.component.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';
1+
import { Component, Input } from '@angular/core';
22
import { MetadataValue } from '../../../core/shared/metadata.models';
33
import { environment } from '../../../../environments/environment';
44

@@ -11,7 +11,7 @@ import { environment } from '../../../../environments/environment';
1111
styleUrls: ['./metadata-values.component.scss'],
1212
templateUrl: './metadata-values.component.html'
1313
})
14-
export class MetadataValuesComponent implements OnChanges {
14+
export class MetadataValuesComponent {
1515

1616
/**
1717
* The metadata values to display
@@ -29,17 +29,11 @@ export class MetadataValuesComponent implements OnChanges {
2929
@Input() label: string;
3030

3131
/**
32-
* Whether this metadata should be rendered with markdown.
32+
* Whether the {@link MarkdownPipe} should be used to render these metadata values.
33+
* This will only have effect if {@link MarkdownConfig#enabled} is true.
34+
* Mathjax will only be rendered if {@link MarkdownConfig#mathjax} is true.
3335
*/
3436
@Input() enableMarkdown = false;
3537

36-
/**
37-
* This variable will be true if this metadata should be rendered with markdown, and if markdown is enabled in the
38-
* environment config.
39-
*/
40-
renderMarkdown = false;
41-
42-
ngOnChanges(changes: SimpleChanges): void {
43-
this.renderMarkdown = !!environment.enableMarkdown && this.enableMarkdown;
44-
}
38+
env = environment;
4539
}

src/app/item-page/simple/field-components/specific-field/abstract/item-page-abstract-field.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@ export class ItemPageAbstractFieldComponent extends ItemPageFieldComponent {
3636
*/
3737
label = 'item.page.abstract';
3838

39+
/**
40+
* Use the {@link MarkdownPipe} to render dc.description.abstract values
41+
*/
3942
enableMarkdown = true;
4043
}

src/app/item-page/simple/field-components/specific-field/item-page-field.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('ItemPageFieldComponent', () => {
5757
describe('when markdown is disabled in the environment config', () => {
5858

5959
beforeEach(() => {
60-
environment.enableMarkdown = false;
60+
environment.markdown.enabled = false;
6161
});
6262

6363
describe('and markdown is disabled in this component', () => {
@@ -88,7 +88,7 @@ describe('ItemPageFieldComponent', () => {
8888
describe('when markdown is enabled in the environment config', () => {
8989

9090
beforeEach(() => {
91-
environment.enableMarkdown = true;
91+
environment.markdown.enabled = true;
9292
});
9393

9494
describe('and markdown is disabled in this component', () => {

src/app/item-page/simple/field-components/specific-field/item-page-field.component.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component, Input } from '@angular/core';
2-
32
import { Item } from '../../../../core/shared/item.model';
43

54
/**
@@ -19,7 +18,7 @@ export class ItemPageFieldComponent {
1918
@Input() item: Item;
2019

2120
/**
22-
* Whether this metadata should be rendered with markdown.
21+
* Whether the {@link MarkdownPipe} should be used to render this metadata.
2322
*/
2423
enableMarkdown = false;
2524

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ describe('Markdown Pipe', () => {
1414
{
1515
provide: APP_CONFIG,
1616
useValue: Object.assign(environment, {
17-
enableMarkdown: true,
18-
enableMathjax: true,
17+
markdown: {
18+
enabled: true,
19+
mathjax: true,
20+
}
1921
})
2022
},
2123
],

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ const MATHJAX = new InjectionToken<Mathjax>(
1313

1414
/**
1515
* Pipe for rendering markdown and mathjax.
16+
* - markdown will only be rendered if {@link MarkdownConfig#enabled} is true
17+
* - mathjax will only be rendered if both {@link MarkdownConfig#enabled} and {@link MarkdownConfig#mathjax} are true
18+
*
19+
* This pipe should be used on the 'innerHTML' attribute of a component, in combination with an async pipe.
20+
* Example usage:
21+
* <span class="example" [innerHTML]="'# title' | dsMarkdown | async"></span>
22+
* Result:
23+
* <span class="example">
24+
* <h1>title</h1>
25+
* </span>
1626
*/
1727
@Pipe({
1828
name: 'dsMarkdown'
@@ -26,11 +36,14 @@ export class MarkdownPipe implements PipeTransform {
2636
}
2737

2838
async transform(value: string): Promise<SafeHtml> {
39+
if (!environment.markdown.enabled) {
40+
return value;
41+
}
2942
const md = new MarkdownIt({
3043
html: true,
3144
linkify: true,
3245
});
33-
if (environment.enableMathjax) {
46+
if (environment.markdown.mathjax) {
3447
md.use(await this.mathjax);
3548
}
3649
return this.sanitizer.bypassSecurityTrustHtml(

src/config/app-config.interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ActuatorsConfig } from './actuators.config';
1919
import { InfoConfig } from './info-config.interface';
2020
import { CommunityListConfig } from './community-list-config.interface';
2121
import { HomeConfig } from './homepage-config.interface';
22+
import { MarkdownConfig } from './markdown-config.interface';
2223

2324
interface AppConfig extends Config {
2425
ui: UIServerConfig;
@@ -42,8 +43,7 @@ interface AppConfig extends Config {
4243
bundle: BundleConfig;
4344
actuators: ActuatorsConfig
4445
info: InfoConfig;
45-
enableMarkdown: boolean;
46-
enableMathjax: boolean;
46+
markdown: MarkdownConfig;
4747
}
4848

4949
/**

src/config/default-app-config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ export class DefaultAppConfig implements AppConfig {
365365
enablePrivacyStatement: true
366366
};
367367

368-
enableMarkdown = false;
369-
370-
enableMathjax = false;
368+
markdown: {
369+
enabled: false,
370+
mathjax: false,
371+
};
371372
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Config } from './config.interface';
2+
3+
/**
4+
* Config related to the {@link MarkdownPipe}.
5+
*/
6+
export interface MarkdownConfig extends Config {
7+
8+
/**
9+
* Enable Markdown (https://commonmark.org/) syntax for values passed to the {@link MarkdownPipe}.
10+
* - If this is true, values passed to the MarkdownPipe will be transformed to html according to the markdown syntax
11+
* rules.
12+
* - If this is false, using the MarkdownPipe will have no effect.
13+
*/
14+
enabled: boolean;
15+
16+
/**
17+
* Enable MathJax (https://www.mathjax.org/) syntax for values passed to the {@link MarkdownPipe}.
18+
* Requires {@link enabled} to also be true before MathJax will display.
19+
*/
20+
mathjax: boolean;
21+
}

0 commit comments

Comments
 (0)