1
0
Fork 0

Remove remote class from HTML

This commit is contained in:
Chocobozzz 2025-03-31 08:40:10 +02:00
parent b35127e172
commit dff2e95369
No known key found for this signature in database
GPG key ID: 583A612D890159BE
3 changed files with 18 additions and 13 deletions

View file

@ -97,17 +97,12 @@
.comment-html {
@include peertube-word-wrap;
// Mentions
::ng-deep a {
color: pvar(--fg);
&:not(.linkified-url) {
color: pvar(--fg);
font-weight: $font-semibold;
@include disable-default-a-behaviour;
}
font-weight: $font-semibold;
@include disable-default-a-behaviour;
}
// Paragraphs

View file

@ -22,7 +22,7 @@ export class HtmlRendererService {
this.addHrefHook(this.enhancedDomPurify)
this.addCheckSchemesHook(this.simpleDomPurify, getDefaultSanitizedSchemes())
this.addCheckSchemesHook(this.simpleDomPurify, [ ...getDefaultSanitizedSchemes(), 'mailto' ])
this.addCheckSchemesHook(this.enhancedDomPurify, [ ...getDefaultSanitizedSchemes(), 'mailto' ])
}
private addHrefHook (dompurifyInstance: DOMPurifyI) {
@ -72,8 +72,17 @@ export class HtmlRendererService {
})
}
removeClassAttributes (html: string) {
return DOMPurify().sanitize(html, {
ALLOWED_TAGS: getDefaultSanitizedTags(),
ALLOWED_ATTR: getDefaultSanitizedHrefAttributes().filter(a => a !== 'class'),
ALLOW_DATA_ATTR: true
})
}
async toSimpleSafeHtml (text: string) {
const html = await this.linkifier.linkify(text)
let html = this.removeClassAttributes(text)
html = await this.linkifier.linkify(html)
return this.sanitize(this.simpleDomPurify, html)
}

View file

@ -1,17 +1,18 @@
import { Injectable } from '@angular/core'
import { getAbsoluteAPIUrl } from '@app/helpers/utils'
import * as LinkifyJS from 'linkifyjs'
import type * as LinkifyJS from 'linkifyjs'
import type LinkifyHTML from 'linkify-html'
@Injectable()
export class LinkifierService {
static CLASSNAME = 'linkified'
private linkifyModule: typeof LinkifyJS
private linkifyHtmlModule: any
private linkifyHtmlModule: typeof LinkifyHTML
private mentionPluginInitialized = false
private linkifyOptions = {
private linkifyOptions: LinkifyJS.Opts = {
className: {
mention: LinkifierService.CLASSNAME + '-mention',
url: LinkifierService.CLASSNAME + '-url'