@f5-sales-demo/pi-tui 21.6.2 → 21.6.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.
- package/package.json +3 -3
- package/src/latex.ts +61 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@f5-sales-demo/pi-tui",
|
|
4
|
-
"version": "21.6.
|
|
4
|
+
"version": "21.6.3",
|
|
5
5
|
"description": "Terminal User Interface library with differential rendering for efficient text-based applications",
|
|
6
6
|
"homepage": "https://github.com/f5-sales-demo/xcsh",
|
|
7
7
|
"author": "Can Boluk",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"fmt": "biome format --write ."
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@f5-sales-demo/pi-natives": "21.6.
|
|
41
|
-
"@f5-sales-demo/pi-utils": "21.6.
|
|
40
|
+
"@f5-sales-demo/pi-natives": "21.6.3",
|
|
41
|
+
"@f5-sales-demo/pi-utils": "21.6.3",
|
|
42
42
|
"marked": "^18.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
package/src/latex.ts
CHANGED
|
@@ -1226,7 +1226,64 @@ class LatexParser {
|
|
|
1226
1226
|
}
|
|
1227
1227
|
|
|
1228
1228
|
private splitEnvironmentRows(body: string): string[] {
|
|
1229
|
-
return
|
|
1229
|
+
return this.splitEnvironment(body, "row");
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
private splitEnvironmentCells(body: string): string[] {
|
|
1233
|
+
return this.splitEnvironment(body, "cell");
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
private splitEnvironment(body: string, delimiter: "row" | "cell"): string[] {
|
|
1237
|
+
const rows: string[] = [];
|
|
1238
|
+
let rowStart = 0;
|
|
1239
|
+
let position = 0;
|
|
1240
|
+
let braceDepth = 0;
|
|
1241
|
+
const environments: string[] = [];
|
|
1242
|
+
|
|
1243
|
+
while (position < body.length) {
|
|
1244
|
+
if (body[position] === "\\") {
|
|
1245
|
+
const environment = body.slice(position).match(/^\\(begin|end)\{([^}]+)\}/);
|
|
1246
|
+
if (environment) {
|
|
1247
|
+
const [, kind, name] = environment;
|
|
1248
|
+
if (kind === "begin") {
|
|
1249
|
+
environments.push(name);
|
|
1250
|
+
} else if (environments.at(-1) === name) {
|
|
1251
|
+
environments.pop();
|
|
1252
|
+
}
|
|
1253
|
+
position += environment[0].length;
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
if (delimiter === "row" && body[position + 1] === "\\" && braceDepth === 0 && environments.length === 0) {
|
|
1258
|
+
let rowEnd = position + 2;
|
|
1259
|
+
if (body[rowEnd] === "[") {
|
|
1260
|
+
const optionalEnd = body.indexOf("]", rowEnd + 1);
|
|
1261
|
+
if (optionalEnd >= 0 && !body.slice(rowEnd + 1, optionalEnd).includes("\n")) {
|
|
1262
|
+
rowEnd = optionalEnd + 1;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
rows.push(body.slice(rowStart, position));
|
|
1266
|
+
rowStart = rowEnd;
|
|
1267
|
+
position = rowEnd;
|
|
1268
|
+
continue;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
position += 2;
|
|
1272
|
+
continue;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
if (delimiter === "cell" && body[position] === "&" && braceDepth === 0 && environments.length === 0) {
|
|
1276
|
+
rows.push(body.slice(rowStart, position));
|
|
1277
|
+
rowStart = position + 1;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
if (body[position] === "{") braceDepth++;
|
|
1281
|
+
if (body[position] === "}" && braceDepth > 0) braceDepth--;
|
|
1282
|
+
position++;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
rows.push(body.slice(rowStart));
|
|
1286
|
+
return rows;
|
|
1230
1287
|
}
|
|
1231
1288
|
|
|
1232
1289
|
private parseEnvironment(): string {
|
|
@@ -1264,7 +1321,7 @@ class LatexParser {
|
|
|
1264
1321
|
const alignedBody = alignedAt ? body.replace(/^\s*\{[^}]*\}/, "") : body;
|
|
1265
1322
|
return this.splitEnvironmentRows(alignedBody)
|
|
1266
1323
|
.map(row => {
|
|
1267
|
-
const cells =
|
|
1324
|
+
const cells = this.splitEnvironmentCells(row);
|
|
1268
1325
|
const source = alignedAt
|
|
1269
1326
|
? Array.from({ length: Math.ceil(cells.length / 2) }, (_, index) =>
|
|
1270
1327
|
cells.slice(index * 2, index * 2 + 2).join(""),
|
|
@@ -1278,7 +1335,7 @@ class LatexParser {
|
|
|
1278
1335
|
|
|
1279
1336
|
if (environment === "cases" || environment === "cases*") {
|
|
1280
1337
|
const rows = this.splitEnvironmentRows(body)
|
|
1281
|
-
.map(row =>
|
|
1338
|
+
.map(row => this.splitEnvironmentCells(row).map(cell => this.renderNested(cell, false).trim()))
|
|
1282
1339
|
.filter(row => row.some(Boolean));
|
|
1283
1340
|
return rows
|
|
1284
1341
|
.map((row, index) => {
|
|
@@ -1304,7 +1361,7 @@ class LatexParser {
|
|
|
1304
1361
|
|
|
1305
1362
|
private renderMatrix(environment: string, body: string): string {
|
|
1306
1363
|
const matrix = this.splitEnvironmentRows(body)
|
|
1307
|
-
.map(row =>
|
|
1364
|
+
.map(row => this.splitEnvironmentCells(row).map(cell => this.renderNested(cell, false).trim()))
|
|
1308
1365
|
.filter(row => row.some(Boolean));
|
|
1309
1366
|
const columnCount = Math.max(0, ...matrix.map(row => row.length));
|
|
1310
1367
|
const columnWidths = Array.from({ length: columnCount }, (_, column) =>
|