]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix HTML in account/channel description
authorChocobozzz <me@florianbigard.com>
Mon, 14 Nov 2022 09:47:39 +0000 (10:47 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 14 Nov 2022 09:47:39 +0000 (10:47 +0100)
17 files changed:
client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
client/src/app/+accounts/accounts.component.ts
client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
client/src/app/+admin/overview/comments/video-comment-list.component.ts
client/src/app/+video-channels/video-channels.component.ts
client/src/app/+videos/+video-watch/shared/comment/video-comment.component.ts
client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts
client/src/app/app.component.ts
client/src/app/core/plugins/plugin.service.ts
client/src/app/core/renderer/markdown.service.ts
client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts
client/src/app/shared/shared-custom-markup/custom-markup.service.ts
client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
client/src/app/shared/shared-forms/markdown-textarea.component.ts
client/src/app/shared/shared-instance/instance.service.ts
client/src/app/shared/shared-support-modal/support-modal.component.ts
client/src/app/shared/shared-video-playlist/video-playlist-miniature.component.ts

index 457a432fe3da85ec155805425356a0d8b361b488..59814a93d4aca2160486188ea26a96b6d2e97bcb 100644 (file)
@@ -105,7 +105,11 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
         })
       )
       .subscribe(async ({ videoChannel, videos, total }) => {
-        this.channelsDescriptionHTML[videoChannel.id] = await this.markdown.textMarkdownToHTML(videoChannel.description)
+        this.channelsDescriptionHTML[videoChannel.id] = await this.markdown.textMarkdownToHTML({
+          markdown: videoChannel.description,
+          withEmoji: true,
+          withHtml: true
+        })
 
         this.videoChannels.push(videoChannel)
 
index cf66b817a64ab8a3316a47d515488f1994b3a103..0033fbf59f37c71bbf2fc563fcbb5f03384fd458 100644 (file)
@@ -142,7 +142,11 @@ export class AccountsComponent implements OnInit, OnDestroy {
   }
 
   private async onAccount (account: Account) {
-    this.accountDescriptionHTML = await this.markdown.textMarkdownToHTML(account.description)
+    this.accountDescriptionHTML = await this.markdown.textMarkdownToHTML({
+      markdown: account.description,
+      withEmoji: true,
+      withHtml: true
+    })
 
     // After the markdown renderer to avoid layout changes
     this.account = account
index 911d2418e24195fa51fafa043378dbd7e434defe..efd99e52bc0f68de4e0716ad48a824e367309c31 100644 (file)
@@ -127,7 +127,7 @@ export class VideoBlockListComponent extends RestTable implements OnInit {
   }
 
   toHtml (text: string) {
-    return this.markdownRenderer.textMarkdownToHTML(text)
+    return this.markdownRenderer.textMarkdownToHTML({ markdown: text })
   }
 
   async unblockVideo (entry: VideoBlacklist) {
index cfe40b92a36da822b728718992ec3e9143c51b43..c95d2ffeb12e2b932678782b90b87d7c12b0ee36 100644 (file)
@@ -115,7 +115,7 @@ export class VideoCommentListComponent extends RestTable implements OnInit {
   }
 
   toHtml (text: string) {
-    return this.markdownRenderer.textMarkdownToHTML(text, true, true)
+    return this.markdownRenderer.textMarkdownToHTML({ markdown: text, withHtml: true, withEmoji: true })
   }
 
   isInSelectionMode () {
index c5bcdffe2a9ec0b968f9b3871fb71772046074cc..afbf960325fa6a5a83556c3dd694b9f05c4af49d 100644 (file)
@@ -56,8 +56,17 @@ export class VideoChannelsComponent implements OnInit, OnDestroy {
                           ]))
                         )
                         .subscribe(async videoChannel => {
-                          this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.description)
-                          this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.ownerAccount.description)
+                          this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML({
+                            markdown: videoChannel.description,
+                            withEmoji: true,
+                            withHtml: true
+                          })
+
+                          this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML({
+                            markdown: videoChannel.ownerAccount.description,
+                            withEmoji: true,
+                            withHtml: true
+                          })
 
                           // After the markdown renderer to avoid layout changes
                           this.videoChannel = videoChannel
index cabea7551da6246a0fe83ceb624e20555c598a8f..191ec4a286e12378deb3a8804845ffddc5653d72 100644 (file)
@@ -160,7 +160,7 @@ export class VideoCommentComponent implements OnInit, OnChanges {
   private async init () {
     // Before HTML rendering restore line feed for markdown list compatibility
     const commentText = this.comment.text.replace(/<br.?\/?>/g, '\r\n')
-    const html = await this.markdownService.textMarkdownToHTML(commentText, true, true)
+    const html = await this.markdownService.textMarkdownToHTML({ markdown: commentText, withHtml: true, withEmoji: true })
     this.sanitizedCommentHTML = this.markdownService.processVideoTimestamps(this.video.shortUUID, html)
     this.newParentComments = this.parentComments.concat([ this.comment ])
 
index b5444facb6003e654c2a8808c5c0b8e5ce849234..72b09a274b16b06fe33f94451a4c6279e823daff 100644 (file)
@@ -80,7 +80,7 @@ export class VideoDescriptionComponent implements OnChanges {
   }
 
   private async setVideoDescriptionHTML () {
-    const html = await this.markdownService.textMarkdownToHTML(this.video.description)
+    const html = await this.markdownService.textMarkdownToHTML({ markdown: this.video.description })
 
     this.videoHTMLDescription = this.markdownService.processVideoTimestamps(this.video.shortUUID, html)
   }
index f2488aa59d98ff1881fb34fdffd0896444c9d5f1..e621ce432d4a8dcbb95ce80fabefca4fdd4d13a1 100644 (file)
@@ -206,7 +206,7 @@ export class AppComponent implements OnInit, AfterViewInit {
       }
 
       this.broadcastMessage = {
-        message: await this.markdownService.unsafeMarkdownToHTML(messageConfig.message, true),
+        message: await this.markdownService.markdownToUnsafeHTML({ markdown: messageConfig.message }),
         dismissable: messageConfig.dismissable,
         class: classes[messageConfig.level]
       }
index 1e79cbf79b6cbde46158b9118b71efed73aecef4..bd8c61d9aa5135b0e38dfd3d646ebe0c728eeb5a 100644 (file)
@@ -259,11 +259,11 @@ export class PluginService implements ClientHook {
 
       markdownRenderer: {
         textMarkdownToHTML: (textMarkdown: string) => {
-          return this.markdownRenderer.textMarkdownToHTML(textMarkdown)
+          return this.markdownRenderer.textMarkdownToHTML({ markdown: textMarkdown })
         },
 
         enhancedMarkdownToHTML: (enhancedMarkdown: string) => {
-          return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown)
+          return this.markdownRenderer.enhancedMarkdownToHTML({ markdown: enhancedMarkdown })
         }
       },
 
index 42e8c4a8814f1d5189ebd5b0f5ad10fb0d7a7bb8..a5fd7286294bad2c721d5365ece57423b250d8cf 100644 (file)
@@ -62,23 +62,40 @@ export class MarkdownService {
 
   constructor (private htmlRenderer: HtmlRendererService) {}
 
-  textMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
+  textMarkdownToHTML (options: {
+    markdown: string
+    withHtml?: boolean
+    withEmoji?: boolean
+  }) {
+    const { markdown, withHtml = false, withEmoji = false } = options
+
     if (withHtml) return this.render({ name: 'textWithHTMLMarkdownIt', markdown, withEmoji })
 
     return this.render({ name: 'textMarkdownIt', markdown, withEmoji })
   }
 
-  enhancedMarkdownToHTML (markdown: string, withHtml = false, withEmoji = false) {
+  enhancedMarkdownToHTML (options: {
+    markdown: string
+    withHtml?: boolean
+    withEmoji?: boolean
+  }) {
+    const { markdown, withHtml = false, withEmoji = false } = options
+
     if (withHtml) return this.render({ name: 'enhancedWithHTMLMarkdownIt', markdown, withEmoji })
 
     return this.render({ name: 'enhancedMarkdownIt', markdown, withEmoji })
   }
 
-  unsafeMarkdownToHTML (markdown: string, _trustedInput: true) {
-    return this.render({ name: 'unsafeMarkdownIt', markdown, withEmoji: true })
+  markdownToUnsafeHTML (options: { markdown: string }) {
+    return this.render({ name: 'unsafeMarkdownIt', markdown: options.markdown, withEmoji: true })
   }
 
-  customPageMarkdownToHTML (markdown: string, additionalAllowedTags: string[]) {
+  customPageMarkdownToHTML (options: {
+    markdown: string
+    additionalAllowedTags: string[]
+  }) {
+    const { markdown, additionalAllowedTags } = options
+
     return this.render({ name: 'customPageMarkdownIt', markdown, withEmoji: true, additionalAllowedTags })
   }
 
index a3a71ae2056bdf05caf5e9233870f2739a3a5e16..569a37b1753deb7f7d438d0abf909b94816ef8f0 100644 (file)
@@ -214,8 +214,8 @@ export class AbuseListTableComponent extends RestTable implements OnInit {
               abuse.truncatedCommentHtml = abuse.commentHtml = $localize`Deleted comment`
             } else {
               const truncated = truncate(abuse.comment.text, { length: 100 })
-              abuse.truncatedCommentHtml = await this.markdownRenderer.textMarkdownToHTML(truncated, true)
-              abuse.commentHtml = await this.markdownRenderer.textMarkdownToHTML(abuse.comment.text, true)
+              abuse.truncatedCommentHtml = await this.markdownRenderer.textMarkdownToHTML({ markdown: truncated, withHtml: true })
+              abuse.commentHtml = await this.markdownRenderer.textMarkdownToHTML({ markdown: abuse.comment.text, withHtml: true })
             }
           }
 
@@ -451,6 +451,6 @@ export class AbuseListTableComponent extends RestTable implements OnInit {
   }
 
   private toHtml (text: string) {
-    return this.markdownRenderer.textMarkdownToHTML(text)
+    return this.markdownRenderer.textMarkdownToHTML({ markdown: text })
   }
 }
index d738a644ec0f90498271eb62b2f2cdd6736e20e4..618c3dd4fbd5ae325d8a8fb6132537ea833766a9 100644 (file)
@@ -58,7 +58,7 @@ export class CustomMarkupService {
   }
 
   async buildElement (text: string) {
-    const html = await this.markdown.customPageMarkdownToHTML(text, this.getSupportedTags())
+    const html = await this.markdown.customPageMarkdownToHTML({ markdown: text, additionalAllowedTags: this.getSupportedTags() })
 
     const rootElement = document.createElement('div')
     rootElement.innerHTML = html
index e9c466a904bd641e4682aeff5fe47efe4d865683..ba12b713945da2d804d5f430b7c44abc6414119b 100644 (file)
@@ -42,7 +42,11 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
         tap(channel => {
           this.channel = channel
         }),
-        switchMap(() => from(this.markdown.textMarkdownToHTML(this.channel.description))),
+        switchMap(() => from(this.markdown.textMarkdownToHTML({
+          markdown: this.channel.description,
+          withEmoji: true,
+          withHtml: true
+        }))),
         tap(html => {
           this.descriptionHTML = html
         }),
index 0899918848b59a20a735c8a2d042ecd9fd30448b..e3371f22c7592b594f58f9e7551758020fe8a12d 100644 (file)
@@ -144,9 +144,9 @@ export class MarkdownTextareaComponent implements ControlValueAccessor, OnInit {
 
       html = result
     } else if (this.markdownType === 'text') {
-      html = await this.markdownService.textMarkdownToHTML(text)
+      html = await this.markdownService.textMarkdownToHTML({ markdown: text })
     } else {
-      html = await this.markdownService.enhancedMarkdownToHTML(text)
+      html = await this.markdownService.enhancedMarkdownToHTML({ markdown: text })
     }
 
     if (this.markdownVideo) {
index 0241f56eff208a5ee4744cf5d84c342d5715b6a2..89f47db240cbc05a333bae3be50dfaac8879ded0 100644 (file)
@@ -51,7 +51,7 @@ export class InstanceService {
     }
 
     for (const key of Object.keys(html)) {
-      html[key] = await this.markdownService.textMarkdownToHTML(about.instance[key])
+      html[key] = await this.markdownService.textMarkdownToHTML({ markdown: about.instance[key] })
     }
 
     return html
index 08e997f7bfeb9b52cc5972069e941bfa9d124b11..f330228e130c319c87af071e80f33e6d734c0a64 100644 (file)
@@ -27,7 +27,7 @@ export class SupportModalComponent {
 
     const support = this.video?.support || this.videoChannel.support
 
-    this.markdownService.enhancedMarkdownToHTML(support)
+    this.markdownService.enhancedMarkdownToHTML({ markdown: support })
       .then(r => {
         this.htmlSupport = r
       })
index dd9fe0a5aae9a02b319b20e7fa9aa553147c9177..225c4eb644d2fcf7790314b86b7a5797cfa74e9f 100644 (file)
@@ -32,7 +32,7 @@ export class VideoPlaylistMiniatureComponent implements OnInit {
   async ngOnInit () {
     this.buildPlaylistUrl()
     if (this.displayDescription) {
-      this.playlistDescription = await this.markdownService.textMarkdownToHTML(this.playlist.description)
+      this.playlistDescription = await this.markdownService.textMarkdownToHTML({ markdown: this.playlist.description })
     }
   }