@diplodoc/transform 4.77.11 → 4.77.12

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.
@@ -155,6 +155,11 @@ function collectDataAttrs(
155
155
  continue;
156
156
  }
157
157
 
158
+ if (key === 'gallery-id' && value !== '') {
159
+ result['data-gallery-id'] = value;
160
+ continue;
161
+ }
162
+
158
163
  const gallerySrc = resolveGallerySrcAttr(
159
164
  key,
160
165
  value,
@@ -173,6 +178,7 @@ function collectDataAttrs(
173
178
  if (
174
179
  key.startsWith('data-') &&
175
180
  key !== 'data-gallery-src' &&
181
+ (key !== 'data-gallery-id' || value !== '') &&
176
182
  (key !== 'data-gallery' || isGalleryValid(value))
177
183
  ) {
178
184
  result[key] = value;
@@ -182,10 +188,17 @@ function collectDataAttrs(
182
188
  image.attrs = image.attrs.filter(
183
189
  ([key, value]) =>
184
190
  key !== 'gallery' &&
191
+ key !== 'gallery-id' &&
185
192
  key !== 'gallery-src' &&
186
193
  (key !== 'data-gallery' || isGalleryValid(value)) &&
194
+ (key !== 'data-gallery-id' || value !== '') &&
187
195
  (key !== 'data-gallery-src' || value !== ''),
188
196
  );
197
+
198
+ if (result['data-gallery-id']) {
199
+ result['data-gallery'] = 'true';
200
+ }
201
+
189
202
  return result;
190
203
  }
191
204
 
@@ -307,19 +307,26 @@ function isOwnAttr(key: string): boolean {
307
307
  key === 'height' ||
308
308
  key === 'inline' ||
309
309
  key === 'gallery' ||
310
+ key === 'gallery-id' ||
310
311
  key === 'gallery-src' ||
311
312
  key.startsWith('data-')
312
313
  );
313
314
  }
314
315
 
315
316
  function resolveDataAttr(key: string, value: string): [string, string] | null {
316
- const isGalleryValid = value === 'true' || value === 'false';
317
+ if (key === 'gallery' || key === 'data-gallery') {
318
+ const isGalleryValid = value === 'true' || value === 'false';
317
319
 
318
- if (key === 'gallery') return isGalleryValid ? ['data-gallery', value] : null;
319
- if (key === 'data-gallery') return isGalleryValid ? [key, value] : null;
320
- if (key === 'gallery-src') return value === '' ? null : ['data-gallery-src', value];
321
- if (key.startsWith('data-')) return [key, value];
322
- return null;
320
+ return isGalleryValid ? ['data-gallery', value] : null;
321
+ }
322
+
323
+ if (key === 'gallery-id' || key === 'gallery-src') {
324
+ if (value === '') return null;
325
+
326
+ return [`data-${key}`, value];
327
+ }
328
+
329
+ return key.startsWith('data-') ? [key, value] : null;
323
330
  }
324
331
 
325
332
  function parseInlineAttributes(attrsStr: string): ParsedAttrs {
@@ -358,6 +365,10 @@ function parseInlineAttributes(attrsStr: string): ParsedAttrs {
358
365
  }
359
366
  }
360
367
 
368
+ if (result.dataAttrs?.['data-gallery-id']) {
369
+ result.dataAttrs['data-gallery'] = 'true';
370
+ }
371
+
361
372
  // The block is fully ours only if it carries our attributes and nothing
362
373
  // foreign is left over — otherwise someone downstream has to parse it.
363
374
  result.foreign = own === 0 || ownChars !== dense(attrsStr);