summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2018-12-09 13:15:32 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2018-12-09 13:15:32 +0900
commit197e2c83777e8bb01f75566d8d78424c8e4eba2d (patch)
tree3d9e198f582c6c9319701ddb75afcec79acde9d4 /src
parentEliminate if-statement (#3556) (diff)
downloadmisskey-197e2c83777e8bb01f75566d8d78424c8e4eba2d.tar.gz
misskey-197e2c83777e8bb01f75566d8d78424c8e4eba2d.tar.bz2
misskey-197e2c83777e8bb01f75566d8d78424c8e4eba2d.zip
#2501 (#3567)
* refactor mfm/html * fix * fix * https://github.com/syuilo/misskey/pull/3567#discussion_r240023301
Diffstat (limited to 'src')
-rw-r--r--src/mfm/html.ts28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/mfm/html.ts b/src/mfm/html.ts
index 50d26e10e6..66617adf9c 100644
--- a/src/mfm/html.ts
+++ b/src/mfm/html.ts
@@ -14,44 +14,44 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
const doc = window.document;
- function dive(nodes: Node[]): any[] {
- return nodes.map(n => handlers[n.name](n));
+ function appendChildren(children: Node[], targetElement: any): void {
+ for (const child of children.map(n => handlers[n.name](n))) targetElement.appendChild(child);
}
const handlers: { [key: string]: (token: Node) => any } = {
bold(token) {
const el = doc.createElement('b');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
big(token) {
const el = doc.createElement('strong');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
small(token) {
const el = doc.createElement('small');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
strike(token) {
const el = doc.createElement('del');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
italic(token) {
const el = doc.createElement('i');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
motion(token) {
const el = doc.createElement('i');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
@@ -65,7 +65,7 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
center(token) {
const el = doc.createElement('div');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
@@ -96,7 +96,7 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
link(token) {
const a = doc.createElement('a');
a.href = token.props.url;
- dive(token.children).forEach(child => a.appendChild(child));
+ appendChildren(token.children, a);
return a;
},
@@ -111,13 +111,13 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
quote(token) {
const el = doc.createElement('blockquote');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
title(token) {
const el = doc.createElement('h1');
- dive(token.children).forEach(child => el.appendChild(child));
+ appendChildren(token.children, el);
return el;
},
@@ -147,9 +147,7 @@ export default (tokens: Node[], mentionedRemoteUsers: INote['mentionedRemoteUser
}
};
- dive(tokens).forEach(x => {
- doc.body.appendChild(x);
- });
+ appendChildren(tokens, doc.body);
return `<p>${doc.body.innerHTML}</p>`;
};