diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2018-08-19 00:52:10 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-08-19 00:52:10 +0900 |
| commit | 043b66f5da81ab5da0c8d4792251b0e8def90083 (patch) | |
| tree | 712a779697306da8debc5bd5f358356743ae9995 | |
| parent | Merge pull request #2329 from syuilo/improve-chart (diff) | |
| parent | Clean up (diff) | |
| download | sharkey-043b66f5da81ab5da0c8d4792251b0e8def90083.tar.gz sharkey-043b66f5da81ab5da0c8d4792251b0e8def90083.tar.bz2 sharkey-043b66f5da81ab5da0c8d4792251b0e8def90083.zip | |
Merge pull request #2330 from syuilo/patch
Clean up
| -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); } }, |