]>
Commit | Line | Data |
---|---|---|
04ed10b2 | 1 | import { Component, Input, OnChanges, OnInit } from '@angular/core' |
621d99f5 | 2 | import { MarkdownService } from '@app/videos/shared' |
8a8e02a4 C |
3 | |
4 | @Component({ | |
5 | selector: 'my-help', | |
6 | styleUrls: [ './help.component.scss' ], | |
7 | templateUrl: './help.component.html' | |
8 | }) | |
9 | ||
5afdd0a5 | 10 | export class HelpComponent implements OnInit, OnChanges { |
8a8e02a4 C |
11 | @Input() preHtml = '' |
12 | @Input() postHtml = '' | |
13 | @Input() customHtml = '' | |
14 | @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom' | |
15 | ||
16 | mainHtml = '' | |
17 | ||
18 | ngOnInit () { | |
5afdd0a5 C |
19 | this.init() |
20 | } | |
21 | ||
22 | ngOnChanges () { | |
23 | this.init() | |
24 | } | |
25 | ||
5afdd0a5 | 26 | private init () { |
8a8e02a4 C |
27 | if (this.helpType === 'custom') { |
28 | this.mainHtml = this.customHtml | |
29 | return | |
30 | } | |
31 | ||
32 | if (this.helpType === 'markdownText') { | |
621d99f5 | 33 | this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES) |
8a8e02a4 C |
34 | return |
35 | } | |
36 | ||
37 | if (this.helpType === 'markdownEnhanced') { | |
621d99f5 | 38 | this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES) |
8a8e02a4 C |
39 | return |
40 | } | |
41 | } | |
621d99f5 | 42 | |
621d99f5 | 43 | private formatMarkdownSupport (rules: string[]) { |
632c5e36 C |
44 | return '<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> ' + |
45 | 'compatible that supports:' + | |
621d99f5 C |
46 | this.createMarkdownList(rules) |
47 | } | |
48 | ||
49 | private createMarkdownList (rules: string[]) { | |
50 | const rulesToText = { | |
51 | 'emphasis': 'Emphasis', | |
52 | 'link': 'Links', | |
53 | 'newline': 'New lines', | |
54 | 'list': 'Lists', | |
55 | 'image': 'Images' | |
56 | } | |
57 | ||
58 | const bullets = rules.map(r => rulesToText[r]) | |
59 | .filter(text => text) | |
60 | .map(text => '<li>' + text + '</li>') | |
61 | .join('') | |
62 | ||
63 | return '<ul>' + bullets + '</ul>' | |
64 | } | |
8a8e02a4 | 65 | } |