@diplodoc/transform 4.20.0 → 4.22.0

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.
@@ -1,7 +1,7 @@
1
1
  import StateBlock from 'markdown-it/lib/rules_block/state_block';
2
2
  import {MarkdownItPluginCb} from '../typings';
3
3
  import Token from 'markdown-it/lib/token';
4
- import {parseAttrsClass} from './utils';
4
+ import {AttrsParser} from './attrs';
5
5
 
6
6
  const pluginName = 'yfm_table';
7
7
  const pipeChar = 0x7c; // |
@@ -96,6 +96,7 @@ class StateIterator {
96
96
  interface RowPositions {
97
97
  rows: [number, number, [Stats, Stats][]][];
98
98
  endOfTable: number | null;
99
+ pos: number;
99
100
  }
100
101
 
101
102
  function getTableRowPositions(
@@ -214,7 +215,19 @@ function getTableRowPositions(
214
215
 
215
216
  iter.next();
216
217
  }
217
- return {rows, endOfTable};
218
+
219
+ const {pos} = iter;
220
+
221
+ return {rows, endOfTable, pos};
222
+ }
223
+
224
+ function extractAttributes(state: StateBlock, pos: number): Record<string, string[]> {
225
+ const attrsStringStart = state.skipSpaces(pos);
226
+ const attrsString = state.src.slice(attrsStringStart);
227
+
228
+ const attrsParser = new AttrsParser();
229
+
230
+ return attrsParser.parse(attrsString);
218
231
  }
219
232
 
220
233
  /**
@@ -232,7 +245,10 @@ function extractAndApplyClassFromToken(contentToken: Token, tdOpenToken: Token):
232
245
  if (!allAttrs) {
233
246
  return;
234
247
  }
235
- const attrsClass = parseAttrsClass(allAttrs[0].trim());
248
+
249
+ const attrs = new AttrsParser().parse(allAttrs[0].trim());
250
+ const attrsClass = attrs?.class?.join(' ');
251
+
236
252
  if (attrsClass) {
237
253
  tdOpenToken.attrSet('class', attrsClass);
238
254
  // remove the class from the token so that it's not propagated to tr or table level
@@ -363,13 +379,15 @@ const yfmTable: MarkdownItPluginCb = (md) => {
363
379
  return true;
364
380
  }
365
381
 
366
- const {rows, endOfTable} = getTableRowPositions(
382
+ const {rows, endOfTable, pos} = getTableRowPositions(
367
383
  state,
368
384
  startPosition,
369
385
  endPosition,
370
386
  startLine,
371
387
  );
372
388
 
389
+ const attrs = extractAttributes(state, pos);
390
+
373
391
  if (!endOfTable) {
374
392
  token = state.push('__yfm_lint', '', 0);
375
393
  token.hidden = true;
@@ -385,6 +403,16 @@ const yfmTable: MarkdownItPluginCb = (md) => {
385
403
 
386
404
  const tableStart = state.tokens.length;
387
405
  token = state.push('yfm_table_open', 'table', 1);
406
+
407
+ const {attr: singleKeyAttrs = [], ...fullAttrs} = attrs;
408
+ for (const [property, values] of Object.entries(fullAttrs)) {
409
+ token.attrJoin(property, values.join(' '));
410
+ }
411
+
412
+ for (const attr of singleKeyAttrs) {
413
+ token.attrJoin(attr, 'true');
414
+ }
415
+
388
416
  token.map = [startLine, endOfTable];
389
417
 
390
418
  token = state.push('yfm_tbody_open', 'tbody', 1);
@@ -288,6 +288,7 @@ const htmlAttrs = [
288
288
  'referrerpolicy',
289
289
  'aria-describedby',
290
290
  'data-*',
291
+ 'wide-content',
291
292
  ];
292
293
 
293
294
  const svgAttrs = [
@@ -1,8 +0,0 @@
1
- /**
2
- * Parse the markdown-attrs format to retrieve a class name
3
- * Putting all the requirements in regex was more complicated than parsing a string char by char.
4
- *
5
- * @param {string} inputString - The string to parse.
6
- * @returns {string|null} - The extracted class or null if there is none
7
- */
8
- export declare function parseAttrsClass(inputString: string): string | null;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- /**
3
- * Parse the markdown-attrs format to retrieve a class name
4
- * Putting all the requirements in regex was more complicated than parsing a string char by char.
5
- *
6
- * @param {string} inputString - The string to parse.
7
- * @returns {string|null} - The extracted class or null if there is none
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.parseAttrsClass = void 0;
11
- function parseAttrsClass(inputString) {
12
- const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .=-_';
13
- if (!inputString.startsWith('{')) {
14
- return null;
15
- }
16
- for (let i = 1; i < inputString.length; i++) {
17
- const char = inputString[i];
18
- if (char === '}') {
19
- const contentInside = inputString.slice(1, i).trim(); // content excluding { and }
20
- if (!contentInside) {
21
- return null;
22
- }
23
- const parts = contentInside.split('.');
24
- if (parts.length !== 2 || !parts[1]) {
25
- return null;
26
- }
27
- //There should be a preceding whitespace
28
- if (!parts[0].endsWith(' ') && parts[0] !== '') {
29
- return null;
30
- }
31
- return parts[1];
32
- }
33
- if (!validChars.includes(char)) {
34
- return null;
35
- }
36
- }
37
- return null;
38
- }
39
- exports.parseAttrsClass = parseAttrsClass;
40
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transform/plugins/table/utils.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,SAAgB,eAAe,CAAC,WAAmB;IAC/C,MAAM,UAAU,GAAG,2DAA2D,CAAC;IAE/E,IAAI,CAAC,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,OAAO,IAAI,CAAC;KACf;IAED,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACzC,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QAE5B,IAAI,IAAI,KAAK,GAAG,EAAE;YACd,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,4BAA4B;YAElF,IAAI,CAAC,aAAa,EAAE;gBAChB,OAAO,IAAI,CAAC;aACf;YAED,MAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACvC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACjC,OAAO,IAAI,CAAC;aACf;YACD,wCAAwC;YACxC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC5C,OAAO,IAAI,CAAC;aACf;YAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;SACnB;QAED,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC;SACf;KACJ;IAED,OAAO,IAAI,CAAC;AAChB,CAAC;AAnCD,0CAmCC"}
@@ -1,44 +0,0 @@
1
- /**
2
- * Parse the markdown-attrs format to retrieve a class name
3
- * Putting all the requirements in regex was more complicated than parsing a string char by char.
4
- *
5
- * @param {string} inputString - The string to parse.
6
- * @returns {string|null} - The extracted class or null if there is none
7
- */
8
-
9
- export function parseAttrsClass(inputString: string): string | null {
10
- const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .=-_';
11
-
12
- if (!inputString.startsWith('{')) {
13
- return null;
14
- }
15
-
16
- for (let i = 1; i < inputString.length; i++) {
17
- const char = inputString[i];
18
-
19
- if (char === '}') {
20
- const contentInside = inputString.slice(1, i).trim(); // content excluding { and }
21
-
22
- if (!contentInside) {
23
- return null;
24
- }
25
-
26
- const parts = contentInside.split('.');
27
- if (parts.length !== 2 || !parts[1]) {
28
- return null;
29
- }
30
- //There should be a preceding whitespace
31
- if (!parts[0].endsWith(' ') && parts[0] !== '') {
32
- return null;
33
- }
34
-
35
- return parts[1];
36
- }
37
-
38
- if (!validChars.includes(char)) {
39
- return null;
40
- }
41
- }
42
-
43
- return null;
44
- }