@drghaliasri/butex 7.0.3 → 7.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.
- package/dist/document2-cli.js +259 -34
- package/dist/document2-cli.js.map +1 -1
- package/dist/document2.d.mts +63 -3
- package/dist/document2.d.ts +63 -3
- package/dist/document2.js +299 -37
- package/dist/document2.js.map +1 -1
- package/dist/document2.mjs +297 -37
- package/dist/document2.mjs.map +1 -1
- package/dist/react-document2-preview.d.mts +336 -0
- package/dist/react-document2-preview.d.ts +336 -0
- package/dist/react-document2-preview.js +7767 -0
- package/dist/react-document2-preview.js.map +1 -0
- package/dist/react-document2-preview.mjs +7737 -0
- package/dist/react-document2-preview.mjs.map +1 -0
- package/dist/react-document2.d.mts +53 -14
- package/dist/react-document2.d.ts +53 -14
- package/dist/react-document2.js +281 -42
- package/dist/react-document2.js.map +1 -1
- package/dist/react-document2.mjs +278 -41
- package/dist/react-document2.mjs.map +1 -1
- package/package.json +6 -1
package/dist/document2-cli.js
CHANGED
|
@@ -708,6 +708,10 @@ function defaultFloatMeta() {
|
|
|
708
708
|
centered: true,
|
|
709
709
|
captionEnabled: false,
|
|
710
710
|
caption: "",
|
|
711
|
+
captionField: {
|
|
712
|
+
id: document2Id("field"),
|
|
713
|
+
tokens: [{ id: document2Id("text"), kind: "text", text: "" }]
|
|
714
|
+
},
|
|
711
715
|
labelEnabled: false,
|
|
712
716
|
label: ""
|
|
713
717
|
};
|
|
@@ -766,15 +770,20 @@ function collectDocument2Labels(document2) {
|
|
|
766
770
|
}
|
|
767
771
|
function walk(blocks) {
|
|
768
772
|
for (const block of blocks) {
|
|
769
|
-
if (block.kind === "image"
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
773
|
+
if (block.kind === "image") {
|
|
774
|
+
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
775
|
+
counters.fig += 1;
|
|
776
|
+
entries.push({
|
|
777
|
+
key: block.label.trim(),
|
|
778
|
+
kind: "fig",
|
|
779
|
+
caption: block.captionEnabled ? block.caption : "",
|
|
780
|
+
ownerId: block.id,
|
|
781
|
+
number: counters.fig
|
|
782
|
+
});
|
|
783
|
+
}
|
|
784
|
+
if (block.captionEnabled) {
|
|
785
|
+
pushEqFromField(block.captionField.tokens);
|
|
786
|
+
}
|
|
778
787
|
}
|
|
779
788
|
if (block.kind === "table") {
|
|
780
789
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
@@ -787,6 +796,9 @@ function collectDocument2Labels(document2) {
|
|
|
787
796
|
number: counters.tab
|
|
788
797
|
});
|
|
789
798
|
}
|
|
799
|
+
if (block.captionEnabled) {
|
|
800
|
+
pushEqFromField(block.captionField.tokens);
|
|
801
|
+
}
|
|
790
802
|
for (const row of block.rows) {
|
|
791
803
|
for (const cell of row) {
|
|
792
804
|
pushEqFromField(cell.tokens);
|
|
@@ -829,6 +841,14 @@ function applyFloatMetaPatch(block, patch) {
|
|
|
829
841
|
}
|
|
830
842
|
if (typeof patch.caption === "string") {
|
|
831
843
|
block.caption = patch.caption;
|
|
844
|
+
const existingText = block.captionField.tokens.find((token) => token.kind === "text");
|
|
845
|
+
block.captionField.tokens = [
|
|
846
|
+
{
|
|
847
|
+
id: existingText?.id ?? document2Id("text"),
|
|
848
|
+
kind: "text",
|
|
849
|
+
text: patch.caption
|
|
850
|
+
}
|
|
851
|
+
];
|
|
832
852
|
}
|
|
833
853
|
if (typeof patch.labelEnabled === "boolean") {
|
|
834
854
|
block.labelEnabled = patch.labelEnabled;
|
|
@@ -1348,6 +1368,21 @@ function parseListBlock(json, options, path, diagnostics, identities) {
|
|
|
1348
1368
|
...metadataFromJson(json.metadata)
|
|
1349
1369
|
};
|
|
1350
1370
|
}
|
|
1371
|
+
function captionFieldFromJson(json, options, path, diagnostics, identities) {
|
|
1372
|
+
const caption = typeof json.caption === "string" ? json.caption : "";
|
|
1373
|
+
return applyImportedInlineIds(
|
|
1374
|
+
createInlineField2(
|
|
1375
|
+
caption,
|
|
1376
|
+
json.caption_math_objects ?? [],
|
|
1377
|
+
options,
|
|
1378
|
+
`${path}.caption`,
|
|
1379
|
+
diagnostics,
|
|
1380
|
+
json.caption_formats ?? []
|
|
1381
|
+
),
|
|
1382
|
+
json.caption_inline_ids,
|
|
1383
|
+
identities
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1351
1386
|
function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
1352
1387
|
if (!Array.isArray(json.rows)) {
|
|
1353
1388
|
throw new Error("\\begin{tabular} requires rows array");
|
|
@@ -1374,6 +1409,7 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1374
1409
|
if (mathObjects.length > 0 && mathObjects.length !== mathObjectIndex) {
|
|
1375
1410
|
pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathObjectIndex)}, got ${String(mathObjects.length)}`);
|
|
1376
1411
|
}
|
|
1412
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1377
1413
|
return {
|
|
1378
1414
|
id: blockIdFromJson(json, identities),
|
|
1379
1415
|
kind: "table",
|
|
@@ -1381,13 +1417,15 @@ function parseTableBlock(json, options, path, diagnostics, identities) {
|
|
|
1381
1417
|
closing: "\\end{tabular}",
|
|
1382
1418
|
columns: typeof json.columns === "string" ? json.columns : "",
|
|
1383
1419
|
rows,
|
|
1384
|
-
...
|
|
1420
|
+
...floatMeta,
|
|
1421
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1385
1422
|
...metadataFromJson(json.metadata)
|
|
1386
1423
|
};
|
|
1387
1424
|
}
|
|
1388
|
-
function parseImageBlock(json, identities) {
|
|
1425
|
+
function parseImageBlock(json, options, path, diagnostics, identities) {
|
|
1389
1426
|
const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
|
|
1390
1427
|
const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
|
|
1428
|
+
const floatMeta = parseFloatMetaFromJson(json);
|
|
1391
1429
|
return {
|
|
1392
1430
|
id: blockIdFromJson(json, identities),
|
|
1393
1431
|
kind: "image",
|
|
@@ -1395,7 +1433,8 @@ function parseImageBlock(json, identities) {
|
|
|
1395
1433
|
value,
|
|
1396
1434
|
...assetId !== void 0 ? { assetId } : {},
|
|
1397
1435
|
options: isRecordOfStrings(json.options) ? json.options : {},
|
|
1398
|
-
...
|
|
1436
|
+
...floatMeta,
|
|
1437
|
+
captionField: captionFieldFromJson(json, options, path, diagnostics, identities),
|
|
1399
1438
|
...metadataFromJson(json.metadata)
|
|
1400
1439
|
};
|
|
1401
1440
|
}
|
|
@@ -1428,7 +1467,7 @@ function parseBlock(json, options, path, diagnostics, identities) {
|
|
|
1428
1467
|
return parseTableBlock(json, options, path, diagnostics, identities);
|
|
1429
1468
|
}
|
|
1430
1469
|
if (json.command === "\\includegraphics") {
|
|
1431
|
-
return parseImageBlock(json, identities);
|
|
1470
|
+
return parseImageBlock(json, options, path, diagnostics, identities);
|
|
1432
1471
|
}
|
|
1433
1472
|
if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
|
|
1434
1473
|
return parseBibliographyBlock(json, identities);
|
|
@@ -2980,6 +3019,9 @@ function findField(blocks, fieldId) {
|
|
|
2980
3019
|
if (block.kind === "textBlock" && block.field.id === fieldId) {
|
|
2981
3020
|
return block.field;
|
|
2982
3021
|
}
|
|
3022
|
+
if ((block.kind === "image" || block.kind === "table") && block.captionField.id === fieldId) {
|
|
3023
|
+
return block.captionField;
|
|
3024
|
+
}
|
|
2983
3025
|
if (block.kind === "list") {
|
|
2984
3026
|
for (const item of block.items) {
|
|
2985
3027
|
if (item.field.id === fieldId) {
|
|
@@ -3018,26 +3060,30 @@ function findBlock(blocks, blockId) {
|
|
|
3018
3060
|
}
|
|
3019
3061
|
return null;
|
|
3020
3062
|
}
|
|
3063
|
+
function collectFieldIdentity(field, sets) {
|
|
3064
|
+
sets.fields.add(field.id);
|
|
3065
|
+
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
3066
|
+
}
|
|
3021
3067
|
function collectIdentitySets(blocks, sets) {
|
|
3022
3068
|
for (const block of blocks) {
|
|
3023
3069
|
sets.blocks.add(block.id);
|
|
3024
3070
|
if (block.kind === "textBlock") {
|
|
3025
|
-
|
|
3026
|
-
block.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
3071
|
+
collectFieldIdentity(block.field, sets);
|
|
3027
3072
|
} else if (block.kind === "list") {
|
|
3028
3073
|
for (const item of block.items) {
|
|
3029
3074
|
sets.items.add(item.id);
|
|
3030
|
-
|
|
3031
|
-
item.field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
3075
|
+
collectFieldIdentity(item.field, sets);
|
|
3032
3076
|
collectIdentitySets(item.blocks, sets);
|
|
3033
3077
|
}
|
|
3034
3078
|
} else if (block.kind === "table") {
|
|
3079
|
+
collectFieldIdentity(block.captionField, sets);
|
|
3035
3080
|
for (const row of block.rows) {
|
|
3036
3081
|
for (const field of row) {
|
|
3037
|
-
|
|
3038
|
-
field.tokens.forEach((token) => sets.tokens.add(token.id));
|
|
3082
|
+
collectFieldIdentity(field, sets);
|
|
3039
3083
|
}
|
|
3040
3084
|
}
|
|
3085
|
+
} else if (block.kind === "image") {
|
|
3086
|
+
collectFieldIdentity(block.captionField, sets);
|
|
3041
3087
|
}
|
|
3042
3088
|
}
|
|
3043
3089
|
}
|
|
@@ -3372,6 +3418,37 @@ function applyReferenceFields(reference, command) {
|
|
|
3372
3418
|
reference.fieldSeparator = command.field_separator;
|
|
3373
3419
|
}
|
|
3374
3420
|
}
|
|
3421
|
+
function replaceCitationKey(document2, previousKey, nextKey) {
|
|
3422
|
+
function replaceInField(field) {
|
|
3423
|
+
for (const token of field.tokens) {
|
|
3424
|
+
if (token.kind === "cite") {
|
|
3425
|
+
token.keys = token.keys.map((key) => key === previousKey ? nextKey : key);
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
function visitBlocks(blocks) {
|
|
3430
|
+
for (const block of blocks) {
|
|
3431
|
+
if (block.kind === "textBlock") {
|
|
3432
|
+
replaceInField(block.field);
|
|
3433
|
+
} else if (block.kind === "table") {
|
|
3434
|
+
replaceInField(block.captionField);
|
|
3435
|
+
for (const row of block.rows) {
|
|
3436
|
+
for (const cell of row) {
|
|
3437
|
+
replaceInField(cell);
|
|
3438
|
+
}
|
|
3439
|
+
}
|
|
3440
|
+
} else if (block.kind === "image") {
|
|
3441
|
+
replaceInField(block.captionField);
|
|
3442
|
+
} else if (block.kind === "list") {
|
|
3443
|
+
for (const item of block.items) {
|
|
3444
|
+
replaceInField(item.field);
|
|
3445
|
+
visitBlocks(item.blocks);
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
}
|
|
3449
|
+
}
|
|
3450
|
+
visitBlocks(document2.blocks);
|
|
3451
|
+
}
|
|
3375
3452
|
function applyArticleCommand(document2, command) {
|
|
3376
3453
|
if (command.op === "update_document_meta") {
|
|
3377
3454
|
document2.meta = {
|
|
@@ -3400,7 +3477,10 @@ function applyArticleCommand(document2, command) {
|
|
|
3400
3477
|
const target = document2.references[targetIndex];
|
|
3401
3478
|
if (command.op === "update_reference") {
|
|
3402
3479
|
if (command.key !== void 0) {
|
|
3403
|
-
|
|
3480
|
+
const previousKey = target.key;
|
|
3481
|
+
const nextKey = validateReferenceKey(document2, command.key, target.id);
|
|
3482
|
+
target.key = nextKey;
|
|
3483
|
+
replaceCitationKey(document2, previousKey, nextKey);
|
|
3404
3484
|
}
|
|
3405
3485
|
applyReferenceFields(target, command);
|
|
3406
3486
|
return;
|
|
@@ -3829,10 +3909,15 @@ function insertTable(document2, command) {
|
|
|
3829
3909
|
columns: command.columns,
|
|
3830
3910
|
rows: command.rows.map((row) => row.map((cell) => createCommandInlineField(document2, cell))),
|
|
3831
3911
|
...defaultFloatMeta(),
|
|
3832
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
3833
3912
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
3834
3913
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
3835
3914
|
};
|
|
3915
|
+
if (command.caption !== void 0) {
|
|
3916
|
+
applyFloatMetaPatch(block, {
|
|
3917
|
+
caption: command.caption,
|
|
3918
|
+
captionEnabled: command.caption.trim().length > 0
|
|
3919
|
+
});
|
|
3920
|
+
}
|
|
3836
3921
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
3837
3922
|
}
|
|
3838
3923
|
function checkCell(table, rowIndex, columnIndex) {
|
|
@@ -3977,6 +4062,15 @@ function fieldJson(field) {
|
|
|
3977
4062
|
...serialized.hasPersistedMath ? { math_objects: serialized.mathObjects } : {}
|
|
3978
4063
|
};
|
|
3979
4064
|
}
|
|
4065
|
+
function captionJson(field) {
|
|
4066
|
+
const serialized = serializeField(field);
|
|
4067
|
+
return {
|
|
4068
|
+
caption: serialized.value,
|
|
4069
|
+
caption_inline_ids: serialized.inlineIds,
|
|
4070
|
+
...serialized.formats.length > 0 ? { caption_formats: serialized.formats } : {},
|
|
4071
|
+
...serialized.hasPersistedMath ? { caption_math_objects: serialized.mathObjects } : {}
|
|
4072
|
+
};
|
|
4073
|
+
}
|
|
3980
4074
|
function listItemJson(item) {
|
|
3981
4075
|
const field = fieldJson(item.field);
|
|
3982
4076
|
return {
|
|
@@ -4021,7 +4115,7 @@ function blockJson(block) {
|
|
|
4021
4115
|
...hasPersistedMath ? { math_objects: fields.flatMap((row) => row.flatMap((field) => field.mathObjects)) } : {},
|
|
4022
4116
|
centered: block.centered,
|
|
4023
4117
|
caption_enabled: block.captionEnabled,
|
|
4024
|
-
|
|
4118
|
+
...captionJson(block.captionField),
|
|
4025
4119
|
label_enabled: block.labelEnabled,
|
|
4026
4120
|
label: block.label,
|
|
4027
4121
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -4036,7 +4130,7 @@ function blockJson(block) {
|
|
|
4036
4130
|
options: { ...block.options },
|
|
4037
4131
|
centered: block.centered,
|
|
4038
4132
|
caption_enabled: block.captionEnabled,
|
|
4039
|
-
|
|
4133
|
+
...captionJson(block.captionField),
|
|
4040
4134
|
label_enabled: block.labelEnabled,
|
|
4041
4135
|
label: block.label,
|
|
4042
4136
|
...block.metadata ? { metadata: { ...block.metadata } } : {}
|
|
@@ -4363,10 +4457,15 @@ function applyBasicCommand(document2, command) {
|
|
|
4363
4457
|
assetId: command.asset_id,
|
|
4364
4458
|
options: { width: "0.8\\columnwidth" },
|
|
4365
4459
|
...defaultFloatMeta(),
|
|
4366
|
-
...command.caption !== void 0 ? { caption: command.caption, captionEnabled: command.caption.trim().length > 0 } : {},
|
|
4367
4460
|
...command.label !== void 0 ? { label: command.label, labelEnabled: command.label.trim().length > 0 } : {},
|
|
4368
4461
|
...command.metadata ? { metadata: { ...command.metadata } } : {}
|
|
4369
4462
|
};
|
|
4463
|
+
if (command.caption !== void 0) {
|
|
4464
|
+
applyFloatMetaPatch(block, {
|
|
4465
|
+
caption: command.caption,
|
|
4466
|
+
captionEnabled: command.caption.trim().length > 0
|
|
4467
|
+
});
|
|
4468
|
+
}
|
|
4370
4469
|
document2.blocks.splice(blockInsertionIndex(document2, command.anchor), 0, block);
|
|
4371
4470
|
}
|
|
4372
4471
|
function applyDocument2Command(json, commandInput) {
|
|
@@ -4460,6 +4559,119 @@ function document2Outline(json) {
|
|
|
4460
4559
|
});
|
|
4461
4560
|
}
|
|
4462
4561
|
|
|
4562
|
+
// src/document2/introspection.ts
|
|
4563
|
+
function appendUnique(target, seen, values) {
|
|
4564
|
+
for (const value of values) {
|
|
4565
|
+
if (!seen.has(value)) {
|
|
4566
|
+
seen.add(value);
|
|
4567
|
+
target.push(value);
|
|
4568
|
+
}
|
|
4569
|
+
}
|
|
4570
|
+
}
|
|
4571
|
+
function getDocument2References(document2) {
|
|
4572
|
+
return document2.references.map((reference) => ({
|
|
4573
|
+
key: reference.key,
|
|
4574
|
+
authors: reference.authors,
|
|
4575
|
+
title: reference.title,
|
|
4576
|
+
year: reference.year,
|
|
4577
|
+
venue: reference.venue,
|
|
4578
|
+
url: reference.url,
|
|
4579
|
+
field_separator: reference.fieldSeparator
|
|
4580
|
+
}));
|
|
4581
|
+
}
|
|
4582
|
+
function getDocument2ReferenceIndex(document2) {
|
|
4583
|
+
const referenceKeys = new Set(document2.references.map((reference) => reference.key));
|
|
4584
|
+
const labelEntries = collectDocument2Labels(document2);
|
|
4585
|
+
const labelKeys = new Set(labelEntries.map((entry) => entry.key));
|
|
4586
|
+
const citations = [];
|
|
4587
|
+
const crossReferences = [];
|
|
4588
|
+
const tokenLocations = /* @__PURE__ */ new Map();
|
|
4589
|
+
const unresolvedCitationKeys = [];
|
|
4590
|
+
const unresolvedCrossReferenceKeys = [];
|
|
4591
|
+
const seenCitationKeys = /* @__PURE__ */ new Set();
|
|
4592
|
+
const seenCrossReferenceKeys = /* @__PURE__ */ new Set();
|
|
4593
|
+
function visitField(blockId, field) {
|
|
4594
|
+
for (const token of field.tokens) {
|
|
4595
|
+
tokenLocations.set(token.id, { block_id: blockId, field_id: field.id });
|
|
4596
|
+
if (token.kind === "cite") {
|
|
4597
|
+
const unresolvedKeys = token.keys.filter((key) => !referenceKeys.has(key));
|
|
4598
|
+
citations.push({
|
|
4599
|
+
kind: "cite",
|
|
4600
|
+
block_id: blockId,
|
|
4601
|
+
field_id: field.id,
|
|
4602
|
+
token_id: token.id,
|
|
4603
|
+
keys: [...token.keys],
|
|
4604
|
+
unresolved_keys: unresolvedKeys
|
|
4605
|
+
});
|
|
4606
|
+
appendUnique(unresolvedCitationKeys, seenCitationKeys, unresolvedKeys);
|
|
4607
|
+
} else if (token.kind === "ref") {
|
|
4608
|
+
const unresolvedKeys = token.keys.filter((key) => !labelKeys.has(key));
|
|
4609
|
+
crossReferences.push({
|
|
4610
|
+
kind: "ref",
|
|
4611
|
+
ref_command: token.refCommand,
|
|
4612
|
+
block_id: blockId,
|
|
4613
|
+
field_id: field.id,
|
|
4614
|
+
token_id: token.id,
|
|
4615
|
+
keys: [...token.keys],
|
|
4616
|
+
unresolved_keys: unresolvedKeys
|
|
4617
|
+
});
|
|
4618
|
+
appendUnique(unresolvedCrossReferenceKeys, seenCrossReferenceKeys, unresolvedKeys);
|
|
4619
|
+
}
|
|
4620
|
+
}
|
|
4621
|
+
}
|
|
4622
|
+
function visitBlocks(blocks) {
|
|
4623
|
+
for (const block of blocks) {
|
|
4624
|
+
if (block.kind === "textBlock") {
|
|
4625
|
+
visitField(block.id, block.field);
|
|
4626
|
+
} else if (block.kind === "table") {
|
|
4627
|
+
visitField(block.id, block.captionField);
|
|
4628
|
+
for (const row of block.rows) {
|
|
4629
|
+
for (const cell of row) {
|
|
4630
|
+
visitField(block.id, cell);
|
|
4631
|
+
}
|
|
4632
|
+
}
|
|
4633
|
+
} else if (block.kind === "image") {
|
|
4634
|
+
visitField(block.id, block.captionField);
|
|
4635
|
+
} else if (block.kind === "list") {
|
|
4636
|
+
for (const item of block.items) {
|
|
4637
|
+
visitField(block.id, item.field);
|
|
4638
|
+
visitBlocks(item.blocks);
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
}
|
|
4642
|
+
}
|
|
4643
|
+
visitBlocks(document2.blocks);
|
|
4644
|
+
const labels = labelEntries.map((entry) => {
|
|
4645
|
+
if (entry.kind !== "eq") {
|
|
4646
|
+
return {
|
|
4647
|
+
key: entry.key,
|
|
4648
|
+
kind: entry.kind,
|
|
4649
|
+
caption: entry.caption,
|
|
4650
|
+
number: entry.number,
|
|
4651
|
+
block_id: entry.ownerId
|
|
4652
|
+
};
|
|
4653
|
+
}
|
|
4654
|
+
const location = tokenLocations.get(entry.ownerId);
|
|
4655
|
+
return {
|
|
4656
|
+
key: entry.key,
|
|
4657
|
+
kind: entry.kind,
|
|
4658
|
+
caption: entry.caption,
|
|
4659
|
+
number: entry.number,
|
|
4660
|
+
...location ? { block_id: location.block_id, field_id: location.field_id } : {},
|
|
4661
|
+
token_id: entry.ownerId
|
|
4662
|
+
};
|
|
4663
|
+
});
|
|
4664
|
+
return {
|
|
4665
|
+
citations,
|
|
4666
|
+
cross_references: crossReferences,
|
|
4667
|
+
labels,
|
|
4668
|
+
unresolved: {
|
|
4669
|
+
citation_keys: unresolvedCitationKeys,
|
|
4670
|
+
cross_reference_keys: unresolvedCrossReferenceKeys
|
|
4671
|
+
}
|
|
4672
|
+
};
|
|
4673
|
+
}
|
|
4674
|
+
|
|
4463
4675
|
// src/document2/arabicPreamble.ts
|
|
4464
4676
|
function fontOptions(digitsMapping, includeScript = true) {
|
|
4465
4677
|
const parts = [];
|
|
@@ -4827,11 +5039,12 @@ ${block.closing}`;
|
|
|
4827
5039
|
${rows.join(" \\\\\n")}
|
|
4828
5040
|
${block.closing}`;
|
|
4829
5041
|
}
|
|
4830
|
-
function floatCaptionLabelLines(block, counter) {
|
|
5042
|
+
function floatCaptionLabelLines(block, counter, labelKinds) {
|
|
4831
5043
|
const lines = [];
|
|
4832
|
-
const
|
|
5044
|
+
const caption = inlineFieldLatexWithLabelKinds(block.captionField, labelKinds).trim();
|
|
5045
|
+
const hasCaption = block.captionEnabled && caption.length > 0;
|
|
4833
5046
|
if (hasCaption) {
|
|
4834
|
-
lines.push(` \\caption{${
|
|
5047
|
+
lines.push(` \\caption{${caption}}`);
|
|
4835
5048
|
}
|
|
4836
5049
|
if (block.labelEnabled && block.label.trim().length > 0) {
|
|
4837
5050
|
if (!hasCaption) {
|
|
@@ -4847,7 +5060,7 @@ function tableBlockLatex(block, labelKinds, fixedFloats) {
|
|
|
4847
5060
|
if (block.centered) {
|
|
4848
5061
|
lines.push(" \\centering");
|
|
4849
5062
|
}
|
|
4850
|
-
lines.push(...floatCaptionLabelLines(block, "table"));
|
|
5063
|
+
lines.push(...floatCaptionLabelLines(block, "table", labelKinds));
|
|
4851
5064
|
lines.push(indent(tabularInnerLatex(block, labelKinds)));
|
|
4852
5065
|
lines.push("\\end{table}");
|
|
4853
5066
|
return lines.join("\n");
|
|
@@ -4867,14 +5080,14 @@ function imageOptionsLatex(block, constrainToColumn) {
|
|
|
4867
5080
|
}
|
|
4868
5081
|
return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
|
|
4869
5082
|
}
|
|
4870
|
-
function imageBlockLatex(block, fixedFloats) {
|
|
5083
|
+
function imageBlockLatex(block, labelKinds, fixedFloats) {
|
|
4871
5084
|
const placement = fixedFloats ? "H" : "htbp";
|
|
4872
5085
|
const lines = [`\\begin{figure}[${placement}]`];
|
|
4873
5086
|
if (block.centered) {
|
|
4874
5087
|
lines.push(" \\centering");
|
|
4875
5088
|
}
|
|
4876
5089
|
lines.push(` ${block.command}${imageOptionsLatex(block, true)}{${block.value}}`);
|
|
4877
|
-
lines.push(...floatCaptionLabelLines(block, "figure"));
|
|
5090
|
+
lines.push(...floatCaptionLabelLines(block, "figure", labelKinds));
|
|
4878
5091
|
lines.push("\\end{figure}");
|
|
4879
5092
|
return lines.join("\n");
|
|
4880
5093
|
}
|
|
@@ -4889,7 +5102,7 @@ function blockLatex(block, references, labelKinds, fixedFloats) {
|
|
|
4889
5102
|
return tableBlockLatex(block, labelKinds, fixedFloats);
|
|
4890
5103
|
}
|
|
4891
5104
|
if (block.kind === "image") {
|
|
4892
|
-
return imageBlockLatex(block, fixedFloats);
|
|
5105
|
+
return imageBlockLatex(block, labelKinds, fixedFloats);
|
|
4893
5106
|
}
|
|
4894
5107
|
if (block.kind === "bibliography") {
|
|
4895
5108
|
const width = String(Math.max(references.length, 9));
|
|
@@ -5082,7 +5295,7 @@ function validateBlock(context, block, path) {
|
|
|
5082
5295
|
);
|
|
5083
5296
|
});
|
|
5084
5297
|
});
|
|
5085
|
-
|
|
5298
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
5086
5299
|
if (block.labelEnabled) {
|
|
5087
5300
|
registerKey(context, block.label, `${path}.label`, "tab", block.id);
|
|
5088
5301
|
}
|
|
@@ -5095,7 +5308,7 @@ function validateBlock(context, block, path) {
|
|
|
5095
5308
|
addIssue(context, "empty_image", path, block.id);
|
|
5096
5309
|
}
|
|
5097
5310
|
validateTextValue(context, block.value, `${path}.value`, block.id);
|
|
5098
|
-
|
|
5311
|
+
validateInlineField(context, block.captionField, `${path}.caption`, block.id);
|
|
5099
5312
|
if (block.labelEnabled) {
|
|
5100
5313
|
registerKey(context, block.label, `${path}.label`, "fig", block.id);
|
|
5101
5314
|
}
|
|
@@ -5282,7 +5495,7 @@ function parseDocument2WorkerRequest(value) {
|
|
|
5282
5495
|
if (!("document" in value)) {
|
|
5283
5496
|
throw new Document2WorkerProtocolError("invalid_request", "Worker request requires a document");
|
|
5284
5497
|
}
|
|
5285
|
-
if (value.action === "normalize" || value.action === "outline" || value.action === "export") {
|
|
5498
|
+
if (value.action === "normalize" || value.action === "outline" || value.action === "references" || value.action === "reference_index" || value.action === "export") {
|
|
5286
5499
|
return { action: value.action, document: value.document };
|
|
5287
5500
|
}
|
|
5288
5501
|
if (value.action === "apply_command") {
|
|
@@ -5392,6 +5605,12 @@ function executeDocument2WorkerRequest(input) {
|
|
|
5392
5605
|
if (request.action === "outline") {
|
|
5393
5606
|
return { ok: true, outline: document2Outline(asDocument2Json(request.document)) };
|
|
5394
5607
|
}
|
|
5608
|
+
if (request.action === "references") {
|
|
5609
|
+
return { ok: true, references: getDocument2References(resolveDocument2(request.document)) };
|
|
5610
|
+
}
|
|
5611
|
+
if (request.action === "reference_index") {
|
|
5612
|
+
return { ok: true, reference_index: getDocument2ReferenceIndex(resolveDocument2(request.document)) };
|
|
5613
|
+
}
|
|
5395
5614
|
if (request.action === "export") {
|
|
5396
5615
|
const document2 = resolveDocument2(request.document);
|
|
5397
5616
|
return {
|
|
@@ -5531,6 +5750,12 @@ function actionForPath(pathname) {
|
|
|
5531
5750
|
if (pathname === "/v1/document2/outline") {
|
|
5532
5751
|
return "outline";
|
|
5533
5752
|
}
|
|
5753
|
+
if (pathname === "/v1/document2/references") {
|
|
5754
|
+
return "references";
|
|
5755
|
+
}
|
|
5756
|
+
if (pathname === "/v1/document2/reference-index") {
|
|
5757
|
+
return "reference_index";
|
|
5758
|
+
}
|
|
5534
5759
|
if (pathname === "/v1/document2/export") {
|
|
5535
5760
|
return "export";
|
|
5536
5761
|
}
|