-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtemplate.component.ts
118 lines (106 loc) · 3.27 KB
/
template.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { MarkdownService } from 'ngx-markdown';
import { EditorInstance, EditorLocale, EditorOption } from '../../lib/angular-markdown-editor';
@Component({
templateUrl: './template.component.html',
encapsulation: ViewEncapsulation.None,
styleUrls: ['./template.component.scss']
})
export class TemplateComponent implements OnInit {
bsEditorInstance!: EditorInstance;
markdownText = '';
showEditor = true;
templateForm!: FormGroup;
editorOptions!: EditorOption;
locale: EditorLocale = {
language: 'fr',
dictionary: {
'Bold': 'Gras',
'Italic': 'Italique',
'Heading': 'Titre',
'URL/Link': 'Insérer un lien HTTP',
'Image': 'Insérer une image',
'List': 'Liste à puces',
'Ordered List': 'Liste ordonnée',
'Unordered List': 'Liste non-ordonnée',
'Code': 'Code',
'Quote': 'Citation',
'Preview': 'Prévisualiser',
'Strikethrough': 'Caractères barrés',
'Table': 'Table',
'strong text': 'texte important',
'emphasized text': 'texte souligné',
'heading text': 'texte d\'entête',
'enter link description here': 'entrez la description du lien ici',
'Insert Hyperlink': 'Insérez le lien hypertexte',
'enter image description here': 'entrez la description de l\'image ici',
'Insert Image Hyperlink': 'Insérez le lien hypertexte de l\'image',
'enter image title here': 'entrez le titre de l\'image ici',
'list text here': 'texte à puce ici'
}
};
constructor(
private fb: FormBuilder,
private markdownService: MarkdownService
) { }
ngOnInit() {
this.editorOptions = {
autofocus: false,
iconlibrary: 'fa',
savable: false,
onShow: (e) => this.bsEditorInstance = e,
parser: (val) => this.parse(val)
};
// put the text completely on the left to avoid extra white spaces
this.markdownText =
`### Markdown example
---
This is an **example** where we bind a variable to the \`markdown\` component that is also bind to a textarea.
#### example.component.ts
\`\`\`javascript
function hello() {
alert('Hello World');
}
\`\`\`
#### example.component.css
\`\`\`css
.bold {
font-weight: bold;
}
\`\`\``;
this.buildForm(this.markdownText);
}
onChange(e: any) {
// for example show textarea new body content
// console.log(e.getContent());
}
buildForm(markdownText: string) {
this.templateForm = this.fb.group({
body: [markdownText],
isPreview: [true]
});
}
/** highlight all code found, needs to be wrapped in timer to work properly */
highlight() {
setTimeout(() => {
this.markdownService.highlight();
});
}
hidePreview() {
if (this.bsEditorInstance && this.bsEditorInstance.hidePreview) {
this.bsEditorInstance.hidePreview();
}
}
showFullScreen(isFullScreen: boolean) {
if (this.bsEditorInstance && this.bsEditorInstance.setFullscreen) {
this.bsEditorInstance.showPreview();
this.bsEditorInstance.setFullscreen(isFullScreen);
}
}
parse(inputValue: string) {
const markedOutput = this.markdownService.parse(inputValue.trim());
this.highlight();
return markedOutput;
}
}