@@ -2,6 +2,7 @@ import { exists as _exists } from 'fs';
22import _imageSize from 'image-size' ;
33import { HTML , Image } from 'mdast' ;
44import { basename , resolve } from 'path' ;
5+ import { expect } from 'ts-std' ;
56import { promisify } from 'util' ;
67import BaseWalker from '../../walker' ;
78import Options from './options' ;
@@ -38,9 +39,14 @@ function attr(v: unknown): string {
3839
3940
4041async function toImgTag ( node : Image , options : Options ) : Promise < HTML > {
41- let size = await imageSize ( pathFor ( node . url , options ) ) ;
42- let width = Math . floor ( size ! . width ! / 2 ) ;
43- let height = Math . floor ( size ! . height ! / 2 ) ;
42+ let sizeOfImage = await imageSize ( pathFor ( node . url , options ) ) ;
43+
44+ let size = expect ( sizeOfImage , 'size should be present' ) ;
45+ let width = expect ( size . width , 'width should be present' ) ;
46+ let height = expect ( size . height , 'height should be present' ) ;
47+
48+ let widthAttr = Math . floor ( width / 2 ) ;
49+ let heightAttr = Math . floor ( height / 2 ) ;
4450
4551 let attrs = [ ] ;
4652
@@ -54,8 +60,8 @@ async function toImgTag(node: Image, options: Options): Promise<HTML> {
5460 attrs . push ( `title=${ attr ( node . title ) } ` ) ;
5561 }
5662
57- attrs . push ( `width=${ attr ( width ) } ` ) ;
58- attrs . push ( `height=${ attr ( height ) } ` ) ;
63+ attrs . push ( `width=${ attr ( widthAttr ) } ` ) ;
64+ attrs . push ( `height=${ attr ( heightAttr ) } ` ) ;
5965
6066 return {
6167 type : 'html' ,
0 commit comments