@@ -57,6 +57,12 @@ describe("CommonMark HTML blocks", () => {
5757 expect ( widgetsCss ) . toMatch (
5858 / \. P r o s e M i r r o r h t m l - b l o c k \. h t m l - b l o c k - p r e v i e w \{ \s + d i s p l a y : f l o w - r o o t ; \s + m a r g i n : 0 ; \s + p a d d i n g : 0 ; \s + \} / ,
5959 ) ;
60+ expect ( widgetsCss ) . toContain (
61+ ".ProseMirror html-block.html-source-open .html-block-source { margin-bottom: 10px; }" ,
62+ ) ;
63+ expect ( widgetsCss ) . not . toContain (
64+ ".ProseMirror html-block.html-source-open .html-block-preview { display: none; }" ,
65+ ) ;
6066 expect ( widgetsCss ) . not . toContain ( "min-height: 4.5em;" ) ;
6167 expect ( widgetsCss ) . not . toContain ( "margin: 8px 0 0;" ) ;
6268 expect ( widgetsCss ) . not . toContain ( "padding: 10px 12px;" ) ;
@@ -144,9 +150,11 @@ describe("CommonMark HTML blocks", () => {
144150
145151 expect ( block . classList . contains ( "html-source-open" ) ) . toBe ( true ) ;
146152 expect ( source ?. hidden ) . toBe ( false ) ;
153+ expect ( source ?. nextElementSibling ) . toBe ( block . querySelector ( ".html-block-preview" ) ) ;
147154 expect ( source ?. querySelector ( ".cm-editor.typora-web-html-source" ) ) . not . toBeNull ( ) ;
148155 expect ( source ?. textContent ) . toContain ( "<details>" ) ;
149156 expect ( source ?. querySelector ( "details" ) ) . toBeNull ( ) ;
157+ expect ( block . querySelector ( ".html-block-preview strong" ) ?. textContent ) . toBe ( "safe" ) ;
150158 } finally {
151159 cleanup ( ) ;
152160 }
@@ -223,4 +231,43 @@ describe("CommonMark HTML blocks", () => {
223231 cleanup ( ) ;
224232 }
225233 } ) ;
234+
235+ test ( "HTML image source edits keep a live preview with updated dimensions" , ( ) => {
236+ const { block, view, cleanup } = mountHtmlBlock (
237+ '<img src="favicon.svg" alt="Typora-Web logo" width="180" />' ,
238+ ) ;
239+
240+ try {
241+ const preview = block . querySelector < HTMLElement > ( ".html-block-preview" ) ;
242+ preview ?. dispatchEvent ( new MouseEvent ( "mousedown" , { bubbles : true , cancelable : true } ) ) ;
243+
244+ const source = block . querySelector < HTMLElement > ( "div.html-block-source" ) ;
245+ expect ( source ?. hidden ) . toBe ( false ) ;
246+ expect ( source ?. nextElementSibling ) . toBe ( preview ) ;
247+ expect ( preview ?. querySelector ( "img" ) ?. getAttribute ( "width" ) ) . toBe ( "180" ) ;
248+
249+ const editorView = htmlSourceEditor ( block ) ;
250+ const current = editorView . state . doc . toString ( ) ;
251+ editorView . dispatch ( {
252+ changes : {
253+ from : 0 ,
254+ to : current . length ,
255+ insert : '<img src="favicon.svg" alt="Typora-Web logo" width="96" />' ,
256+ } ,
257+ } ) ;
258+
259+ const image = preview ?. querySelector ( "img" ) ;
260+ expect ( image ?. getAttribute ( "src" ) ) . toBe ( "favicon.svg" ) ;
261+ expect ( image ?. getAttribute ( "alt" ) ) . toBe ( "Typora-Web logo" ) ;
262+ expect ( image ?. getAttribute ( "width" ) ) . toBe ( "96" ) ;
263+ expect ( block . dataset . raw ) . toBe (
264+ '<img src="favicon.svg" alt="Typora-Web logo" width="96" />' ,
265+ ) ;
266+ expect ( serialize ( view . state . doc ) ) . toBe (
267+ '<img src="favicon.svg" alt="Typora-Web logo" width="96" />' ,
268+ ) ;
269+ } finally {
270+ cleanup ( ) ;
271+ }
272+ } ) ;
226273} ) ;
0 commit comments