Move escaping MFM to a separate function
This commit is contained in:
parent
3e9e1635e2
commit
0a92dcd9d6
|
@ -42,6 +42,16 @@ namespace MisskeyAPI {
|
|||
}
|
||||
|
||||
export namespace Converter {
|
||||
// FIXME: Properly render MFM instead of just escaping HTML characters.
|
||||
const escapeMFM = (text: string): string => text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/`/g, '`')
|
||||
.replace(/\r?\n/g, '<br>');
|
||||
|
||||
export const emoji = (e: Entity.Emoji): MegalodonEntity.Emoji => {
|
||||
return {
|
||||
shortcode: e.name,
|
||||
|
@ -229,16 +239,7 @@ namespace MisskeyAPI {
|
|||
in_reply_to_id: n.replyId,
|
||||
in_reply_to_account_id: n.reply?.userId ?? null,
|
||||
reblog: n.renote ? note(n.renote, host) : null,
|
||||
content: n.text
|
||||
? n.text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/`/g, '`')
|
||||
.replace(/\r?\n/g, '<br>')
|
||||
: '',
|
||||
content: n.text ? escapeMFM(n.text) : '',
|
||||
plain_content: n.text ? n.text : null,
|
||||
created_at: n.createdAt,
|
||||
emojis: n.emojis.map(e => emoji(e)),
|
||||
|
@ -385,33 +386,22 @@ namespace MisskeyAPI {
|
|||
moved: null
|
||||
}
|
||||
|
||||
export const announcement = (a: Entity.Announcement): MegalodonEntity.Announcement => {
|
||||
// Reused from Note converter.
|
||||
const escapeHTML = (text: string) => text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''')
|
||||
.replace(/`/g, '`')
|
||||
.replace(/\r?\n/g, '<br>');
|
||||
return {
|
||||
id: a.id,
|
||||
content: `<h1>${escapeHTML(a.title)}</h1>${escapeHTML(a.text)}`,
|
||||
starts_at: null,
|
||||
ends_at: null,
|
||||
published: true,
|
||||
all_day: false,
|
||||
published_at: a.createdAt,
|
||||
updated_at: a.updatedAt,
|
||||
read: a.isRead,
|
||||
mentions: [],
|
||||
statuses: [],
|
||||
tags: [],
|
||||
emojis: [],
|
||||
reactions: [],
|
||||
};
|
||||
}
|
||||
export const announcement = (a: Entity.Announcement): MegalodonEntity.Announcement => ({
|
||||
id: a.id,
|
||||
content: `<h1>${escapeMFM(a.title)}</h1>${escapeMFM(a.text)}`,
|
||||
starts_at: null,
|
||||
ends_at: null,
|
||||
published: true,
|
||||
all_day: false,
|
||||
published_at: a.createdAt,
|
||||
updated_at: a.updatedAt,
|
||||
read: a.isRead,
|
||||
mentions: [],
|
||||
statuses: [],
|
||||
tags: [],
|
||||
emojis: [],
|
||||
reactions: [],
|
||||
})
|
||||
|
||||
export const notification = (n: Entity.Notification, host: string): MegalodonEntity.Notification => {
|
||||
let notification = {
|
||||
|
|
Loading…
Reference in a new issue