File tree Expand file tree Collapse file tree 3 files changed +64
-1
lines changed
cypress/e2e/4.image-rendering Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+
3+ describe ( 'Image rendering' , ( ) => {
4+
5+ const imageUrl = 'https://picsum.photos/id/237/150' ;
6+
7+ beforeEach ( ( ) => {
8+ cy . visit ( __dirname + '/index.html' ) ;
9+ cy . intercept ( 'GET' , imageUrl ) . as ( 'image' ) ;
10+ } ) ;
11+
12+ it ( 'must render an image inside the editor' , ( ) => {
13+ cy . get ( '.EasyMDEContainer' ) . should ( 'be.visible' ) ;
14+ cy . get ( '#textarea' ) . should ( 'not.be.visible' ) ;
15+
16+ cy . get ( '.EasyMDEContainer .CodeMirror' ) . type ( imageUrl ) ;
17+ cy . get ( '.EasyMDEContainer .CodeMirror' ) . type ( '{home}' ) ;
18+
19+ cy . wait ( '@image' ) ;
20+
21+ cy . get ( `.EasyMDEContainer [data-img-src="${ imageUrl } "]` ) . should ( 'be.visible' ) ;
22+
23+ cy . previewOn ( ) ;
24+
25+ cy . get ( '.EasyMDEContainer .editor-preview' ) . should ( 'contain.html' , `<p><img src="${ imageUrl } " alt="Dog!"></p>` ) ;
26+ } ) ;
27+
28+ it ( 'must be able to handle parentheses inside image alt text' , ( ) => {
29+ cy . get ( '.EasyMDEContainer' ) . should ( 'be.visible' ) ;
30+ cy . get ( '#textarea' ) . should ( 'not.be.visible' ) ;
31+
32+ cy . get ( '.EasyMDEContainer .CodeMirror' ) . type ( imageUrl ) ;
33+ cy . get ( '.EasyMDEContainer .CodeMirror' ) . type ( '{home}' ) ;
34+
35+ cy . wait ( '@image' ) ;
36+
37+ cy . get ( `.EasyMDEContainer [data-img-src="${ imageUrl } "]` ) . should ( 'be.visible' ) ;
38+
39+ cy . previewOn ( ) ;
40+
41+ cy . get ( '.EasyMDEContainer .editor-preview' ) . should ( 'contain.html' , `<p><img src="${ imageUrl } " alt="Dog! (He's a good boy!)"></p>` ) ;
42+ } ) ;
43+ } ) ;
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Default</ title >
7+ < link rel ="stylesheet " href ="../../../dist/easymde.min.css ">
8+ < script src ="../../../dist/easymde.min.js "> </ script >
9+ </ head >
10+
11+ < body >
12+ < textarea id ="textarea "> </ textarea >
13+ < script >
14+ const easyMDE = new EasyMDE ( {
15+ previewImagesInEditor : true ,
16+ } ) ;
17+ </ script >
18+ </ body >
19+
20+ </ html >
Original file line number Diff line number Diff line change @@ -2251,7 +2251,7 @@ EasyMDE.prototype.render = function (el) {
22512251 return ;
22522252 }
22532253 if ( ! parentEl . hasAttribute ( 'data-img-src' ) ) {
2254- var srcAttr = parentEl . innerText . match ( '\\ ((.*)\\)' ) ; // might require better parsing according to markdown spec
2254+ var srcAttr = parentEl . innerText . match ( / ! \[ . * ? \] \ (( .* ? ) \) / ) ; // might require better parsing according to markdown spec
22552255 if ( ! window . EMDEimagesCache ) {
22562256 window . EMDEimagesCache = { } ;
22572257 }
You can’t perform that action at this time.
0 commit comments