]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - 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
04ed10b2 1import { Component, Input, OnChanges, OnInit } from '@angular/core'
621d99f5 2import { MarkdownService } from '@app/videos/shared'
0975cd5c 3import { I18n } from '@ngx-translate/i18n-polyfill'
8a8e02a4
C
4
5@Component({
6 selector: 'my-help',
7 styleUrls: [ './help.component.scss' ],
8 templateUrl: './help.component.html'
9})
10
5afdd0a5 11export class HelpComponent implements OnInit, OnChanges {
8a8e02a4
C
12 @Input() preHtml = ''
13 @Input() postHtml = ''
14 @Input() customHtml = ''
15 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
41f657c5 16 @Input() tooltipPlacement = 'right'
8a8e02a4
C
17
18 mainHtml = ''
19
0975cd5c
C
20 constructor (private i18n: I18n) { }
21
8a8e02a4 22 ngOnInit () {
5afdd0a5
C
23 this.init()
24 }
25
26 ngOnChanges () {
27 this.init()
28 }
29
5afdd0a5 30 private init () {
8a8e02a4
C
31 if (this.helpType === 'custom') {
32 this.mainHtml = this.customHtml
33 return
34 }
35
36 if (this.helpType === 'markdownText') {
621d99f5 37 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
8a8e02a4
C
38 return
39 }
40
41 if (this.helpType === 'markdownEnhanced') {
621d99f5 42 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
8a8e02a4
C
43 return
44 }
45 }
621d99f5 46
621d99f5 47 private formatMarkdownSupport (rules: string[]) {
0975cd5c
C
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:') +
621d99f5
C
50 this.createMarkdownList(rules)
51 }
52
53 private createMarkdownList (rules: string[]) {
54 const rulesToText = {
0975cd5c
C
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')
621d99f5
C
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 }
8a8e02a4 69}