diff --git a/src/mfm/html.ts b/src/mfm/html.ts index b7fa5b6f0..df9959dc4 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 706c4c549..901ffb80e 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); + }); + }); });