Browse Source

Fix HTML in account/channel description

develop
Chocobozzz 1 week ago
parent
commit
0e45e336f6
No known key found for this signature in database GPG Key ID: 583A612D890159BE
17 changed files with 64 additions and 26 deletions
  1. +5
    -1
      client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
  2. +5
    -1
      client/src/app/+accounts/accounts.component.ts
  3. +1
    -1
      client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts
  4. +1
    -1
      client/src/app/+admin/overview/comments/video-comment-list.component.ts
  5. +11
    -2
      client/src/app/+video-channels/video-channels.component.ts
  6. +1
    -1
      client/src/app/+videos/+video-watch/shared/comment/video-comment.component.ts
  7. +1
    -1
      client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts
  8. +1
    -1
      client/src/app/app.component.ts
  9. +2
    -2
      client/src/app/core/plugins/plugin.service.ts
  10. +22
    -5
      client/src/app/core/renderer/markdown.service.ts
  11. +3
    -3
      client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts
  12. +1
    -1
      client/src/app/shared/shared-custom-markup/custom-markup.service.ts
  13. +5
    -1
      client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
  14. +2
    -2
      client/src/app/shared/shared-forms/markdown-textarea.component.ts
  15. +1
    -1
      client/src/app/shared/shared-instance/instance.service.ts
  16. +1
    -1
      client/src/app/shared/shared-support-modal/support-modal.component.ts
  17. +1
    -1
      client/src/app/shared/shared-video-playlist/video-playlist-miniature.component.ts

+ 5
- 1
client/src/app/+accounts/account-video-channels/account-video-channels.component.ts View 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)



+ 5
- 1
client/src/app/+accounts/accounts.component.ts View 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


+ 1
- 1
client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts View 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) {


+ 1
- 1
client/src/app/+admin/overview/comments/video-comment-list.component.ts View 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 () {


+ 11
- 2
client/src/app/+video-channels/video-channels.component.ts View 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


+ 1
- 1
client/src/app/+videos/+video-watch/shared/comment/video-comment.component.ts View 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 ])



+ 1
- 1
client/src/app/+videos/+video-watch/shared/metadata/video-description.component.ts View 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)
}


+ 1
- 1
client/src/app/app.component.ts View 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]
}


+ 2
- 2
client/src/app/core/plugins/plugin.service.ts View 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 })
}
},



+ 22
- 5
client/src/app/core/renderer/markdown.service.ts View 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 })
}



+ 3
- 3
client/src/app/shared/shared-abuse-list/abuse-list-table.component.ts View 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 })
}
}

+ 1
- 1
client/src/app/shared/shared-custom-markup/custom-markup.service.ts View 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


+ 5
- 1
client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts View 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
}),


+ 2
- 2
client/src/app/shared/shared-forms/markdown-textarea.component.ts View 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) {


+ 1
- 1
client/src/app/shared/shared-instance/instance.service.ts View 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


+ 1
- 1
client/src/app/shared/shared-support-modal/support-modal.component.ts View 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
})


+ 1
- 1
client/src/app/shared/shared-video-playlist/video-playlist-miniature.component.ts View 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 })
}
}



Loading…
Cancel
Save