diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-08-19 00:31:25 +0900 |
|---|---|---|
| committer | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-08-19 00:31:25 +0900 |
| commit | 7aac2c4e297593b2a89a2fdc3a25f8a20267b9c3 (patch) | |
| tree | 70e3e5783ccdd5a2c707d8d7ebd04add25d60d9c /src | |
| parent | missing semicolon (diff) | |
| download | sharkey-7aac2c4e297593b2a89a2fdc3a25f8a20267b9c3.tar.gz sharkey-7aac2c4e297593b2a89a2fdc3a25f8a20267b9c3.tar.bz2 sharkey-7aac2c4e297593b2a89a2fdc3a25f8a20267b9c3.zip | |
Clean up
Diffstat (limited to 'src')
| -rw-r--r-- | src/mfm/html.ts | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/mfm/html.ts b/src/mfm/html.ts index 1544ac34f1..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 }) { - const t = content.split('\n'); - for (let i = 0; i < t.length; i++) { - document.body.appendChild(document.createTextNode(t[i])); - if (i != t.length - 1) { - document.body.appendChild(document.createElement('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); } }, |