/* Copyright 2024 New Vector Ltd. Copyright 2021 The Matrix.org Foundation C.I.C. SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only Please see LICENSE files in the repository root for full details. */ import Markdown from "../src/Markdown"; describe("Markdown parser test", () => { describe("fixing HTML links", () => { const testString = [ "Test1:", "#_foonetic_xkcd:matrix.org", "http://google.com/_thing_", "https://matrix.org/_matrix/client/foo/123_", "#_foonetic_xkcd:matrix.org", "", "Test1A:", "#_foonetic_xkcd:matrix.org", "http://google.com/_thing_", "https://matrix.org/_matrix/client/foo/123_", "#_foonetic_xkcd:matrix.org", "", "Test2:", "http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg", "http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg", "", "Test3:", "https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org", "https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org", ].join("\n"); it("tests that links with markdown empasis in them are getting properly HTML formatted", () => { /* eslint-disable max-len */ const expectedResult = [ "
Test1:
#_foonetic_xkcd:matrix.org
http://google.com/_thing_
https://matrix.org/_matrix/client/foo/123_
#_foonetic_xkcd:matrix.org
Test1A:
#_foonetic_xkcd:matrix.org
http://google.com/_thing_
https://matrix.org/_matrix/client/foo/123_
#_foonetic_xkcd:matrix.org
Test2:
http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg
http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg
Test3:
https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org
https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org
Test1:
<#_foonetic_xkcd:matrix.org>
http://google.com/_thing_
https://matrix.org/_matrix/client/foo/123_
<#_foonetic_xkcd:matrix.org>
Test1A:
<#_foonetic_xkcd:matrix.org>
http://google.com/_thing_
https://matrix.org/_matrix/client/foo/123_
<#_foonetic_xkcd:matrix.org>
Test2:
http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg
http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg
Test3:
https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org
https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org
#_foonetic_xkcd:matrix.org',
"http://google.com/_thing_",
"https://matrix.org/_matrix/client/foo/123_",
"#_foonetic_xkcd:matrix.org",
"",
"Test1A:",
"#_foonetic_xkcd:matrix.org",
"http://google.com/_thing_",
"https://matrix.org/_matrix/client/foo/123_",
"#_foonetic_xkcd:matrix.org",
"",
"Test2:",
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"",
"Test3:",
"https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org",
"https://riot.im/app/#/room/#_foonetic_xkcd:matrix.org```",
"
",
"",
].join("\n");
const md = new Markdown("```" + testString + "```");
expect(md.toHTML()).toEqual(expectedResult);
});
it('expects that links with emphasis are "escaped" correctly', () => {
/* eslint-disable max-len */
const testString = [
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg" +
" " +
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg" +
" " +
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"https://example.com/_test_test2_-test3",
"https://example.com/_test_test2_test3_",
"https://example.com/_test__test2_test3_",
"https://example.com/_test__test2__test3_",
"https://example.com/_test__test2_test3__",
"https://example.com/_test__test2",
].join("\n");
const expectedResult = [
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg http://domain.xyz/foo/bar-_stuff-like-this_-in-it.jpg",
"https://example.com/_test_test2_-test3",
"https://example.com/_test_test2_test3_",
"https://example.com/_test__test2_test3_",
"https://example.com/_test__test2__test3_",
"https://example.com/_test__test2_test3__",
"https://example.com/_test__test2",
].join("