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", async () => { const input = "foo\nbar\nbaz"; const output = "

foo
bar
baz

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

foo
bar
baz

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

a

b

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

abc

d

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

a c d

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

a c d

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

a https://joiniceshrimp.org/b d

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

a https://joiniceshrimp.org/ä d

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

a c d

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

a c d

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

a d

'), "a https://joiniceshrimp.org/b d", ); }); it("link without both", async () => { assert.deepStrictEqual(await fromHtml("

a d

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

a @user d

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

a #a d

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