]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Handle markdown in account/video channel pages
authorChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 09:19:10 +0000 (11:19 +0200)
committerChocobozzz <me@florianbigard.com>
Mon, 18 Jun 2018 09:19:10 +0000 (11:19 +0200)
client/src/app/+accounts/account-about/account-about.component.html
client/src/app/+accounts/account-about/account-about.component.ts
client/src/app/+video-channels/video-channel-about/video-channel-about.component.html
client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts
client/src/app/videos/+video-watch/modal/video-support.component.ts
client/src/app/videos/+video-watch/video-watch.component.ts
client/src/app/videos/shared/markdown.service.ts

index b178f5cc867e798c4d2072da9f74f8a362d7b2d3..f857e5a52a8c9a1036d9864d75a8250168597ca9 100644 (file)
@@ -1,7 +1,7 @@
 <div *ngIf="account" class="row">
   <div class="block col-md-6 col-sm-12">
     <div i18n class="small-title">Description</div>
-    <div class="content">{{ getAccountDescription() }}</div>
+    <div class="content" [innerHtml]="getAccountDescription()"></div>
   </div>
 
   <div class="block col-md-6 col-sm-12">
index c0e79375468b766c48ac8598226d9cd56b3d7743..2acf67a59ae85909159fd0fb80e46afafea181c4 100644 (file)
@@ -4,6 +4,7 @@ import { Account } from '@app/shared/account/account.model'
 import { AccountService } from '@app/shared/account/account.service'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { Subscription } from 'rxjs'
+import { MarkdownService } from '@app/videos/shared'
 
 @Component({
   selector: 'my-account-about',
@@ -12,19 +13,24 @@ import { Subscription } from 'rxjs'
 })
 export class AccountAboutComponent implements OnInit, OnDestroy {
   account: Account
+  descriptionHTML = ''
 
   private accountSub: Subscription
 
   constructor (
     private route: ActivatedRoute,
     private i18n: I18n,
-    private accountService: AccountService
+    private accountService: AccountService,
+    private markdownService: MarkdownService
   ) { }
 
   ngOnInit () {
     // Parent get the account for us
     this.accountSub = this.accountService.accountLoaded
-      .subscribe(account => this.account = account)
+      .subscribe(account => {
+        this.account = account
+        this.descriptionHTML = this.markdownService.textMarkdownToHTML(this.account.description)
+      })
   }
 
   ngOnDestroy () {
@@ -32,7 +38,7 @@ export class AccountAboutComponent implements OnInit, OnDestroy {
   }
 
   getAccountDescription () {
-    if (this.account.description) return this.account.description
+    if (this.descriptionHTML) return this.descriptionHTML
 
     return this.i18n('No description')
   }
index b7125ff71c869abe45941add683d3fe8ab955b28..9655668d73a16af55a4bc270b6d7fdf642e50a21 100644 (file)
@@ -2,12 +2,12 @@
   <div class="description col-md-6 col-sm-12">
     <div class="block">
       <div i18n class="small-title">Description</div>
-      <div class="content">{{ getVideoChannelDescription() }}</div>
+      <div class="content" [innerHtml]="getVideoChannelDescription()"></div>
     </div>
 
-    <div class="block" *ngIf="videoChannel.support">
+    <div class="block" *ngIf="supportHTML">
       <div i18n class="small-title">Support this channel</div>
-      <div class="content">{{ videoChannel.support }}</div>
+      <div class="content" [innerHtml]="supportHTML"></div>
     </div>
   </div>
 
index dc0893962056fdd0023146ddce34a8e5e399a230..901c91de9560df9b1d3e162c454a7bce495cc6f1 100644 (file)
@@ -4,6 +4,7 @@ import { VideoChannelService } from '@app/shared/video-channel/video-channel.ser
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { Subscription } from 'rxjs'
+import { MarkdownService } from '@app/videos/shared'
 
 @Component({
   selector: 'my-video-channel-about',
@@ -12,19 +13,27 @@ import { Subscription } from 'rxjs'
 })
 export class VideoChannelAboutComponent implements OnInit, OnDestroy {
   videoChannel: VideoChannel
+  descriptionHTML = ''
+  supportHTML = ''
 
   private videoChannelSub: Subscription
 
   constructor (
     private route: ActivatedRoute,
     private i18n: I18n,
-    private videoChannelService: VideoChannelService
+    private videoChannelService: VideoChannelService,
+    private markdownService: MarkdownService
   ) { }
 
   ngOnInit () {
     // Parent get the video channel for us
     this.videoChannelSub = this.videoChannelService.videoChannelLoaded
-      .subscribe(videoChannel => this.videoChannel = videoChannel)
+      .subscribe(videoChannel => {
+        this.videoChannel = videoChannel
+
+        this.descriptionHTML = this.markdownService.textMarkdownToHTML(this.videoChannel.description)
+        this.supportHTML = this.markdownService.enhancedMarkdownToHTML(this.videoChannel.support)
+      })
   }
 
   ngOnDestroy () {
@@ -32,7 +41,7 @@ export class VideoChannelAboutComponent implements OnInit, OnDestroy {
   }
 
   getVideoChannelDescription () {
-    if (this.videoChannel.description) return this.videoChannel.description
+    if (this.descriptionHTML) return this.descriptionHTML
 
     return this.i18n('No description')
   }
index f805215b98ab9e22e6ff01f31520752ebed26d60..c515298a07d5fd32fdd302625ed42b20f93229c4 100644 (file)
@@ -23,11 +23,7 @@ export class VideoSupportComponent {
   show () {
     this.modal.show()
 
-    if (this.video.support) {
-      this.videoHTMLSupport = this.markdownService.enhancedMarkdownToHTML(this.video.support)
-    } else {
-      this.videoHTMLSupport = ''
-    }
+    this.videoHTMLSupport = this.markdownService.enhancedMarkdownToHTML(this.video.support)
   }
 
   hide () {
index 6f6bd4e5d55528b7048317846fd2de57bfd0b977..8adf97d480dfcd4bb5d993252e504623f35a9343 100644 (file)
@@ -290,11 +290,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
   }
 
   private setVideoDescriptionHTML () {
-    if (!this.video.description) {
-      this.videoHTMLDescription = ''
-      return
-    }
-
     this.videoHTMLDescription = this.markdownService.textMarkdownToHTML(this.video.description)
   }
 
index 68114008766903f2b4f5845625f88ad4630d5963..14eeba77750c85acc5aa0091240dd1ee75ad7420 100644 (file)
@@ -23,14 +23,16 @@ export class MarkdownService {
   }
 
   textMarkdownToHTML (markdown: string) {
-    const html = this.textMarkdownIt.render(markdown)
+    if (!markdown) return ''
 
+    const html = this.textMarkdownIt.render(markdown)
     return this.avoidTruncatedLinks(html)
   }
 
   enhancedMarkdownToHTML (markdown: string) {
-    const html = this.enhancedMarkdownIt.render(markdown)
+    if (!markdown) return ''
 
+    const html = this.enhancedMarkdownIt.render(markdown)
     return this.avoidTruncatedLinks(html)
   }