]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/shared/misc/help.component.ts
adding CSP, no-referrer policies and allow dns prefetching
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / help.component.ts
... / ...
CommitLineData
1import { Component, Input, OnChanges, OnInit } from '@angular/core'
2import { MarkdownService } from '@app/videos/shared'
3import { I18n } from '@ngx-translate/i18n-polyfill'
4
5@Component({
6 selector: 'my-help',
7 styleUrls: [ './help.component.scss' ],
8 templateUrl: './help.component.html'
9})
10
11export class HelpComponent implements OnInit, OnChanges {
12 @Input() preHtml = ''
13 @Input() postHtml = ''
14 @Input() customHtml = ''
15 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
16 @Input() tooltipPlacement = 'right'
17
18 mainHtml = ''
19
20 constructor (private i18n: I18n) { }
21
22 ngOnInit () {
23 this.init()
24 }
25
26 ngOnChanges () {
27 this.init()
28 }
29
30 private init () {
31 if (this.helpType === 'custom') {
32 this.mainHtml = this.customHtml
33 return
34 }
35
36 if (this.helpType === 'markdownText') {
37 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
38 return
39 }
40
41 if (this.helpType === 'markdownEnhanced') {
42 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
43 return
44 }
45 }
46
47 private formatMarkdownSupport (rules: string[]) {
48 // tslint:disable:max-line-length
49 return this.i18n('<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:') +
50 this.createMarkdownList(rules)
51 }
52
53 private createMarkdownList (rules: string[]) {
54 const rulesToText = {
55 'emphasis': this.i18n('Emphasis'),
56 'link': this.i18n('Links'),
57 'newline': this.i18n('New lines'),
58 'list': this.i18n('Lists'),
59 'image': this.i18n('Images')
60 }
61
62 const bullets = rules.map(r => rulesToText[r])
63 .filter(text => text)
64 .map(text => '<li>' + text + '</li>')
65 .join('')
66
67 return '<ul>' + bullets + '</ul>'
68 }
69}