@@ -19,58 +19,80 @@ import { htmlSerializeIfNeeded } from "../../src/editor/serialize";
1919import { createPartCreator } from "./mock" ;
2020
2121describe ( 'editor/serialize' , function ( ) {
22- it ( 'user pill turns message into html' , function ( ) {
23- const pc = createPartCreator ( ) ;
24- const model = new EditorModel ( [ pc . userPill ( "Alice" , "@alice:hs.tld" ) ] , pc ) ;
25- const html = htmlSerializeIfNeeded ( model , { } ) ;
26- expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@alice:hs.tld\">Alice</a>" ) ;
22+ describe ( 'with markdown' , function ( ) {
23+ it ( 'user pill turns message into html' , function ( ) {
24+ const pc = createPartCreator ( ) ;
25+ const model = new EditorModel ( [ pc . userPill ( "Alice" , "@alice:hs.tld" ) ] , pc ) ;
26+ const html = htmlSerializeIfNeeded ( model , { } ) ;
27+ expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@alice:hs.tld\">Alice</a>" ) ;
28+ } ) ;
29+ it ( 'room pill turns message into html' , function ( ) {
30+ const pc = createPartCreator ( ) ;
31+ const model = new EditorModel ( [ pc . roomPill ( "#room:hs.tld" ) ] , pc ) ;
32+ const html = htmlSerializeIfNeeded ( model , { } ) ;
33+ expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/#room:hs.tld\">#room:hs.tld</a>" ) ;
34+ } ) ;
35+ it ( '@room pill turns message into html' , function ( ) {
36+ const pc = createPartCreator ( ) ;
37+ const model = new EditorModel ( [ pc . atRoomPill ( "@room" ) ] , pc ) ;
38+ const html = htmlSerializeIfNeeded ( model , { } ) ;
39+ expect ( html ) . toBeFalsy ( ) ;
40+ } ) ;
41+ it ( 'any markdown turns message into html' , function ( ) {
42+ const pc = createPartCreator ( ) ;
43+ const model = new EditorModel ( [ pc . plain ( "*hello* world" ) ] , pc ) ;
44+ const html = htmlSerializeIfNeeded ( model , { } ) ;
45+ expect ( html ) . toBe ( "<em>hello</em> world" ) ;
46+ } ) ;
47+ it ( 'displaynames ending in a backslash work' , function ( ) {
48+ const pc = createPartCreator ( ) ;
49+ const model = new EditorModel ( [ pc . userPill ( "Displayname\\" , "@user:server" ) ] , pc ) ;
50+ const html = htmlSerializeIfNeeded ( model , { } ) ;
51+ expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname\\</a>" ) ;
52+ } ) ;
53+ it ( 'displaynames containing an opening square bracket work' , function ( ) {
54+ const pc = createPartCreator ( ) ;
55+ const model = new EditorModel ( [ pc . userPill ( "Displayname[[" , "@user:server" ) ] , pc ) ;
56+ const html = htmlSerializeIfNeeded ( model , { } ) ;
57+ expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname[[</a>" ) ;
58+ } ) ;
59+ it ( 'displaynames containing a closing square bracket work' , function ( ) {
60+ const pc = createPartCreator ( ) ;
61+ const model = new EditorModel ( [ pc . userPill ( "Displayname]" , "@user:server" ) ] , pc ) ;
62+ const html = htmlSerializeIfNeeded ( model , { } ) ;
63+ expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname]</a>" ) ;
64+ } ) ;
65+ it ( 'escaped markdown should not retain backslashes' , function ( ) {
66+ const pc = createPartCreator ( ) ;
67+ const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world' ) ] , pc ) ;
68+ const html = htmlSerializeIfNeeded ( model , { } ) ;
69+ expect ( html ) . toBe ( '*hello* world' ) ;
70+ } ) ;
71+ it ( 'escaped markdown should convert HTML entities' , function ( ) {
72+ const pc = createPartCreator ( ) ;
73+ const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world < hey world!' ) ] , pc ) ;
74+ const html = htmlSerializeIfNeeded ( model , { } ) ;
75+ expect ( html ) . toBe ( '*hello* world < hey world!' ) ;
76+ } ) ;
2777 } ) ;
28- it ( 'room pill turns message into html' , function ( ) {
29- const pc = createPartCreator ( ) ;
30- const model = new EditorModel ( [ pc . roomPill ( "#room:hs.tld" ) ] , pc ) ;
31- const html = htmlSerializeIfNeeded ( model , { } ) ;
32- expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/#room:hs.tld\">#room:hs.tld</a>" ) ;
33- } ) ;
34- it ( '@room pill turns message into html' , function ( ) {
35- const pc = createPartCreator ( ) ;
36- const model = new EditorModel ( [ pc . atRoomPill ( "@room" ) ] , pc ) ;
37- const html = htmlSerializeIfNeeded ( model , { } ) ;
38- expect ( html ) . toBeFalsy ( ) ;
39- } ) ;
40- it ( 'any markdown turns message into html' , function ( ) {
41- const pc = createPartCreator ( ) ;
42- const model = new EditorModel ( [ pc . plain ( "*hello* world" ) ] , pc ) ;
43- const html = htmlSerializeIfNeeded ( model , { } ) ;
44- expect ( html ) . toBe ( "<em>hello</em> world" ) ;
45- } ) ;
46- it ( 'displaynames ending in a backslash work' , function ( ) {
47- const pc = createPartCreator ( ) ;
48- const model = new EditorModel ( [ pc . userPill ( "Displayname\\" , "@user:server" ) ] , pc ) ;
49- const html = htmlSerializeIfNeeded ( model , { } ) ;
50- expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname\\</a>" ) ;
51- } ) ;
52- it ( 'displaynames containing an opening square bracket work' , function ( ) {
53- const pc = createPartCreator ( ) ;
54- const model = new EditorModel ( [ pc . userPill ( "Displayname[[" , "@user:server" ) ] , pc ) ;
55- const html = htmlSerializeIfNeeded ( model , { } ) ;
56- expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname[[</a>" ) ;
57- } ) ;
58- it ( 'displaynames containing a closing square bracket work' , function ( ) {
59- const pc = createPartCreator ( ) ;
60- const model = new EditorModel ( [ pc . userPill ( "Displayname]" , "@user:server" ) ] , pc ) ;
61- const html = htmlSerializeIfNeeded ( model , { } ) ;
62- expect ( html ) . toBe ( "<a href=\"https://matrix.to/#/@user:server\">Displayname]</a>" ) ;
63- } ) ;
64- it ( 'escaped markdown should not retain backslashes' , function ( ) {
65- const pc = createPartCreator ( ) ;
66- const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world' ) ] , pc ) ;
67- const html = htmlSerializeIfNeeded ( model , { } ) ;
68- expect ( html ) . toBe ( '*hello* world' ) ;
69- } ) ;
70- it ( 'escaped markdown should convert HTML entities' , function ( ) {
71- const pc = createPartCreator ( ) ;
72- const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world < hey world!' ) ] , pc ) ;
73- const html = htmlSerializeIfNeeded ( model , { } ) ;
74- expect ( html ) . toBe ( '*hello* world < hey world!' ) ;
78+ describe ( 'with plaintext' , function ( ) {
79+ it ( 'markdown remains plaintext' , function ( ) {
80+ const pc = createPartCreator ( ) ;
81+ const model = new EditorModel ( [ pc . plain ( "*hello* world" ) ] , pc ) ;
82+ const html = htmlSerializeIfNeeded ( model , { useMarkdown : false } ) ;
83+ expect ( html ) . toBe ( "*hello* world" ) ;
84+ } ) ;
85+ it ( 'markdown should retain backslashes' , function ( ) {
86+ const pc = createPartCreator ( ) ;
87+ const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world' ) ] , pc ) ;
88+ const html = htmlSerializeIfNeeded ( model , { useMarkdown : false } ) ;
89+ expect ( html ) . toBe ( '\\*hello\\* world' ) ;
90+ } ) ;
91+ it ( 'markdown should convert HTML entities' , function ( ) {
92+ const pc = createPartCreator ( ) ;
93+ const model = new EditorModel ( [ pc . plain ( '\\*hello\\* world < hey world!' ) ] , pc ) ;
94+ const html = htmlSerializeIfNeeded ( model , { useMarkdown : false } ) ;
95+ expect ( html ) . toBe ( '\\*hello\\* world < hey world!' ) ;
96+ } ) ;
7597 } ) ;
7698} ) ;
0 commit comments