@adobe/helix-markdown-support 4.0.0 → 4.0.1

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [4.0.1](https://github.com/adobe/helix-markdown-support/compare/v4.0.0...v4.0.1) (2022-09-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * clean cell contents ([#131](https://github.com/adobe/helix-markdown-support/issues/131)) ([f422e97](https://github.com/adobe/helix-markdown-support/commit/f422e97ac0094f0c3448eba88c68476c8f3415cd))
7
+
1
8
  # [4.0.0](https://github.com/adobe/helix-markdown-support/compare/v3.1.8...v4.0.0) (2022-09-02)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "4.0.0",
3
+ "version": "4.0.1",
4
4
  "description": "Helix Markdown Support",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -10,6 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  import { all } from 'mdast-util-to-hast';
13
+ import { CONTINUE, SKIP, visit } from 'unist-util-visit';
13
14
  import {
14
15
  TYPE_BODY, TYPE_CELL, TYPE_FOOTER, TYPE_HEADER, TYPE_ROW,
15
16
  } from './types.js';
@@ -33,7 +34,24 @@ function handleRow(h, node, cellElementName) {
33
34
  props[p] = child[p];
34
35
  }
35
36
  }
36
- cells.push(h(child, cellElementName, props, all(h, child)));
37
+ // if cell contains only 1 single paragraph, unwrap it
38
+ if (child.children?.length === 1 && child.children[0].type === 'paragraph') {
39
+ child.children = child.children[0].children;
40
+ }
41
+ const cell = h(child, cellElementName, props, all(h, child));
42
+ cells.push(cell);
43
+
44
+ // clean text elements
45
+ visit(cell, (n) => {
46
+ if (n.tagName === 'code') {
47
+ return SKIP;
48
+ }
49
+ if (n.type === 'text') {
50
+ // eslint-disable-next-line no-param-reassign
51
+ n.value = n.value.replace(/\r?\n/mg, ' ');
52
+ }
53
+ return CONTINUE;
54
+ });
37
55
  }
38
56
  }
39
57