remove unused async from toMastoApiHtml / fromMastoApiHtml

This commit is contained in:
Hazelnoot 2025-03-22 18:18:10 -04:00
parent 8d67a8c9ae
commit fbdee815da
2 changed files with 37 additions and 37 deletions

View file

@ -179,7 +179,7 @@ export class MfmService {
break;
}
// this is here only to catch upstream changes!
// this is here only to catch upstream changes!
case 'ruby--': {
let ruby: [string, string][] = [];
for (const child of node.childNodes) {
@ -584,9 +584,10 @@ export class MfmService {
}
// the toMastoApiHtml function was taken from Iceshrimp and written by zotan and modified by marie to work with the current MK version
// additionally modified by hazelnoot to remove async
@bindThis
public async toMastoApiHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
public toMastoApiHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
if (nodes == null) {
return null;
}
@ -597,50 +598,50 @@ export class MfmService {
const body = doc.createElement('p');
async function appendChildren(children: mfm.MfmNode[], targetElement: any): Promise<void> {
function appendChildren(children: mfm.MfmNode[], targetElement: any): void {
if (children) {
for (const child of await Promise.all(children.map(async (x) => await (handlers as any)[x.type](x)))) targetElement.appendChild(child);
for (const child of children.map((x) => (handlers as any)[x.type](x))) targetElement.appendChild(child);
}
}
const handlers: {
[K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any;
} = {
async bold(node) {
bold(node) {
const el = doc.createElement('span');
el.textContent = '**';
await appendChildren(node.children, el);
appendChildren(node.children, el);
el.textContent += '**';
return el;
},
async small(node) {
small(node) {
const el = doc.createElement('small');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
},
async strike(node) {
strike(node) {
const el = doc.createElement('span');
el.textContent = '~~';
await appendChildren(node.children, el);
appendChildren(node.children, el);
el.textContent += '~~';
return el;
},
async italic(node) {
italic(node) {
const el = doc.createElement('span');
el.textContent = '*';
await appendChildren(node.children, el);
appendChildren(node.children, el);
el.textContent += '*';
return el;
},
async fn(node) {
fn(node) {
switch (node.props.name) {
case 'group': { // hack for ruby
const el = doc.createElement('span');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
}
case 'ruby': {
@ -666,7 +667,7 @@ export class MfmService {
if (!rt) {
const el = doc.createElement('span');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
}
@ -679,7 +680,7 @@ export class MfmService {
const rpEndEl = doc.createElement('rp');
rpEndEl.appendChild(doc.createTextNode(')'));
await appendChildren(node.children.slice(0, node.children.length - 1), rubyEl);
appendChildren(node.children.slice(0, node.children.length - 1), rubyEl);
rtEl.appendChild(doc.createTextNode(text.trim()));
rubyEl.appendChild(rpStartEl);
rubyEl.appendChild(rtEl);
@ -691,7 +692,7 @@ export class MfmService {
default: {
const el = doc.createElement('span');
el.textContent = '*';
await appendChildren(node.children, el);
appendChildren(node.children, el);
el.textContent += '*';
return el;
}
@ -714,9 +715,9 @@ export class MfmService {
return pre;
},
async center(node) {
center(node) {
const el = doc.createElement('div');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
},
@ -755,16 +756,16 @@ export class MfmService {
return el;
},
async link(node) {
link(node) {
const a = doc.createElement('a');
a.setAttribute('rel', 'nofollow noopener noreferrer');
a.setAttribute('target', '_blank');
a.setAttribute('href', node.props.url);
await appendChildren(node.children, a);
appendChildren(node.children, a);
return a;
},
async mention(node) {
mention(node) {
const { username, host, acct } = node.props;
const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
@ -787,9 +788,9 @@ export class MfmService {
return el;
},
async quote(node) {
quote(node) {
const el = doc.createElement('blockquote');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
},
@ -822,14 +823,14 @@ export class MfmService {
return a;
},
async plain(node) {
plain(node) {
const el = doc.createElement('span');
await appendChildren(node.children, el);
appendChildren(node.children, el);
return el;
},
};
await appendChildren(nodes, body);
appendChildren(nodes, body);
if (quoteUri !== null) {
const a = doc.createElement('a');