1 import { Component, Input, OnChanges, OnInit } from '@angular/core'
2 import { I18n } from '@ngx-translate/i18n-polyfill'
3 import { MarkdownService } from '@app/shared/renderer'
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'
18 isPopoverOpened = false
21 constructor (private i18n: I18n) { }
32 this.isPopoverOpened = false
36 this.isPopoverOpened = true
40 if (this.helpType === 'custom') {
41 this.mainHtml = this.customHtml
45 if (this.helpType === 'markdownText') {
46 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
50 if (this.helpType === 'markdownEnhanced') {
51 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
56 private formatMarkdownSupport (rules: string[]) {
57 // tslint:disable:max-line-length
58 return this.i18n('<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:') +
59 this.createMarkdownList(rules)
62 private createMarkdownList (rules: string[]) {
64 'emphasis': this.i18n('Emphasis'),
65 'link': this.i18n('Links'),
66 'newline': this.i18n('New lines'),
67 'list': this.i18n('Lists'),
68 'image': this.i18n('Images')
71 const bullets = rules.map(r => rulesToText[r])
73 .map(text => '<li>' + text + '</li>')
76 return '<ul>' + bullets + '</ul>'