1 import { Component, Input, OnChanges, OnInit } from '@angular/core'
2 import { MarkdownService } from '@app/videos/shared'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
7 styleUrls: [ './help.component.scss' ],
8 templateUrl: './help.component.html'
11 export class HelpComponent implements OnInit, OnChanges {
13 @Input() postHtml = ''
14 @Input() customHtml = ''
15 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
16 @Input() tooltipPlacement = 'right'
20 constructor (private i18n: I18n) { }
31 if (this.helpType === 'custom') {
32 this.mainHtml = this.customHtml
36 if (this.helpType === 'markdownText') {
37 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
41 if (this.helpType === 'markdownEnhanced') {
42 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
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)
53 private createMarkdownList (rules: string[]) {
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')
62 const bullets = rules.map(r => rulesToText[r])
64 .map(text => '<li>' + text + '</li>')
67 return '<ul>' + bullets + '</ul>'