From c0fbcee38a5be0d67237a42dd5faceeb298ce940 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 18 Aug 2018 11:36:43 +0900 Subject: improve MFM to html --- src/mfm/html.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/mfm/html.ts') diff --git a/src/mfm/html.ts b/src/mfm/html.ts index c11bd55cf4..c53542ac8f 100644 --- a/src/mfm/html.ts +++ b/src/mfm/html.ts @@ -80,12 +80,12 @@ 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 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')); + } } }, -- cgit v1.2.3-freya From f59d0a75e4f75d56b9d1afb50b924e36109ef985 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sat, 18 Aug 2018 21:58:00 +0900 Subject: missing semicolon --- src/mfm/html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/mfm/html.ts') diff --git a/src/mfm/html.ts b/src/mfm/html.ts index c53542ac8f..1544ac34f1 100644 --- a/src/mfm/html.ts +++ b/src/mfm/html.ts @@ -80,7 +80,7 @@ const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: }, text({ document }, { content }) { - const t = content.split('\n') + 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) { -- cgit v1.2.3-freya From 7aac2c4e297593b2a89a2fdc3a25f8a20267b9c3 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Sun, 19 Aug 2018 00:31:25 +0900 Subject: Clean up --- src/mfm/html.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/mfm/html.ts') 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(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); } }, -- cgit v1.2.3-freya