mirror of https://github.com/vector-im/riot-web
				
				
				
			Merge pull request #4694 from justin-sleep/remove-escape-backslashes
Remove escape backslashes in non-Markdown messagespull/21833/head
						commit
						803b7bb30f
					
				| 
						 | 
				
			
			@ -175,14 +175,6 @@ export default class Markdown {
 | 
			
		|||
        const renderer = new commonmark.HtmlRenderer({safe: false});
 | 
			
		||||
        const real_paragraph = renderer.paragraph;
 | 
			
		||||
 | 
			
		||||
        // The default `out` function only sends the input through an XML
 | 
			
		||||
        // escaping function, which causes messages to be entity encoded,
 | 
			
		||||
        // which we don't want in this case.
 | 
			
		||||
        renderer.out = function(s) {
 | 
			
		||||
            // The `lit` function adds a string literal to the output buffer.
 | 
			
		||||
            this.lit(s);
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        renderer.paragraph = function(node, entering) {
 | 
			
		||||
            // as with toHTML, only append lines to paragraphs if there are
 | 
			
		||||
            // multiple paragraphs
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,6 +42,10 @@ export function htmlSerializeIfNeeded(model: EditorModel, {forceHTML = false} =
 | 
			
		|||
    if (!parser.isPlainText() || forceHTML) {
 | 
			
		||||
        return parser.toHTML();
 | 
			
		||||
    }
 | 
			
		||||
    // ensure removal of escape backslashes in non-Markdown messages
 | 
			
		||||
    if (md.indexOf("\\") > -1) {
 | 
			
		||||
        return parser.toPlaintext();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function textSerialize(model: EditorModel) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -61,4 +61,16 @@ describe('editor/serialize', function() {
 | 
			
		|||
        const html = htmlSerializeIfNeeded(model, {});
 | 
			
		||||
        expect(html).toBe("<a href=\"https://matrix.to/#/@user:server\">Displayname]</a>");
 | 
			
		||||
    });
 | 
			
		||||
    it('escaped markdown should not retain backslashes', function() {
 | 
			
		||||
        const pc = createPartCreator();
 | 
			
		||||
        const model = new EditorModel([pc.plain('\\*hello\\* world')]);
 | 
			
		||||
        const html = htmlSerializeIfNeeded(model, {});
 | 
			
		||||
        expect(html).toBe('*hello* world');
 | 
			
		||||
    });
 | 
			
		||||
    it('escaped markdown should convert HTML entities', function() {
 | 
			
		||||
        const pc = createPartCreator();
 | 
			
		||||
        const model = new EditorModel([pc.plain('\\*hello\\* world < hey world!')]);
 | 
			
		||||
        const html = htmlSerializeIfNeeded(model, {});
 | 
			
		||||
        expect(html).toBe('*hello* world < hey world!');
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue