import * as assert from "assert"; import * as mfm from "mfm-js"; import { toHtml } from "../src/mfm/to-html.js"; import { fromHtml } from "../src/mfm/from-html.js"; 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://iceshrimp.dev/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://joiniceshrimp.org/b d

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

a https://joiniceshrimp.org/ä 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://joiniceshrimp.org/b d", ); }); it("link without both", () => { assert.deepStrictEqual(fromHtml("

a d

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

a @user d

', ), "a @user@joiniceshrimp.org d", ); }); it("hashtag", () => { assert.deepStrictEqual( fromHtml('

a #a d

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