From 374b276f5ca46555235b76413a14b7f09528b5e0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 17 Sep 2018 02:45:30 +0900 Subject: [PATCH] Fix #2720 --- src/mfm/html.ts | 8 ++++++-- test/mfm.ts | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mfm/html.ts b/src/mfm/html.ts index b7fa5b6f03..df9959dc4b 100644 --- a/src/mfm/html.ts +++ b/src/mfm/html.ts @@ -82,8 +82,12 @@ const handlers: { [key: string]: (window: any, token: any, mentionedRemoteUsers: text({ document }, { content }) { 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); + for (const x of intersperse('br', nodes)) { + if (x === 'br') { + document.body.appendChild(document.createElement('br')); + } else { + document.body.appendChild(x); + } } }, diff --git a/test/mfm.ts b/test/mfm.ts index 706c4c549a..901ffb80e3 100644 --- a/test/mfm.ts +++ b/test/mfm.ts @@ -1,6 +1,7 @@ import * as assert from 'assert'; import analyze from '../src/mfm/parse'; +import toHtml from '../src/mfm/html'; import syntaxhighlighter from '../src/mfm/parse/core/syntax-highlighter'; describe('Text', () => { @@ -170,4 +171,12 @@ describe('Text', () => { assert.equal(html, '/'); }); }); + + describe('toHtml', () => { + it('br', () => { + const input = 'foo\nbar\nbaz'; + const output = '

foo
bar
baz

'; + assert.equal(toHtml(analyze(input)), output); + }); + }); });