Skip to content

Commit 665b804

Browse files
[UXP-241] migrate to new markdown library
1 parent c407f9c commit 665b804

7 files changed

Lines changed: 36 additions & 34 deletions

File tree

angular.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@
6969
"inject": false,
7070
"bundleName": "dspace-theme"
7171
},
72-
"./node_modules/leaflet/dist/leaflet.css"
72+
"./node_modules/leaflet/dist/leaflet.css",
73+
"./node_modules/quill/dist/quill.core.css",
74+
"./node_modules/quill/dist/quill.snow.css",
75+
"./node_modules/quill/dist/quill.bubble.css",
7376
],
7477
"scripts": [],
7578
"baseHref": "/"

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
"@ng-bootstrap/ng-bootstrap": "^11.0.0",
9292
"@ng-dynamic-forms/core": "^15.0.0",
9393
"@ng-dynamic-forms/ui-ng-bootstrap": "^15.0.0",
94-
"@ng-util/markdown": "^12.1.2",
9594
"@ngrx/effects": "^15.4.0",
9695
"@ngrx/router-store": "^15.4.0",
9796
"@ngrx/store": "^15.4.0",
@@ -150,7 +149,9 @@
150149
"ngx-skeleton-loader": "^7.0.0",
151150
"nouislider": "^15.8.1",
152151
"pem": "1.14.8",
152+
"ngx-quill": "21.0.2",
153153
"prop-types": "^15.8.1",
154+
"quill": "1.3.7",
154155
"react-copy-to-clipboard": "^5.1.0",
155156
"reflect-metadata": "^0.2.2",
156157
"rxjs": "^7.8.0",

src/app/app.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ const IMPORTS = [
5757
FooterModule,
5858
HttpClientModule,
5959
AppRoutingModule,
60-
NuMarkdownModule.forRoot({}),
6160
CoreModule.forRoot(),
6261
ScrollToModule.forRoot(),
6362
NgbModule,
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
<nu-markdown [id]="controlId" [(ngModel)]="editValue" class="markdown-editor"
2-
(ngModelChange)="editValueChange.emit($event)" [options]="options">
3-
</nu-markdown>
1+
<quill-editor class="markdown-editor" [ngModel]="editValue" [modules]="modules" (onContentChanged)="updateContent($event)"></quill-editor>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
quill-editor {
2+
width: 100%;
3+
}
Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,45 @@
1-
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
2+
import { ContentChange, QuillModules } from 'ngx-quill';
23

34
@Component({
45
selector: 'ds-markdown-editor',
56
templateUrl: './markdown-editor.component.html',
67
styleUrls: ['./markdown-editor.component.scss']
78
})
8-
export class MarkdownEditorComponent implements OnInit {
9-
// to allow multiple textarea on the same screen, need to set an uniqueId for the textarea
10-
controlId: string;
9+
export class MarkdownEditorComponent {
1110
/**
1211
* Markdown Editor String value
1312
*/
14-
@Input() editValue: string;
13+
@Input() editValue = '';
1514
/**
1615
* Markdown Editor String value Emitter
1716
*/
1817
@Output() editValueChange = new EventEmitter();
18+
1919
/**
20-
* Nu markdown library options (default is chinese)
20+
* Quill modules config
2121
*/
22-
options = {
23-
minHeight: 200,
24-
lang: 'en_US',
25-
mode: 'ir',
26-
preview: {
27-
markdown: {
28-
codeBlockPreview: false,
29-
},
30-
actions: [
31-
'desktop', 'tablet', 'mobile'
32-
]
33-
},
22+
modules: QuillModules = {
3423
toolbar: [
35-
'emoji', 'headings', 'bold', 'italic', 'strike', 'link', '|',
36-
'list', 'ordered-list', 'check', 'outdent', 'indent', 'table', '|',
37-
'quote', 'line', 'code', 'inline-code', 'insert-before', 'insert-after', '|',
38-
'undo', 'redo', '|',
39-
'fullscreen', 'preview'
24+
['bold', 'italic', 'underline', 'strike'],
25+
[{ 'header': 1 }, { 'header': 2 }],
26+
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
27+
[{ 'indent': '-1'}, { 'indent': '+1' }],
28+
[{ 'direction': 'rtl' }],
29+
[{ 'size': ['small', false, 'large', 'huge'] }],
30+
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
31+
[{ 'font': [] }],
32+
[{ 'align': [] }],
33+
['clean'],
4034
],
35+
syntax: false
4136
};
4237

43-
ngOnInit(): void {
44-
this.controlId = `MarkdownEditor-${Math.floor(100000 * Math.random())}`;
38+
/**
39+
* Emit content update after editing
40+
* @param content
41+
*/
42+
updateContent(content: ContentChange) {
43+
this.editValueChange.emit(content.html);
4544
}
46-
4745
}

src/app/shared/markdown-editor/markdown-editor.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { MarkdownEditorComponent } from './markdown-editor.component';
44
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
5-
import { NuMarkdownModule } from '@ng-util/markdown';
5+
import { QuillModule } from 'ngx-quill';
66

77
@NgModule({
88
imports: [
99
CommonModule,
1010
FormsModule,
1111
ReactiveFormsModule,
12-
NuMarkdownModule
12+
QuillModule.forRoot()
1313
],
1414
exports: [ MarkdownEditorComponent ],
1515
declarations: [ MarkdownEditorComponent ],

0 commit comments

Comments
 (0)