import * as assert from 'assert'; import * as mfm from 'mfm-js'; import { toHtml } from '../src/mfm/to-html'; import { fromHtml } from '../src/mfm/from-html'; describe('toHtml', () => { it('br', () => { const input = 'foo\nbar\nbaz'; const output = '

foo
bar
baz

'; assert.equal(toHtml(mfm.parse(input)), output); }); it('br alt', () => { const input = 'foo\r\nbar\rbaz'; const output = '

foo
bar
baz

'; assert.equal(toHtml(mfm.parse(input)), output); }); }); describe('fromHtml', () => { it('p', () => { assert.deepStrictEqual(fromHtml('

a

b

'), 'a\n\nb'); }); it('block element', () => { assert.deepStrictEqual(fromHtml('
a
b
'), 'a\nb'); }); it('inline element', () => { assert.deepStrictEqual(fromHtml(''), 'a\nb'); }); it('block code', () => { assert.deepStrictEqual(fromHtml('
a\nb
'), '```\na\nb\n```'); }); it('inline code', () => { assert.deepStrictEqual(fromHtml('a'), '`a`'); }); it('quote', () => { assert.deepStrictEqual(fromHtml('
a\nb
'), '> a\n> b'); }); it('br', () => { assert.deepStrictEqual(fromHtml('

abc

d

'), 'abc\n\nd'); }); it('link with different text', () => { assert.deepStrictEqual(fromHtml('

a c d

'), 'a [c](https://example.com/b) d'); }); it('link with different text, but not encoded', () => { assert.deepStrictEqual(fromHtml('

a c d

'), 'a [c]() d'); }); it('link with same text', () => { assert.deepStrictEqual(fromHtml('

a https://example.com/b d

'), 'a https://example.com/b d'); }); it('link with same text, but not encoded', () => { assert.deepStrictEqual(fromHtml('

a https://example.com/ä d

'), 'a d'); }); it('link with no url', () => { assert.deepStrictEqual(fromHtml('

a c d

'), 'a [c](b) d'); }); it('link without href', () => { assert.deepStrictEqual(fromHtml('

a c d

'), 'a c d'); }); it('link without text', () => { assert.deepStrictEqual(fromHtml('

a d

'), 'a https://example.com/b d'); }); it('link without both', () => { assert.deepStrictEqual(fromHtml('

a d

'), 'a d'); }); it('mention', () => { assert.deepStrictEqual(fromHtml('

a @user d

'), 'a @user@example.com d'); }); it('hashtag', () => { assert.deepStrictEqual(fromHtml('

a #a d

', ['#a']), 'a #a d'); }); });