remark-break-line 0.0.1 → 0.0.3

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 +9 -5
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -45,6 +45,7 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
45
45
  return function (tree) {
46
46
  visit(tree, function (node) {
47
47
  if (node.type === 'paragraph') {
48
+ const baseIndention = (node.position?.start.column ?? 1) - 1;
48
49
  let currentLine = 0
49
50
  /**
50
51
  *
@@ -60,7 +61,7 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
60
61
 
61
62
  { // @ts-ignore
62
63
  const additionalCharacters = path.map(p => (elementSize[p] ?? 0) * 2).reduce((p, c) => p + c, 0);
63
- if (currentLine + additionalCharacters >= maxLineLength) {
64
+ if (currentLine + additionalCharacters >= maxLineLength - baseIndention) {
64
65
  if (path.some(x => x != 'text')) {
65
66
  // we need to split the node
66
67
  const current = path[path.length - 1];
@@ -85,7 +86,7 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
85
86
  if (element === '\n') {
86
87
  // @ts-ignore
87
88
  const additionalCharacters = path.map(p => (elementSize[p] ?? 0) * 2).reduce((p, c) => p + c, 0);
88
- if (currentLine + additionalCharacters >= maxLineLength) {
89
+ if (currentLine + additionalCharacters >= maxLineLength - baseIndention) {
89
90
  if (path.some(x => x != 'text')) {
90
91
  // we need to split the node
91
92
  const current = path[path.length - 1];
@@ -115,7 +116,7 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
115
116
  } else if (element === ' ') {
116
117
  // @ts-ignore
117
118
  const additionalCharacters = path.map(p => (elementSize[p] ?? 0) * 2).reduce((p, c) => p + c, 0);
118
- if (currentLine + additionalCharacters >= maxLineLength) {
119
+ if (currentLine + additionalCharacters >= maxLineLength - baseIndention) {
119
120
  if (path.some(x => x != 'text')) {
120
121
  // we need to split the node
121
122
  const current = path[path.length - 1];
@@ -156,7 +157,7 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
156
157
  {
157
158
  // @ts-ignore
158
159
  const additionalCharacters = path.map(p => (elementSize[p] ?? 0) * 2).reduce((p, c) => p + c, 0);
159
- if (currentLine + additionalCharacters >= maxLineLength) {
160
+ if (currentLine + additionalCharacters >= maxLineLength - baseIndention) {
160
161
  if (path.some(x => x != 'text')) {
161
162
  // we need to split the node
162
163
  const current = path[path.length - 1];
@@ -212,7 +213,6 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
212
213
  for (let i = 0; i < node.children.length; i++) {
213
214
  const element = node.children[i]
214
215
  const result = walk(element, [element.type])
215
-
216
216
  if (result.type == 'split') {
217
217
  currentLine = 0
218
218
  node.children.splice(i, 1, result.replaceBy[0], { type: 'text', value: '\n' }, result.replaceBy[1])
@@ -225,6 +225,10 @@ export default function remarkBreakLongLines({ maxLineLength = 80 } = {}) {
225
225
  prev.value = prev.value.trimEnd();
226
226
  }
227
227
  }
228
+ } else if (currentLine > 0) {
229
+ // @ts-ignore
230
+ const additional = (elementSize[element.type] ?? 0) * 2;
231
+ currentLine += additional;
228
232
  }
229
233
  }
230
234
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-break-line",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "keywords": [