remark-break-line 0.0.3 → 0.0.4

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.
Files changed (2) hide show
  1. package/lib/index.js +22 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -33,7 +33,7 @@ const elementSize = {
33
33
  * @returns
34
34
  * Transform.
35
35
  */
36
- export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
36
+ export default function remarkBreakLongLines({ maxLineLength = 80, removeLinebreaks = false } = {}) {
37
37
  /**
38
38
  * Transform.
39
39
  *
@@ -47,6 +47,24 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
47
47
  if (node.type === 'paragraph') {
48
48
  const baseIndention = (node.position?.start.column ?? 1) - 1;
49
49
  let currentLine = 0
50
+
51
+ /**
52
+ *
53
+ * @param {typeof node.children[number]} n
54
+ */
55
+ const prepare = (n) => {
56
+ if (n.type === 'text' && n.value.length > 0) {
57
+ n.value = n.value.replaceAll('\n', ' ').replace(/ {2..}/g, ' ');
58
+ } else if ('children' in n) {
59
+ for (let i = 0; i < n.children.length; i++) {
60
+ const element = n.children[i]
61
+ if (element.type in elementSize) {
62
+ prepare(element);
63
+ }
64
+ }
65
+ }
66
+ };
67
+
50
68
  /**
51
69
  *
52
70
  * @param {typeof node.children[number]} n
@@ -211,7 +229,9 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
211
229
  }
212
230
 
213
231
  for (let i = 0; i < node.children.length; i++) {
214
- const element = node.children[i]
232
+ const element = node.children[i];
233
+ if (removeLinebreaks)
234
+ prepare(element);
215
235
  const result = walk(element, [element.type])
216
236
  if (result.type == 'split') {
217
237
  currentLine = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-break-line",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "keywords": [