summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/MfmService.ts
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2024-06-08 16:45:53 +0100
committerdakkar <dakkar@thenautilus.net>2024-06-08 16:45:53 +0100
commit5dc8c2827c546f1d4ab4260b051d22e63319da8b (patch)
tree02c9189a3dd16a9716e8d61a284f62a16c2784fe /packages/backend/src/core/MfmService.ts
parent配信停止したインスタンス一覧が見れなくなる問題を修... (diff)
parentmerge: only allow a single boost via hotkey - fixes #467 #468 (!539) (diff)
downloadsharkey-5dc8c2827c546f1d4ab4260b051d22e63319da8b.tar.gz
sharkey-5dc8c2827c546f1d4ab4260b051d22e63319da8b.tar.bz2
sharkey-5dc8c2827c546f1d4ab4260b051d22e63319da8b.zip
Merge branch 'develop' into future-2024-05-31
Diffstat (limited to 'packages/backend/src/core/MfmService.ts')
-rw-r--r--packages/backend/src/core/MfmService.ts288
1 files changed, 144 insertions, 144 deletions
diff --git a/packages/backend/src/core/MfmService.ts b/packages/backend/src/core/MfmService.ts
index 461cb2b6a9..30009c1229 100644
--- a/packages/backend/src/core/MfmService.ts
+++ b/packages/backend/src/core/MfmService.ts
@@ -464,10 +464,10 @@ export class MfmService {
return new XMLSerializer().serializeToString(body);
}
- // the toMastoHtml function was taken from Iceshrimp and written by zotan and modified by marie to work with the current MK version
+ // the toMastoApiHtml function was taken from Iceshrimp and written by zotan and modified by marie to work with the current MK version
@bindThis
- public async toMastoHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
+ public async toMastoApiHtml(nodes: mfm.MfmNode[] | null, mentionedRemoteUsers: IMentionedRemoteUsers = [], inline = false, quoteUri: string | null = null) {
if (nodes == null) {
return null;
}
@@ -485,174 +485,174 @@ export class MfmService {
const handlers: {
[K in mfm.MfmNode['type']]: (node: mfm.NodeType<K>) => any;
} = {
- async bold(node) {
- const el = doc.createElement('span');
- el.textContent = '**';
- await appendChildren(node.children, el);
- el.textContent += '**';
- return el;
- },
+ async bold(node) {
+ const el = doc.createElement('span');
+ el.textContent = '**';
+ await appendChildren(node.children, el);
+ el.textContent += '**';
+ return el;
+ },
- async small(node) {
- const el = doc.createElement('small');
- await appendChildren(node.children, el);
- return el;
- },
+ async small(node) {
+ const el = doc.createElement('small');
+ await appendChildren(node.children, el);
+ return el;
+ },
- async strike(node) {
- const el = doc.createElement('span');
- el.textContent = '~~';
- await appendChildren(node.children, el);
- el.textContent += '~~';
- return el;
- },
+ async strike(node) {
+ const el = doc.createElement('span');
+ el.textContent = '~~';
+ await appendChildren(node.children, el);
+ el.textContent += '~~';
+ return el;
+ },
- async italic(node) {
- const el = doc.createElement('span');
- el.textContent = '*';
- await appendChildren(node.children, el);
- el.textContent += '*';
- return el;
- },
+ async italic(node) {
+ const el = doc.createElement('span');
+ el.textContent = '*';
+ await appendChildren(node.children, el);
+ el.textContent += '*';
+ return el;
+ },
- async fn(node) {
- const el = doc.createElement('span');
- el.textContent = '*';
- await appendChildren(node.children, el);
- el.textContent += '*';
- return el;
- },
+ async fn(node) {
+ const el = doc.createElement('span');
+ el.textContent = '*';
+ await appendChildren(node.children, el);
+ el.textContent += '*';
+ return el;
+ },
- blockCode(node) {
- const pre = doc.createElement('pre');
- const inner = doc.createElement('code');
+ blockCode(node) {
+ const pre = doc.createElement('pre');
+ const inner = doc.createElement('code');
- const nodes = node.props.code
- .split(/\r\n|\r|\n/)
- .map((x) => doc.createTextNode(x));
+ const nodes = node.props.code
+ .split(/\r\n|\r|\n/)
+ .map((x) => doc.createTextNode(x));
- for (const x of intersperse<FIXME | 'br'>('br', nodes)) {
- inner.appendChild(x === 'br' ? doc.createElement('br') : x);
- }
+ for (const x of intersperse<FIXME | 'br'>('br', nodes)) {
+ inner.appendChild(x === 'br' ? doc.createElement('br') : x);
+ }
- pre.appendChild(inner);
- return pre;
- },
+ pre.appendChild(inner);
+ return pre;
+ },
- async center(node) {
- const el = doc.createElement('div');
- await appendChildren(node.children, el);
- return el;
- },
+ async center(node) {
+ const el = doc.createElement('div');
+ await appendChildren(node.children, el);
+ return el;
+ },
- emojiCode(node) {
- return doc.createTextNode(`\u200B:${node.props.name}:\u200B`);
- },
+ emojiCode(node) {
+ return doc.createTextNode(`\u200B:${node.props.name}:\u200B`);
+ },
- unicodeEmoji(node) {
- return doc.createTextNode(node.props.emoji);
- },
+ unicodeEmoji(node) {
+ return doc.createTextNode(node.props.emoji);
+ },
- hashtag: (node) => {
- const a = doc.createElement('a');
- a.setAttribute('href', `${this.config.url}/tags/${node.props.hashtag}`);
- a.textContent = `#${node.props.hashtag}`;
- a.setAttribute('rel', 'tag');
- a.setAttribute('class', 'hashtag');
- return a;
- },
+ hashtag: (node) => {
+ const a = doc.createElement('a');
+ a.setAttribute('href', `${this.config.url}/tags/${node.props.hashtag}`);
+ a.textContent = `#${node.props.hashtag}`;
+ a.setAttribute('rel', 'tag');
+ a.setAttribute('class', 'hashtag');
+ return a;
+ },
- inlineCode(node) {
- const el = doc.createElement('code');
- el.textContent = node.props.code;
- return el;
- },
+ inlineCode(node) {
+ const el = doc.createElement('code');
+ el.textContent = node.props.code;
+ return el;
+ },
- mathInline(node) {
- const el = doc.createElement('code');
- el.textContent = node.props.formula;
- return el;
- },
+ mathInline(node) {
+ const el = doc.createElement('code');
+ el.textContent = node.props.formula;
+ return el;
+ },
- mathBlock(node) {
- const el = doc.createElement('code');
- el.textContent = node.props.formula;
- return el;
- },
+ mathBlock(node) {
+ const el = doc.createElement('code');
+ el.textContent = node.props.formula;
+ return el;
+ },
- async 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);
- return a;
- },
+ async 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);
+ return a;
+ },
- async mention(node) {
- const { username, host, acct } = node.props;
- const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
+ async mention(node) {
+ const { username, host, acct } = node.props;
+ const resolved = mentionedRemoteUsers.find(remoteUser => remoteUser.username === username && remoteUser.host === host);
- const el = doc.createElement('span');
- if (!resolved) {
- el.textContent = acct;
- } else {
- el.setAttribute('class', 'h-card');
- el.setAttribute('translate', 'no');
- const a = doc.createElement('a');
- a.setAttribute('href', resolved.url ? resolved.url : resolved.uri);
- a.className = 'u-url mention';
- const span = doc.createElement('span');
- span.textContent = resolved.username || username;
- a.textContent = '@';
- a.appendChild(span);
- el.appendChild(a);
- }
+ const el = doc.createElement('span');
+ if (!resolved) {
+ el.textContent = acct;
+ } else {
+ el.setAttribute('class', 'h-card');
+ el.setAttribute('translate', 'no');
+ const a = doc.createElement('a');
+ a.setAttribute('href', resolved.url ? resolved.url : resolved.uri);
+ a.className = 'u-url mention';
+ const span = doc.createElement('span');
+ span.textContent = resolved.username || username;
+ a.textContent = '@';
+ a.appendChild(span);
+ el.appendChild(a);
+ }
- return el;
- },
+ return el;
+ },
- async quote(node) {
- const el = doc.createElement('blockquote');
- await appendChildren(node.children, el);
- return el;
- },
+ async quote(node) {
+ const el = doc.createElement('blockquote');
+ await appendChildren(node.children, el);
+ return el;
+ },
- text(node) {
- const el = doc.createElement('span');
- const nodes = node.props.text
- .split(/\r\n|\r|\n/)
- .map((x) => doc.createTextNode(x));
+ text(node) {
+ const el = doc.createElement('span');
+ const nodes = node.props.text
+ .split(/\r\n|\r|\n/)
+ .map((x) => doc.createTextNode(x));
- for (const x of intersperse<FIXME | 'br'>('br', nodes)) {
- el.appendChild(x === 'br' ? doc.createElement('br') : x);
- }
+ for (const x of intersperse<FIXME | 'br'>('br', nodes)) {
+ el.appendChild(x === 'br' ? doc.createElement('br') : x);
+ }
- return el;
- },
+ return el;
+ },
- url(node) {
- const a = doc.createElement('a');
- a.setAttribute('rel', 'nofollow noopener noreferrer');
- a.setAttribute('target', '_blank');
- a.setAttribute('href', node.props.url);
- a.textContent = node.props.url.replace(/^https?:\/\//, '');
- return a;
- },
+ url(node) {
+ const a = doc.createElement('a');
+ a.setAttribute('rel', 'nofollow noopener noreferrer');
+ a.setAttribute('target', '_blank');
+ a.setAttribute('href', node.props.url);
+ a.textContent = node.props.url.replace(/^https?:\/\//, '');
+ return a;
+ },
- search: (node) => {
- const a = doc.createElement('a');
- a.setAttribute('href', `https"google.com/${node.props.query}`);
- a.textContent = node.props.content;
- return a;
- },
+ search: (node) => {
+ const a = doc.createElement('a');
+ a.setAttribute('href', `https://www.google.com/search?q=${node.props.query}`);
+ a.textContent = node.props.content;
+ return a;
+ },
- async plain(node) {
- const el = doc.createElement('span');
- await appendChildren(node.children, el);
- return el;
- },
- };
+ async plain(node) {
+ const el = doc.createElement('span');
+ await appendChildren(node.children, el);
+ return el;
+ },
+ };
await appendChildren(nodes, doc.body);