Skip to content

Commit ba5c05e

Browse files
author
Andrea Barbasso
committed
[UXP-114] refactor markdownPipe to markdownDirective
missing tests and splitting the service into a browser one and a server one
1 parent 00f565e commit ba5c05e

14 files changed

Lines changed: 101 additions & 274 deletions

src/app/core/shared/math.directive.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/app/core/shared/math.service.ts

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,9 @@ import { Observable, ReplaySubject, Subject } from 'rxjs';
33

44
interface MathJaxConfig {
55
source: string;
6-
integrity: string;
76
id: string;
87
}
98

10-
declare global {
11-
interface Window {
12-
MathJax: any;
13-
}
14-
}
15-
169
@Injectable({
1710
providedIn: 'root'
1811
})
@@ -34,12 +27,10 @@ export class MathService {
3427

3528
private mathJax: MathJaxConfig = {
3629
source: 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js',
37-
integrity: 'sha256-CnzfCXjFj1REmPHgWvm/OQv8gFaxwbLKUi41yCU7N2s=',
3830
id: 'MathJaxScript'
3931
};
4032
private mathJaxFallback: MathJaxConfig = {
4133
source: 'assets/mathjax/mml-chtml.js',
42-
integrity: 'sha256-CnzfCXjFj1REmPHgWvm/OQv8gFaxwbLKUi41yCU7N2s=',
4334
id: 'MathJaxBackupScript'
4435
};
4536

@@ -58,6 +49,7 @@ export class MathService {
5849

5950
private async registerMathJaxAsync(config: MathJaxConfig): Promise<any> {
6051
return new Promise<void>((resolve, reject) => {
52+
6153
const optionsScript: HTMLScriptElement = document.createElement('script');
6254
optionsScript.type = 'text/javascript';
6355
optionsScript.text = `MathJax = ${JSON.stringify(this.mathJaxOptions)};`;
@@ -79,11 +71,7 @@ export class MathService {
7971
return this.signal;
8072
}
8173

82-
render(element: HTMLElement, value: string) {
83-
// Take initial typesetting which MathJax performs into account
84-
// window.MathJax.startup.promise.then(() => {
85-
element.innerHTML = value;
86-
window.MathJax.typesetPromise([element]);
87-
// });
74+
render(element: HTMLElement) {
75+
(window as any).MathJax.typesetPromise([element]);
8876
}
8977
}

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
@@ -12,7 +12,7 @@
1212

1313
<!-- Render value as markdown -->
1414
<ng-template #markdown let-value="value">
15-
<span class="dont-break-out" [innerHTML]="value | dsMarkdown | async">
15+
<span class="dont-break-out" [dsMarkdown]="value">
1616
</span>
1717
</ng-template>
1818

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class MetadataValuesComponent implements OnChanges {
3737
@Input() label: string;
3838

3939
/**
40-
* Whether the {@link MarkdownPipe} should be used to render these metadata values.
40+
* Whether the {@link MarkdownDirective} should be used to render these metadata values.
4141
* This will only have effect if {@link MarkdownConfig#enabled} is true.
4242
* Mathjax will only be rendered if {@link MarkdownConfig#mathjax} is true.
4343
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class ItemPageAbstractFieldComponent extends ItemPageFieldComponent {
3737
label = 'item.page.abstract';
3838

3939
/**
40-
* Use the {@link MarkdownPipe} to render dc.description.abstract values
40+
* Use the {@link MarkdownDirective} to render dc.description.abstract values
4141
*/
4242
enableMarkdown = true;
4343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class GenericItemPageFieldComponent extends ItemPageFieldComponent {
3636
@Input() label: string;
3737

3838
/**
39-
* Whether the {@link MarkdownPipe} should be used to render this metadata.
39+
* Whether the {@link MarkdownDirective} should be used to render this metadata.
4040
*/
4141
@Input() enableMarkdown = false;
4242

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ItemPageFieldComponent {
2626
@Input() item: Item;
2727

2828
/**
29-
* Whether the {@link MarkdownPipe} should be used to render this metadata.
29+
* Whether the {@link MarkdownDirective} should be used to render this metadata.
3030
*/
3131
enableMarkdown = false;
3232

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<span class="dont-break-out" [innerHTML]="value | dsMarkdown: true | async">
2-
</span>
3-
<span [dsMath]="value"></span>
1+
<span [dsMarkdown]="value"></span>

src/app/shared/shared.module.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,6 @@ import { SearchExportCsvComponent } from './search/search-export-csv/search-expo
300300
import {
301301
ItemPageTitleFieldComponent
302302
} from '../item-page/simple/field-components/specific-field/title/item-page-title-field.component';
303-
import { MarkdownPipe } from './utils/markdown.pipe';
304303
import { GoogleRecaptchaModule } from '../core/google-recaptcha/google-recaptcha.module';
305304
import { MenuModule } from './menu/menu.module';
306305
import {
@@ -352,7 +351,7 @@ import {
352351
import { ItemCollectionComponent } from './object-collection/shared/mydspace-item-collection/item-collection.component';
353352
import { ThemedItemListPreviewComponent } from './object-list/my-dspace-result-list-element/item-list-preview/themed-item-list-preview.component';
354353
import { ItemListPreviewComponent } from './object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component';
355-
import { MathDirective } from '../core/shared/math.directive';
354+
import { MarkdownDirective } from './utils/markdown.directive';
356355

357356
const MODULES = [
358357
CommonModule,
@@ -399,7 +398,6 @@ const PIPES = [
399398
ConsolePipe,
400399
ObjNgFor,
401400
BrowserOnlyPipe,
402-
MarkdownPipe,
403401
ShortNumberPipe
404402
];
405403

@@ -613,7 +611,7 @@ const DIRECTIVES = [
613611
HoverClassDirective,
614612
ContextHelpDirective,
615613
EntityIconDirective,
616-
MathDirective
614+
MarkdownDirective,
617615
];
618616

619617
@NgModule({
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { MarkdownDirective } from './markdown.directive';
2+
3+
describe('MarkdownDirective', () => {
4+
it('should create an instance', () => {
5+
const directive = new MarkdownDirective();
6+
expect(directive).toBeTruthy();
7+
});
8+
});

0 commit comments

Comments
 (0)