MFMのDOM ParserをJSDOMからhappy-domに変更する (#10016)
Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| import { URL } from 'node:url'; | ||||
| import { Inject, Injectable } from '@nestjs/common'; | ||||
| import * as parse5 from 'parse5'; | ||||
| import { JSDOM } from 'jsdom'; | ||||
| import { Window } from 'happy-dom'; | ||||
| import { DI } from '@/di-symbols.js'; | ||||
| import type { Config } from '@/config.js'; | ||||
| import { intersperse } from '@/misc/prelude/array.js'; | ||||
| @@ -235,7 +235,7 @@ export class MfmService { | ||||
| 			return null; | ||||
| 		} | ||||
| 	 | ||||
| 		const { window } = new JSDOM(''); | ||||
| 		const { window } = new Window(); | ||||
| 	 | ||||
| 		const doc = window.document; | ||||
| 	 | ||||
| @@ -300,7 +300,7 @@ export class MfmService { | ||||
| 	 | ||||
| 			hashtag: (node) => { | ||||
| 				const a = doc.createElement('a'); | ||||
| 				a.href = `${this.config.url}/tags/${node.props.hashtag}`; | ||||
| 				a.setAttribute('href', `${this.config.url}/tags/${node.props.hashtag}`); | ||||
| 				a.textContent = `#${node.props.hashtag}`; | ||||
| 				a.setAttribute('rel', 'tag'); | ||||
| 				return a; | ||||
| @@ -326,7 +326,7 @@ export class MfmService { | ||||
| 	 | ||||
| 			link: (node) => { | ||||
| 				const a = doc.createElement('a'); | ||||
| 				a.href = node.props.url; | ||||
| 				a.setAttribute('href', node.props.url); | ||||
| 				appendChildren(node.children, a); | ||||
| 				return a; | ||||
| 			}, | ||||
| @@ -335,7 +335,7 @@ export class MfmService { | ||||
| 				const a = doc.createElement('a'); | ||||
| 				const { username, host, acct } = node.props; | ||||
| 				const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host); | ||||
| 				a.href = remoteUserInfo ? (remoteUserInfo.url ? remoteUserInfo.url : remoteUserInfo.uri) : `${this.config.url}/${acct}`; | ||||
| 				a.setAttribute('href', remoteUserInfo ? (remoteUserInfo.url ? remoteUserInfo.url : remoteUserInfo.uri) : `${this.config.url}/${acct}`); | ||||
| 				a.className = 'u-url mention'; | ||||
| 				a.textContent = acct; | ||||
| 				return a; | ||||
| @@ -360,14 +360,14 @@ export class MfmService { | ||||
| 	 | ||||
| 			url: (node) => { | ||||
| 				const a = doc.createElement('a'); | ||||
| 				a.href = node.props.url; | ||||
| 				a.setAttribute('href', node.props.url); | ||||
| 				a.textContent = node.props.url; | ||||
| 				return a; | ||||
| 			}, | ||||
| 	 | ||||
| 			search: (node) => { | ||||
| 				const a = doc.createElement('a'); | ||||
| 				a.href = `https://www.google.com/search?q=${node.props.query}`; | ||||
| 				a.setAttribute('href', `https://www.google.com/search?q=${node.props.query}`); | ||||
| 				a.textContent = node.props.content; | ||||
| 				return a; | ||||
| 			}, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 potpro
					potpro