summaryrefslogtreecommitdiff
path: root/src/mfm/html.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-08-19 00:55:07 +0900
committerGitHub <noreply@github.com>2018-08-19 00:55:07 +0900
commit0e45d0d47fca2f9cf2caf87a25442d3090bea2fb (patch)
tree4591218074ce73b4f5d3be7582d76a170dc1b672 /src/mfm/html.ts
parentNew translations ja.yml (Japanese (Kansai-ben)) (diff)
parentMerge pull request #2330 from syuilo/patch (diff)
downloadmisskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.tar.gz
misskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.tar.bz2
misskey-0e45d0d47fca2f9cf2caf87a25442d3090bea2fb.zip
Merge branch 'master' into l10n_master
Diffstat (limited to 'src/mfm/html.ts')
-rw-r--r--src/mfm/html.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mfm/html.ts b/src/mfm/html.ts
index c11bd55cf4..c798ee410a 100644
--- a/src/mfm/html.ts
+++ b/src/mfm/html.ts
@@ -5,6 +5,10 @@ import config from '../config';
import { INote } from '../models/note';
import { TextElement } from './parse';
+function intersperse<T>(sep: T, xs: T[]): T[] {
+ return [].concat(...xs.map(x => [sep, x])).slice(1);
+}
+
const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: INote['mentionedRemoteUsers']) => void } = {
bold({ document }, { bold }) {
const b = document.createElement('b');
@@ -80,12 +84,9 @@ const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers:
},
text({ document }, { content }) {
- for (const text of content.split('\n')) {
- const node = document.createTextNode(text);
- document.body.appendChild(node);
-
- const br = document.createElement('br');
- document.body.appendChild(br);
+ const nodes = (content as string).split('\n').map(x => document.createTextNode(x));
+ for (const x of intersperse(document.createElement('br'), nodes)) {
+ document.body.appendChild(x);
}
},