boxwood 2.15.0 → 2.16.0
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/package.json
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { resolvePath } = require("./replaceVariables")
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Parse a custom component tag from markdown
|
|
3
5
|
* Supports both <Component attr="value"> and <Component attr={variable}>
|
|
@@ -157,7 +159,19 @@ function parseAttributes(attributesStr) {
|
|
|
157
159
|
i++
|
|
158
160
|
}
|
|
159
161
|
}
|
|
160
|
-
|
|
162
|
+
|
|
163
|
+
// Check if the entire quoted value is a variable reference: "{variable}"
|
|
164
|
+
if (value.startsWith("{") && value.endsWith("}")) {
|
|
165
|
+
const variableName = value.substring(1, value.length - 1).trim()
|
|
166
|
+
if (variableName) {
|
|
167
|
+
attributes[name] = { __variable: variableName }
|
|
168
|
+
} else {
|
|
169
|
+
attributes[name] = value
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
attributes[name] = value
|
|
173
|
+
}
|
|
174
|
+
|
|
161
175
|
if (i < str.length) i++ // Skip closing quote
|
|
162
176
|
} else if (str[i] === "{") {
|
|
163
177
|
// Variable reference
|
|
@@ -197,12 +211,10 @@ function resolveAttributes(attributes, data) {
|
|
|
197
211
|
const resolved = {}
|
|
198
212
|
for (const [key, value] of Object.entries(attributes)) {
|
|
199
213
|
if (value && typeof value === "object" && value.__variable) {
|
|
200
|
-
// Resolve variable
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
? data[variableName]
|
|
205
|
-
: undefined
|
|
214
|
+
// Resolve variable using resolvePath to support complex paths
|
|
215
|
+
const variablePath = value.__variable
|
|
216
|
+
const resolvedValue = resolvePath(data, variablePath)
|
|
217
|
+
resolved[key] = resolvedValue
|
|
206
218
|
} else {
|
|
207
219
|
resolved[key] = value
|
|
208
220
|
}
|
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* @returns {*} - The resolved value or undefined
|
|
6
6
|
*/
|
|
7
7
|
function resolvePath(data, path) {
|
|
8
|
+
// Handle null or undefined data
|
|
9
|
+
if (data === null || data === undefined) {
|
|
10
|
+
return undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
// Handle simple variable names (backwards compatibility)
|
|
9
14
|
if (!/[.\[]/.test(path)) {
|
|
10
15
|
return data[path]
|