bare-script 3.8.11 → 3.8.13

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.
@@ -44,25 +44,9 @@ diffTypes = schemaParse( \
44
44
  function diffLines(left, right):
45
45
  diffs = []
46
46
 
47
- # Split the left into an array of lines
48
- if systemType(left) == 'array':
49
- leftLines = []
50
- for leftPart in left:
51
- arrayExtend(leftLines, regexSplit(diffRegexLineSplit, leftPart))
52
- endfor
53
- else:
54
- leftLines = regexSplit(diffRegexLineSplit, left)
55
- endif
56
-
57
- # Split the right into an array of lines
58
- if systemType(right) == 'array':
59
- rightLines = []
60
- for rightPart in right:
61
- arrayExtend(rightLines, regexSplit(diffRegexLineSplit, rightPart))
62
- endfor
63
- else:
64
- rightLines = regexSplit(diffRegexLineSplit, right)
65
- endif
47
+ # Convert inputs to arrays of lines
48
+ leftLines = diffLinesToArray(left)
49
+ rightLines = diffLinesToArray(right)
66
50
 
67
51
  # Compute the differences
68
52
  ixLeft = 0
@@ -97,25 +81,23 @@ function diffLines(left, right):
97
81
  endif
98
82
 
99
83
  # Look ahead to find next matching point
100
- foundMatch = false
84
+ matchIxLeft = null
85
+ matchIxRight = null
101
86
  ixLeftTmp = ixLeft
102
- while ixLeftTmp < leftLength:
87
+ while ixLeftTmp < leftLength && matchIxLeft == null:
103
88
  ixRightTmp = ixRight
104
- while ixRightTmp < rightLength:
89
+ while ixRightTmp < rightLength && matchIxLeft == null:
105
90
  if arrayGet(leftLines, ixLeftTmp) == arrayGet(rightLines, ixRightTmp):
106
- foundMatch = true
107
- break
91
+ matchIxLeft = ixLeftTmp
92
+ matchIxRight = ixRightTmp
108
93
  endif
109
94
  ixRightTmp = ixRightTmp + 1
110
95
  endwhile
111
- if foundMatch:
112
- break
113
- endif
114
96
  ixLeftTmp = ixLeftTmp + 1
115
97
  endwhile
116
98
 
117
99
  # If no match found, use remaining lines
118
- if !foundMatch:
100
+ if matchIxLeft == null:
119
101
  if ixLeft < leftLength:
120
102
  arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft)})
121
103
  ixLeft = leftLength
@@ -128,15 +110,15 @@ function diffLines(left, right):
128
110
  endif
129
111
 
130
112
  # Add removed lines if any
131
- if ixLeftTmp > ixLeft:
132
- arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft, ixLeftTmp)})
133
- ixLeft = ixLeftTmp
113
+ if matchIxLeft > ixLeft:
114
+ arrayPush(diffs, {'type': 'Remove', 'lines': arraySlice(leftLines, ixLeft, matchIxLeft)})
115
+ ixLeft = matchIxLeft
134
116
  endif
135
117
 
136
118
  # Add added lines if any
137
- if ixRightTmp > ixRight:
138
- arrayPush(diffs, {'type': 'Add', 'lines': arraySlice(rightLines, ixRight, ixRightTmp)})
139
- ixRight = ixRightTmp
119
+ if matchIxRight > ixRight:
120
+ arrayPush(diffs, {'type': 'Add', 'lines': arraySlice(rightLines, ixRight, matchIxRight)})
121
+ ixRight = matchIxRight
140
122
  endif
141
123
  endwhile
142
124
 
@@ -144,5 +126,25 @@ function diffLines(left, right):
144
126
  endfunction
145
127
 
146
128
 
129
+ # Helper function to convert input to array of lines
130
+ function diffLinesToArray(input):
131
+ # Array input?
132
+ if systemType(input) == 'array':
133
+ lines = []
134
+ for part in input:
135
+ arrayExtend(lines, regexSplit(diffRegexLineSplit, part))
136
+ endfor
137
+ return lines
138
+ endif
139
+
140
+ # String input
141
+ lines = regexSplit(diffRegexLineSplit, input)
142
+ if arrayLength(lines) == 1 && arrayGet(lines, 0) == '':
143
+ return []
144
+ endif
145
+ return lines
146
+ endfunction
147
+
148
+
147
149
  # Regex for splitting lines
148
150
  diffRegexLineSplit = regexNew('\r?\n')
@@ -442,7 +442,7 @@ endfunction
442
442
 
443
443
 
444
444
  # $function: markdownElements
445
- # $group: Markdown
445
+ # $group: markdownUp.bare: markdown
446
446
  # $doc: Generate an element model from a Markdown model
447
447
  # $arg markdownModel: The [Markdown model](https://craigahobbs.github.io/markdown-model/model/#var.vName='Markdown')
448
448
  # $arg generic: Optional (default is false). If true, render markdown elements in a generic context.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "bare-script",
4
- "version": "3.8.11",
4
+ "version": "3.8.13",
5
5
  "description": "BareScript; a lightweight scripting and expression language",
6
6
  "keywords": [
7
7
  "expression",