mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-26 22:29:28 +09:00
fix #1726
This commit is contained in:
parent
4e04e5e0c0
commit
f0fec654ff
@ -6,7 +6,7 @@ import config from '../../../config';
|
|||||||
export default function(note: INote) {
|
export default function(note: INote) {
|
||||||
if (note.text == null) return null;
|
if (note.text == null) return null;
|
||||||
|
|
||||||
let html = toHtml(parse(note.text));
|
let html = toHtml(parse(note.text), note.mentionedRemoteUsers);
|
||||||
|
|
||||||
if (note.poll != null) {
|
if (note.poll != null) {
|
||||||
const url = `${config.url}/notes/${note._id}`;
|
const url = `${config.url}/notes/${note._id}`;
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import { lib as emojilib } from 'emojilib';
|
import { lib as emojilib } from 'emojilib';
|
||||||
import { JSDOM } from 'jsdom';
|
import { JSDOM } from 'jsdom';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
import { INote } from '../models/note';
|
||||||
|
|
||||||
const handlers = {
|
const handlers: {[key: string]: (window: any, token: any, mentionedRemoteUsers: INote["mentionedRemoteUsers"]) => void} = {
|
||||||
bold({ document }, { bold }) {
|
bold({ document }, { bold }) {
|
||||||
const b = document.createElement('b');
|
const b = document.createElement('b');
|
||||||
b.textContent = bold;
|
b.textContent = bold;
|
||||||
@ -44,9 +45,10 @@ const handlers = {
|
|||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
},
|
},
|
||||||
|
|
||||||
mention({ document }, { content }) {
|
mention({ document }, { content, username, host }, mentionedRemoteUsers) {
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = `${config.url}/${content}`;
|
const remoteUserInfo = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
|
||||||
|
a.href = remoteUserInfo ? remoteUserInfo.uri : `${config.url}/${content}`;
|
||||||
a.textContent = content;
|
a.textContent = content;
|
||||||
document.body.appendChild(a);
|
document.body.appendChild(a);
|
||||||
},
|
},
|
||||||
@ -88,11 +90,11 @@ const handlers = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default tokens => {
|
export default (tokens, mentionedRemoteUsers: INote["mentionedRemoteUsers"] = []) => {
|
||||||
const { window } = new JSDOM('');
|
const { window } = new JSDOM('');
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
handlers[token.type](window, token);
|
handlers[token.type](window, token, mentionedRemoteUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `<p>${window.document.body.innerHTML}</p>`;
|
return `<p>${window.document.body.innerHTML}</p>`;
|
||||||
|
Loading…
Reference in New Issue
Block a user