@@ -5,7 +5,11 @@ import type Token from 'markdown-it/lib/token';
5
5
import { ImsizeAttr } from './const' ;
6
6
import { parseImageSize } from './helpers' ;
7
7
8
- export const imageWithSize = ( md : MarkdownIt ) : ParserInline . RuleInline => {
8
+ export type ImsizeOptions = {
9
+ inlineSizeStyling ?: boolean ;
10
+ } ;
11
+
12
+ export const imageWithSize = ( md : MarkdownIt , opts ?: ImsizeOptions ) : ParserInline . RuleInline => {
9
13
// eslint-disable-next-line complexity
10
14
return ( state , silent ) => {
11
15
if ( state . src . charCodeAt ( state . pos ) !== 0x21 /* ! */ ) {
@@ -207,27 +211,29 @@ export const imageWithSize = (md: MarkdownIt): ParserInline.RuleInline => {
207
211
token . attrs . push ( [ ImsizeAttr . Height , height ] ) ;
208
212
}
209
213
210
- let style : string | undefined = '' ;
214
+ if ( opts ?. inlineSizeStyling ) {
215
+ let style : string | undefined = '' ;
211
216
212
- const widthWithPercent = width . includes ( '%' ) ;
213
- const heightWithPercent = height . includes ( '%' ) ;
217
+ const widthWithPercent = width . includes ( '%' ) ;
218
+ const heightWithPercent = height . includes ( '%' ) ;
214
219
215
- if ( width !== '' ) {
216
- const widthString = widthWithPercent ? width : `${ width } px` ;
217
- style += `width: ${ widthString } ;` ;
218
- }
220
+ if ( width !== '' ) {
221
+ const widthString = widthWithPercent ? width : `${ width } px` ;
222
+ style += `width: ${ widthString } ;` ;
223
+ }
219
224
220
- if ( height !== '' ) {
221
- if ( width !== '' && ! heightWithPercent && ! widthWithPercent ) {
222
- style += `aspect-ratio: ${ width } / ${ height } ;height: auto;` ;
223
- } else {
224
- const heightString = heightWithPercent ? height : `${ height } px` ;
225
- style += `height: ${ heightString } ;` ;
225
+ if ( height !== '' ) {
226
+ if ( width !== '' && ! heightWithPercent && ! widthWithPercent ) {
227
+ style += `aspect-ratio: ${ width } / ${ height } ;height: auto;` ;
228
+ } else {
229
+ const heightString = heightWithPercent ? height : `${ height } px` ;
230
+ style += `height: ${ heightString } ;` ;
231
+ }
226
232
}
227
- }
228
233
229
- if ( style ) {
230
- token . attrs . push ( [ ImsizeAttr . Style , style ] ) ;
234
+ if ( style ) {
235
+ token . attrs . push ( [ ImsizeAttr . Style , style ] ) ;
236
+ }
231
237
}
232
238
}
233
239
0 commit comments