@adobe/helix-markdown-support 4.0.4 → 5.0.2

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,29 @@
1
+ ## [5.0.2](https://github.com/adobe/helix-markdown-support/compare/v5.0.1...v5.0.2) (2022-09-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * clean more breaks ([#137](https://github.com/adobe/helix-markdown-support/issues/137)) ([a6f9d37](https://github.com/adobe/helix-markdown-support/commit/a6f9d372eb040ad0980e681f7deb5dbe694ee7f4))
7
+
8
+ ## [5.0.1](https://github.com/adobe/helix-markdown-support/compare/v5.0.0...v5.0.1) (2022-09-06)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove trailing breaks ([d08b6fc](https://github.com/adobe/helix-markdown-support/commit/d08b6fcded991f054b30da04298a489091d38cf7))
14
+
15
+ # [5.0.0](https://github.com/adobe/helix-markdown-support/compare/v4.0.4...v5.0.0) (2022-09-06)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * remove breaksAsSpaces ([e6bb665](https://github.com/adobe/helix-markdown-support/commit/e6bb665930ce39876228aff9cd9bec842ed5030b))
21
+
22
+
23
+ ### BREAKING CHANGES
24
+
25
+ * breaksAsSpaces removed. no longer needed.
26
+
1
27
  ## [4.0.4](https://github.com/adobe/helix-markdown-support/compare/v4.0.3...v4.0.4) (2022-09-06)
2
28
 
3
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-markdown-support",
3
- "version": "4.0.4",
3
+ "version": "5.0.2",
4
4
  "description": "Helix Markdown Support",
5
5
  "type": "module",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -11,7 +11,6 @@
11
11
  */
12
12
 
13
13
  export { default as robustTables } from './mdast-robust-tables.js';
14
- export { default as breaksAsSpaces } from './remark-breaks-as-spaces.js';
15
14
  export { default as sanitizeHeading } from './mdast-sanitize-heading.js';
16
15
  export { default as suppressSpaceCode } from './mdast-suppress-spacecode.js';
17
16
  export { default as sanitizeFormats } from './mdast-sanitize-formats.js';
@@ -51,18 +51,14 @@ export default function sanitizeHeading(tree, opts = {}) {
51
51
  }
52
52
  }
53
53
 
54
- // move leading breaks before heading
54
+ // remove leading breaks
55
55
  while (children[0]?.type === 'break') {
56
- const brk = children.shift();
57
- siblings.splice(index, 0, brk);
58
- // eslint-disable-next-line no-param-reassign
59
- index += 1;
56
+ children.shift();
60
57
  }
61
- // move trailing breaks after heading
58
+ // remove trailing breaks
62
59
  let last = children.length - 1;
63
60
  while (children[last]?.type === 'break') {
64
- const brk = children.pop();
65
- siblings.splice(index + 1, 0, brk);
61
+ children.pop();
66
62
  last -= 1;
67
63
  }
68
64
  // convert inline breaks to <br>
@@ -18,6 +18,9 @@ import { visit, CONTINUE } from 'unist-util-visit';
18
18
  * - trims ends of texts at the end
19
19
  * - moves leading and trailing whitespaces out of formats
20
20
  * - removes leading whitespaces before images
21
+ * - removes trailing breaks in containers
22
+ * see https://github.com/micromark/micromark/issues/118#issuecomment-1238225086
23
+ * - removes empty paragraphs
21
24
  *
22
25
  * @param {object} tree
23
26
  * @returns {object} The modified (original) tree.
@@ -92,8 +95,13 @@ export default function sanitizeText(tree) {
92
95
  return index - 1;
93
96
  }
94
97
  }
95
- // remove trailing whitespace before break blocks
98
+ // remove trailing whitespace before break blocks and trailing breaks altogether
96
99
  if (node.type === 'break') {
100
+ if (index === siblings.length - 1) {
101
+ siblings.splice(index, 1);
102
+ return index - 1;
103
+ }
104
+
97
105
  // eslint-disable-next-line no-param-reassign
98
106
  delete node.value;
99
107
  if (index > 0) {
@@ -109,5 +117,15 @@ export default function sanitizeText(tree) {
109
117
  }
110
118
  return CONTINUE;
111
119
  });
120
+
121
+ // remove empty paragraphs
122
+ visit(tree, (node, index, parent) => {
123
+ if (node.type === 'paragraph' && node.children.length === 0) {
124
+ parent.children.splice(index, 1);
125
+ return index - 1;
126
+ }
127
+ return CONTINUE;
128
+ });
129
+
112
130
  return tree;
113
131
  }
@@ -1,33 +0,0 @@
1
- /*
2
- * Copyright 2020 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License. You may obtain a copy
5
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
- *
7
- * Unless required by applicable law or agreed to in writing, software distributed under
8
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
- * OF ANY KIND, either express or implied. See the License for the specific language
10
- * governing permissions and limitations under the License.
11
- */
12
-
13
- /**
14
- * Remark extension that handles soft-breaks correctly.
15
- */
16
- export default function softBreak() {
17
- function handleBreak(node, _, context) {
18
- if (context.stack.indexOf('tableCell') !== -1) {
19
- return ' ';
20
- } else {
21
- return ' \n';
22
- }
23
- }
24
-
25
- if (!this.data('toMarkdownExtensions')) {
26
- this.data('toMarkdownExtensions', []);
27
- }
28
- this.data('toMarkdownExtensions').push({
29
- handlers: {
30
- break: handleBreak,
31
- },
32
- });
33
- }