@diplodoc/transform 4.77.10 → 4.77.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -235,7 +235,13 @@ export const imageWithSize = (md: MarkdownIt, opts?: ImsizeOptions): ParserInlin
235
235
  }
236
236
  }
237
237
 
238
- pos = bracePos + 1;
238
+ // Consume the block only when it belongs to imsize entirely.
239
+ // Otherwise leave its source text in the token stream: it still
240
+ // has to be seen by markdown-it-attrs and by the @diplodoc/translation
241
+ // skeleton, which extracts the translatable title from it.
242
+ if (!result.foreign) {
243
+ pos = bracePos + 1;
244
+ }
239
245
  }
240
246
  }
241
247
 
@@ -290,14 +296,28 @@ type ParsedAttrs = {
290
296
  height: string;
291
297
  inline: string;
292
298
  dataAttrs?: Record<string, string>;
299
+ // true when the {...} block holds anything imsize does not own:
300
+ // a foreign key (title=...) or free-form content like markdown-it-attrs' {.class}.
301
+ foreign: boolean;
293
302
  };
294
303
 
304
+ function isOwnAttr(key: string): boolean {
305
+ return (
306
+ key === 'width' ||
307
+ key === 'height' ||
308
+ key === 'inline' ||
309
+ key === 'gallery' ||
310
+ key === 'gallery-src' ||
311
+ key.startsWith('data-')
312
+ );
313
+ }
314
+
295
315
  function resolveDataAttr(key: string, value: string): [string, string] | null {
296
316
  const isGalleryValid = value === 'true' || value === 'false';
297
317
 
298
318
  if (key === 'gallery') return isGalleryValid ? ['data-gallery', value] : null;
299
319
  if (key === 'data-gallery') return isGalleryValid ? [key, value] : null;
300
- if (key === 'gallery-src') return value !== '' ? ['data-gallery-src', value] : null;
320
+ if (key === 'gallery-src') return value === '' ? null : ['data-gallery-src', value];
301
321
  if (key.startsWith('data-')) return [key, value];
302
322
  return null;
303
323
  }
@@ -305,8 +325,11 @@ function resolveDataAttr(key: string, value: string): [string, string] | null {
305
325
  function parseInlineAttributes(attrsStr: string): ParsedAttrs {
306
326
  // Parse key=value pairs
307
327
  const attrRegex = /([\w-]+)=(?:'([^']*)'|"([^"]*)"|(\S+))/g;
308
- const result: ParsedAttrs = {width: '', height: '', inline: '', dataAttrs: {}};
328
+ const result: ParsedAttrs = {width: '', height: '', inline: '', dataAttrs: {}, foreign: false};
329
+ const dense = (str: string) => str.replace(/\s+/g, '').length;
309
330
  let match;
331
+ let own = 0;
332
+ let ownChars = 0;
310
333
 
311
334
  while ((match = attrRegex.exec(attrsStr)) !== null) {
312
335
  const key = match[1];
@@ -316,6 +339,13 @@ function parseInlineAttributes(attrsStr: string): ParsedAttrs {
316
339
  value = value.slice(0, -1);
317
340
  }
318
341
 
342
+ if (!isOwnAttr(key)) {
343
+ continue;
344
+ }
345
+
346
+ own++;
347
+ ownChars += dense(match[0]);
348
+
319
349
  if (key === 'width' || key === 'height' || key === 'inline') {
320
350
  result[key] = value;
321
351
  continue;
@@ -327,5 +357,10 @@ function parseInlineAttributes(attrsStr: string): ParsedAttrs {
327
357
  result.dataAttrs[resolved[0]] = resolved[1];
328
358
  }
329
359
  }
360
+
361
+ // The block is fully ours only if it carries our attributes and nothing
362
+ // foreign is left over — otherwise someone downstream has to parse it.
363
+ result.foreign = own === 0 || ownChars !== dense(attrsStr);
364
+
330
365
  return result;
331
366
  }