@learnosity/lib-qti-converter 0.13.0 → 0.15.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/docs/EXAMPLES.md +48 -34
- package/docs/GETTING_STARTED.md +43 -28
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +1 -1
- package/docs/QTI_METADATA_TO_TAGS.md +47 -4
- package/docs/TAGS_TO_QTI_METADATA.md +8 -7
- package/package.json +1 -1
- package/packages/cli/dist/{batchProcessors-DgiDpfpP.js → batchProcessors-B6Xmhfaz.js} +32 -6
- package/packages/cli/dist/batchProcessors-B6Xmhfaz.js.map +1 -0
- package/packages/cli/dist/batchWorker.js +1 -1
- package/packages/cli/dist/{learnosityToQti-CIj5603P.js → learnosityToQti-hFKA3KnZ.js} +4 -4
- package/packages/cli/dist/{learnosityToQti-CIj5603P.js.map → learnosityToQti-hFKA3KnZ.js.map} +1 -1
- package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js → learnosityToQtiPackage-DI7bYisT.js} +4 -4
- package/packages/cli/dist/{learnosityToQtiPackage-n6nGGr32.js.map → learnosityToQtiPackage-DI7bYisT.js.map} +1 -1
- package/packages/cli/dist/main.js +4 -4
- package/packages/cli/dist/{pathUtils-mTQZ0wYS.js → pathUtils-DkptaCiz.js} +22 -7
- package/packages/cli/dist/{pathUtils-mTQZ0wYS.js.map → pathUtils-DkptaCiz.js.map} +1 -1
- package/packages/cli/dist/{qtiPackageToLearnosity-B4cD8jUw.js → qtiPackageToLearnosity-JDifZn8o.js} +14 -8
- package/packages/cli/dist/qtiPackageToLearnosity-JDifZn8o.js.map +1 -0
- package/packages/cli/dist/{qtiToLearnosity-DDjcpShJ.js → qtiToLearnosity-Be0s-5Dr.js} +6 -5
- package/packages/cli/dist/qtiToLearnosity-Be0s-5Dr.js.map +1 -0
- package/packages/cli/dist/{resolveOptions-Czapkfc1.js → resolveOptions-BotCofhl.js} +15 -5
- package/packages/cli/dist/resolveOptions-BotCofhl.js.map +1 -0
- package/packages/cli/dist/{table-DTSv0atR.js → table-DlY4LGmL.js} +98 -43
- package/packages/cli/dist/table-DlY4LGmL.js.map +1 -0
- package/packages/core/dist/index.d.ts +10 -4
- package/packages/core/dist/index.js +128 -46
- package/packages/core/dist/node.d.ts +13 -5
- package/packages/core/dist/node.js +129 -46
- package/packages/cli/dist/batchProcessors-DgiDpfpP.js.map +0 -1
- package/packages/cli/dist/qtiPackageToLearnosity-B4cD8jUw.js.map +0 -1
- package/packages/cli/dist/qtiToLearnosity-DDjcpShJ.js.map +0 -1
- package/packages/cli/dist/resolveOptions-Czapkfc1.js.map +0 -1
- package/packages/cli/dist/table-DTSv0atR.js.map +0 -1
|
@@ -22999,6 +22999,34 @@ function md5hex(input) {
|
|
|
22999
22999
|
return hex;
|
|
23000
23000
|
}
|
|
23001
23001
|
//#endregion
|
|
23002
|
+
//#region src/qti-to-learnosity/utils/generateQuestionReference.ts
|
|
23003
|
+
/**
|
|
23004
|
+
* Shared utility for generating Learnosity question references.
|
|
23005
|
+
*/
|
|
23006
|
+
/**
|
|
23007
|
+
* Generate a Learnosity question reference from the resolved item reference and
|
|
23008
|
+
* the question's position within that item.
|
|
23009
|
+
*
|
|
23010
|
+
* The reference is `md5hex(`${itemRef}_${index}`)`, which guarantees it is both
|
|
23011
|
+
* unique (scoped to the item plus the per-item ordinal) and repeatable.
|
|
23012
|
+
*
|
|
23013
|
+
* - `itemRef` is the ALREADY-RESOLVED Learnosity item reference. Because it is
|
|
23014
|
+
* resolved upstream, the question reference automatically inherits the user's
|
|
23015
|
+
* `--item-reference-source` choice (item `identifier`, a `uuid`, or the source
|
|
23016
|
+
* filename) without this helper needing to re-read that option.
|
|
23017
|
+
* - `index` is the question's 1-BASED ordinal WITHIN the item. It is reset per
|
|
23018
|
+
* item, not a global counter: the first question in an item is `1`, the second
|
|
23019
|
+
* `2`, and so on. Single-question items always use `1` (a lone question is
|
|
23020
|
+
* `_1`), so there is no bare, unsuffixed variant.
|
|
23021
|
+
*
|
|
23022
|
+
* @param itemRef Resolved Learnosity item reference.
|
|
23023
|
+
* @param index 1-based ordinal of the question within the item.
|
|
23024
|
+
* @returns A 32-character lowercase hex MD5 question reference.
|
|
23025
|
+
*/
|
|
23026
|
+
function generateQuestionReference(itemRef, index) {
|
|
23027
|
+
return md5hex(`${itemRef}_${index}`);
|
|
23028
|
+
}
|
|
23029
|
+
//#endregion
|
|
23002
23030
|
//#region src/qti-to-learnosity/utils/mediaFeature.ts
|
|
23003
23031
|
/**
|
|
23004
23032
|
* Build a stable UUID-shaped identifier for a media feature.
|
|
@@ -23368,12 +23396,16 @@ function transformAssetUrls(html, options) {
|
|
|
23368
23396
|
//#endregion
|
|
23369
23397
|
//#region src/qti-to-learnosity/utils/generateItemReference.ts
|
|
23370
23398
|
/**
|
|
23371
|
-
* Generate item reference based on the configured source
|
|
23399
|
+
* Generate item reference based on the configured source.
|
|
23400
|
+
*
|
|
23401
|
+
* - `'itemIdentifier'` (default) and its deprecated alias `'qti'`, as well as an
|
|
23402
|
+
* omitted source, return the QTI `identifier`.
|
|
23403
|
+
* - `'uuid'` returns an MD5 hash of the QTI `identifier`.
|
|
23404
|
+
* - `'sourceFilename'` derives the reference from the source file name.
|
|
23372
23405
|
*/
|
|
23373
23406
|
function generateItemReference(qtiIdentifier, itemReferenceSource, sourceFile) {
|
|
23374
|
-
if (itemReferenceSource === "qti") return qtiIdentifier;
|
|
23375
23407
|
if (itemReferenceSource === "uuid") return md5hex(qtiIdentifier);
|
|
23376
|
-
if (sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23408
|
+
if (itemReferenceSource === "sourceFilename" && sourceFile) return (sourceFile.split(/[\\/]/).pop() ?? sourceFile).replace(/\.xml$/i, "");
|
|
23377
23409
|
return qtiIdentifier;
|
|
23378
23410
|
}
|
|
23379
23411
|
//#endregion
|
|
@@ -23518,7 +23550,7 @@ function convertMatchToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
23518
23550
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23519
23551
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23520
23552
|
};
|
|
23521
|
-
const questionRef =
|
|
23553
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
23522
23554
|
const stems = parsed.stems.map((stem) => transformAssetUrls(stem.text, {
|
|
23523
23555
|
organisationId,
|
|
23524
23556
|
mediaVault,
|
|
@@ -23940,7 +23972,7 @@ function convertGapMatchToLearnosity(inputXml, diagnostics, lomTags, organisatio
|
|
|
23940
23972
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
23941
23973
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
23942
23974
|
};
|
|
23943
|
-
const questionRef =
|
|
23975
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
23944
23976
|
const possibleResponses = parsed.gapTexts.map((gt) => transformAssetUrls(gt.text, {
|
|
23945
23977
|
organisationId,
|
|
23946
23978
|
mediaVault,
|
|
@@ -24408,7 +24440,7 @@ function convertInlineChoiceToLearnosity(inputXml, diagnostics, lomTags, organis
|
|
|
24408
24440
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24409
24441
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24410
24442
|
};
|
|
24411
|
-
const questionRef =
|
|
24443
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
24412
24444
|
const possibleResponses = parsed.interactions.map((interaction) => interaction.choices.map((choice) => transformAssetUrls(choice.text, transformOpts)));
|
|
24413
24445
|
const validationValue = buildValidationValues(parsed.interactions, parsed.responseDeclarations, diagnostics, transformOpts, sourceFile);
|
|
24414
24446
|
if (!validationValue) return { diagnostics };
|
|
@@ -24687,7 +24719,7 @@ function convertOrderToLearnosity(inputXml, diagnostics, lomTags, organisationId
|
|
|
24687
24719
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
24688
24720
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
24689
24721
|
};
|
|
24690
|
-
const questionRef =
|
|
24722
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
24691
24723
|
const stimulus = transformAssetUrls(parsed.stimulusText ?? "", {
|
|
24692
24724
|
organisationId,
|
|
24693
24725
|
mediaVault,
|
|
@@ -25138,7 +25170,7 @@ function convertHotspotToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25138
25170
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25139
25171
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25140
25172
|
};
|
|
25141
|
-
const questionRef =
|
|
25173
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
25142
25174
|
const stimulus = buildHotspotStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
25143
25175
|
const imageSource = organisationId ? transformUrl(parsed.imageSource, organisationId, mediaVault, customAssetUrl, transformContext) : parsed.imageSource;
|
|
25144
25176
|
const areas = [];
|
|
@@ -25436,7 +25468,7 @@ function convertHottextToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
25436
25468
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
25437
25469
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
25438
25470
|
};
|
|
25439
|
-
const questionRef =
|
|
25471
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
25440
25472
|
if (parsed.shuffle) diagnostics.push({
|
|
25441
25473
|
code: DiagnosticCode.QTI_SHUFFLE_NOT_SUPPORTED,
|
|
25442
25474
|
level: "warning",
|
|
@@ -25948,8 +25980,9 @@ function convertMcqToLearnosity(inputXml, diagnostics, lomTags, sourceFile, orga
|
|
|
25948
25980
|
const questions = [];
|
|
25949
25981
|
const widgets = [];
|
|
25950
25982
|
const questionSpans = [];
|
|
25951
|
-
for (
|
|
25952
|
-
const
|
|
25983
|
+
for (let i = 0; i < parsed.interactions.length; i++) {
|
|
25984
|
+
const interaction = parsed.interactions[i];
|
|
25985
|
+
const questionRef = generateQuestionReference(itemRef, i + 1);
|
|
25953
25986
|
const stimulus = interaction.stimulusText ? transformAssetUrls(interaction.stimulusText, {
|
|
25954
25987
|
organisationId,
|
|
25955
25988
|
mediaVault,
|
|
@@ -26393,7 +26426,7 @@ function convertShorttextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26393
26426
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26394
26427
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26395
26428
|
};
|
|
26396
|
-
const questionRef =
|
|
26429
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
26397
26430
|
const stimulus = normalizeFinalText(transformAssetUrls((parsed.templateText || "").replace(/{{response}}(?:\s*<\/[^>]+>)*\s*$/, "").trim(), {
|
|
26398
26431
|
organisationId,
|
|
26399
26432
|
mediaVault,
|
|
@@ -26487,7 +26520,7 @@ function convertClozetextToLearnosity(parsed, diagnostics, lomTags, organisation
|
|
|
26487
26520
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26488
26521
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26489
26522
|
};
|
|
26490
|
-
const questionRef =
|
|
26523
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
26491
26524
|
const stimulus = parsed.stimulusText ? normalizeFinalText(transformAssetUrls(parsed.stimulusText, {
|
|
26492
26525
|
organisationId,
|
|
26493
26526
|
mediaVault,
|
|
@@ -26737,7 +26770,7 @@ function readAssessmentItemExtendedText(inputXml) {
|
|
|
26737
26770
|
/**
|
|
26738
26771
|
* Build multi-interaction extended text item (multiple longtextV2 questions)
|
|
26739
26772
|
*/
|
|
26740
|
-
function buildMultiExtendedTextItem(parsed,
|
|
26773
|
+
function buildMultiExtendedTextItem(parsed, _inputXml, stimulusOverride, diagnostics, lomTags, organisationId, mediaVault, customAssetUrl, itemReferenceSource, sourceFile, assetTransformContext) {
|
|
26741
26774
|
const itemRef = assetTransformContext?.finalItemReference ?? generateItemReference(parsed.identifier ?? "unknown", itemReferenceSource, sourceFile);
|
|
26742
26775
|
const transformContext = {
|
|
26743
26776
|
finalItemReference: itemRef,
|
|
@@ -26747,9 +26780,8 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26747
26780
|
const questions = [];
|
|
26748
26781
|
const widgets = [];
|
|
26749
26782
|
const questionSpans = [];
|
|
26750
|
-
const responseIdentifiers = extractResponseIdentifiers(inputXml, "extendedTextInteraction");
|
|
26751
26783
|
for (let i = 0; i < stimulusOverride.length; i++) {
|
|
26752
|
-
const questionRef =
|
|
26784
|
+
const questionRef = generateQuestionReference(itemRef, i + 1);
|
|
26753
26785
|
const stimulus = transformAssetUrls(stimulusOverride[i], {
|
|
26754
26786
|
organisationId,
|
|
26755
26787
|
mediaVault,
|
|
@@ -26791,16 +26823,6 @@ function buildMultiExtendedTextItem(parsed, inputXml, stimulusOverride, diagnost
|
|
|
26791
26823
|
};
|
|
26792
26824
|
}
|
|
26793
26825
|
/**
|
|
26794
|
-
* Extract responseIdentifier values from interactions in XML
|
|
26795
|
-
*/
|
|
26796
|
-
function extractResponseIdentifiers(inputXml, interactionTag) {
|
|
26797
|
-
const responseIdentifiers = [];
|
|
26798
|
-
const interactionPattern = new RegExp(`<${assertXmlTagName(interactionTag)}[^>]+responseIdentifier=["']([^"']+)["']`, "g");
|
|
26799
|
-
let match;
|
|
26800
|
-
while ((match = interactionPattern.exec(inputXml)) !== null) responseIdentifiers.push(match[1]);
|
|
26801
|
-
return responseIdentifiers;
|
|
26802
|
-
}
|
|
26803
|
-
/**
|
|
26804
26826
|
* Convert extended text (extendedTextInteraction) to Learnosity longtextV2
|
|
26805
26827
|
* TASK 036: Added stimulusOverride parameter for composite items
|
|
26806
26828
|
*/
|
|
@@ -26816,7 +26838,7 @@ function convertExtendedTextToLearnosity(inputXml, diagnostics, lomTags, sourceF
|
|
|
26816
26838
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
26817
26839
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
26818
26840
|
};
|
|
26819
|
-
const questionRef =
|
|
26841
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
26820
26842
|
const stimulusRaw = stimulusOverride && stimulusOverride.length === 1 ? stimulusOverride[0] : parsed.stimulusText;
|
|
26821
26843
|
const stimulus = stimulusRaw ? transformAssetUrls(stimulusRaw, {
|
|
26822
26844
|
organisationId,
|
|
@@ -27192,7 +27214,7 @@ function convertGraphicGapMatchToLearnosity(inputXml, diagnostics, _lomTags, org
|
|
|
27192
27214
|
};
|
|
27193
27215
|
});
|
|
27194
27216
|
const validationValue = buildValidationValue$1(parsed.hotspots, parsed.correctPairs, gapImgIdToResponse);
|
|
27195
|
-
const questionRef =
|
|
27217
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
27196
27218
|
const question = {
|
|
27197
27219
|
type: "imageclozeassociationV2",
|
|
27198
27220
|
image: {
|
|
@@ -27566,7 +27588,7 @@ function convertDrawingToLearnosity(inputXml, diagnostics, lomTags, organisation
|
|
|
27566
27588
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27567
27589
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27568
27590
|
};
|
|
27569
|
-
const questionRef =
|
|
27591
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
27570
27592
|
const questionData = { type: "drawing" };
|
|
27571
27593
|
const stimulus = buildDrawingStimulus(parsed, organisationId, mediaVault, customAssetUrl, transformContext);
|
|
27572
27594
|
if (stimulus !== void 0) questionData.stimulus = stimulus;
|
|
@@ -27879,7 +27901,7 @@ function convertAssociationToLearnosity(inputXml, diagnostics, lomTags, organisa
|
|
|
27879
27901
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
27880
27902
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
27881
27903
|
};
|
|
27882
|
-
const questionRef =
|
|
27904
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
27883
27905
|
const stimulus = transformAssetUrls(parsed.stimulusText ? `<p>${parsed.stimulusText}</p>` : "", {
|
|
27884
27906
|
organisationId,
|
|
27885
27907
|
mediaVault,
|
|
@@ -28346,6 +28368,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28346
28368
|
}
|
|
28347
28369
|
const allQuestions = [];
|
|
28348
28370
|
const allWidgets = [];
|
|
28371
|
+
let placeholderRefCounter = 0;
|
|
28349
28372
|
const processResult = (result, subDiagnostics) => {
|
|
28350
28373
|
if (result.item) {
|
|
28351
28374
|
allQuestions.push(...result.item.questions);
|
|
@@ -28402,7 +28425,7 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28402
28425
|
if (groupEntries.length > 0) {
|
|
28403
28426
|
const correctResponses = [];
|
|
28404
28427
|
for (const entry of groupEntries) if (entry.correctResponse) correctResponses.push(entry.correctResponse);
|
|
28405
|
-
const questionRef =
|
|
28428
|
+
const questionRef = `__mixed_placeholder_${placeholderRefCounter++}`;
|
|
28406
28429
|
const templateParts = [];
|
|
28407
28430
|
const groupWrapperOpen = group.wrapperOpens[0];
|
|
28408
28431
|
if (groupWrapperOpen) templateParts.push(groupWrapperOpen);
|
|
@@ -28566,6 +28589,17 @@ function convertMixedInteractionsToLearnosity(inputXml, diagnostics, lomTags, or
|
|
|
28566
28589
|
});
|
|
28567
28590
|
return { diagnostics };
|
|
28568
28591
|
}
|
|
28592
|
+
const reassignedWidgets = /* @__PURE__ */ new Set();
|
|
28593
|
+
allQuestions.forEach((question, idx) => {
|
|
28594
|
+
const oldRef = question.reference;
|
|
28595
|
+
const newRef = generateQuestionReference(itemRef, idx + 1);
|
|
28596
|
+
const widget = allWidgets.find((w) => w.widget_type === "response" && w.reference === oldRef && !reassignedWidgets.has(w));
|
|
28597
|
+
if (widget) {
|
|
28598
|
+
widget.reference = newRef;
|
|
28599
|
+
reassignedWidgets.add(widget);
|
|
28600
|
+
}
|
|
28601
|
+
question.reference = newRef;
|
|
28602
|
+
});
|
|
28569
28603
|
const allFeatures = [];
|
|
28570
28604
|
if (hasPassageContent(inputXml)) {
|
|
28571
28605
|
if (extractPassageFromItemBody(inputXml)) {
|
|
@@ -28840,6 +28874,18 @@ function readAssessmentItemPassage(inputXml) {
|
|
|
28840
28874
|
*/
|
|
28841
28875
|
const MAX_TAG_LENGTH = 255;
|
|
28842
28876
|
/**
|
|
28877
|
+
* Split a tag value on commas into separate trimmed values.
|
|
28878
|
+
*
|
|
28879
|
+
* When `splitCsvTags` is false the value is returned unchanged as a single
|
|
28880
|
+
* element. When true, the value is split on literal commas, each part is
|
|
28881
|
+
* trimmed, and empty parts (from leading/trailing/double commas) are dropped.
|
|
28882
|
+
* A value without a comma yields a single trimmed element.
|
|
28883
|
+
*/
|
|
28884
|
+
function splitTagValue(value, splitCsvTags) {
|
|
28885
|
+
if (!splitCsvTags) return [value];
|
|
28886
|
+
return value.split(",").map((part) => part.trim()).filter((part) => part.length > 0);
|
|
28887
|
+
}
|
|
28888
|
+
/**
|
|
28843
28889
|
* Validate and optionally truncate tag types and tag names
|
|
28844
28890
|
*
|
|
28845
28891
|
* @param tags - Tags to validate
|
|
@@ -28901,9 +28947,10 @@ function validateAndProcessTags(tags, options = {}) {
|
|
|
28901
28947
|
* Extracts csm:labelledGUID entries as Learnosity tags
|
|
28902
28948
|
*
|
|
28903
28949
|
* @param metadataXml - XML containing Common Cartridge metadata
|
|
28950
|
+
* @param splitCsvTags - Split comma-separated GUID values into separate elements (default: true)
|
|
28904
28951
|
* @returns Tags object with type->name[] mapping
|
|
28905
28952
|
*/
|
|
28906
|
-
function parseCommonCartridgeTags(metadataXml) {
|
|
28953
|
+
function parseCommonCartridgeTags(metadataXml, splitCsvTags = true) {
|
|
28907
28954
|
const tags = {};
|
|
28908
28955
|
const stack = [];
|
|
28909
28956
|
let inLabel = false;
|
|
@@ -28932,7 +28979,7 @@ function parseCommonCartridgeTags(metadataXml) {
|
|
|
28932
28979
|
inLabel = false;
|
|
28933
28980
|
} else if (localName === "GUID" && inGuid) {
|
|
28934
28981
|
const guidValue = textBuf.join("").trim();
|
|
28935
|
-
if (currentLabel && guidValue) addTagValue(tags, currentLabel, guidValue);
|
|
28982
|
+
if (currentLabel && guidValue) addTagValue(tags, currentLabel, guidValue, splitCsvTags);
|
|
28936
28983
|
inGuid = false;
|
|
28937
28984
|
} else if (localName === "labelledGUID") currentLabel = "";
|
|
28938
28985
|
stack.pop();
|
|
@@ -28944,17 +28991,23 @@ function parseCommonCartridgeTags(metadataXml) {
|
|
|
28944
28991
|
return tags;
|
|
28945
28992
|
}
|
|
28946
28993
|
/**
|
|
28947
|
-
* Add a tag value to the tags object
|
|
28994
|
+
* Add a tag value to the tags object, splitting comma-separated values when
|
|
28995
|
+
* enabled and deduplicating in insertion order.
|
|
28996
|
+
*
|
|
28997
|
+
* @param splitCsvTags - Split a comma-separated value into separate elements (default: true)
|
|
28948
28998
|
*/
|
|
28949
|
-
function addTagValue(tags, source, value) {
|
|
28950
|
-
tags[source] = tags[source] ?? [];
|
|
28951
|
-
if (!
|
|
28999
|
+
function addTagValue(tags, source, value, splitCsvTags = true) {
|
|
29000
|
+
const existing = tags[source] = tags[source] ?? [];
|
|
29001
|
+
for (const part of splitTagValue(value, splitCsvTags)) if (!existing.includes(part)) existing.push(part);
|
|
28952
29002
|
}
|
|
28953
29003
|
/**
|
|
28954
29004
|
* Parse LOM XML and extract tags for Learnosity
|
|
28955
29005
|
* Extracts classification/taxonPath entries grouped by source langstring
|
|
29006
|
+
*
|
|
29007
|
+
* @param lomXml - XML containing LOM metadata
|
|
29008
|
+
* @param splitCsvTags - Split comma-separated taxon entry values into separate elements (default: true)
|
|
28956
29009
|
*/
|
|
28957
|
-
function parseLomXml(lomXml) {
|
|
29010
|
+
function parseLomXml(lomXml, splitCsvTags = true) {
|
|
28958
29011
|
const tags = {};
|
|
28959
29012
|
const stack = [];
|
|
28960
29013
|
let inTaxonPathSource = false;
|
|
@@ -28986,7 +29039,7 @@ function parseLomXml(lomXml) {
|
|
|
28986
29039
|
inTaxonPathSource = false;
|
|
28987
29040
|
} else if (inTaxonEntry) {
|
|
28988
29041
|
const value = textBuf.join("").trim();
|
|
28989
|
-
if (value && currentSource) addTagValue(tags, currentSource, value);
|
|
29042
|
+
if (value && currentSource) addTagValue(tags, currentSource, value, splitCsvTags);
|
|
28990
29043
|
inTaxonEntry = false;
|
|
28991
29044
|
}
|
|
28992
29045
|
}
|
|
@@ -29011,8 +29064,9 @@ function parseLomXml(lomXml) {
|
|
|
29011
29064
|
* @returns Merged tags object and diagnostics
|
|
29012
29065
|
*/
|
|
29013
29066
|
function parseMetadataTags(metadataXml, options = {}) {
|
|
29014
|
-
const
|
|
29015
|
-
const
|
|
29067
|
+
const splitCsvTags = options.splitCsvTags ?? true;
|
|
29068
|
+
const lomTags = parseLomXml(metadataXml, splitCsvTags);
|
|
29069
|
+
const ccTags = parseCommonCartridgeTags(metadataXml, splitCsvTags);
|
|
29016
29070
|
const mergedTags = { ...lomTags };
|
|
29017
29071
|
for (const [tagType, tagValues] of Object.entries(ccTags)) {
|
|
29018
29072
|
const values = tagValues;
|
|
@@ -29085,7 +29139,7 @@ function convertUploadToLearnosity(inputXml, diagnostics, lomTags, organisationI
|
|
|
29085
29139
|
preserveAssetFilenames: assetTransformContext?.preserveAssetFilenames ?? false,
|
|
29086
29140
|
sourceHrefBase: assetTransformContext?.sourceHrefBase
|
|
29087
29141
|
};
|
|
29088
|
-
const questionRef =
|
|
29142
|
+
const questionRef = generateQuestionReference(itemRef, 1);
|
|
29089
29143
|
const questionData = { type: "fileupload" };
|
|
29090
29144
|
if (parsed.stimulus) try {
|
|
29091
29145
|
questionData.stimulus = transformAssetUrls(parsed.stimulus, {
|
|
@@ -29404,6 +29458,7 @@ function convertQtiAssessmentItemToLearnosity(inputXml, opts = {}) {
|
|
|
29404
29458
|
if (lomXml) try {
|
|
29405
29459
|
const tagResult = parseMetadataTags(lomXml, {
|
|
29406
29460
|
truncateTags: opts.truncateTags,
|
|
29461
|
+
splitCsvTags: opts.splitCsvTags,
|
|
29407
29462
|
filePath: opts.inputPath
|
|
29408
29463
|
});
|
|
29409
29464
|
lomTags = tagResult.tags;
|
|
@@ -29544,11 +29599,13 @@ function convertQtiToLearnosity(input, opts) {
|
|
|
29544
29599
|
const result = convertQtiAssessmentItemToLearnosity(input, {
|
|
29545
29600
|
qtiVersion: opts.qtiVersion,
|
|
29546
29601
|
inputPath: opts.inputPath,
|
|
29602
|
+
sourceFile: opts.inputPath,
|
|
29547
29603
|
organisationId: opts.organisationId,
|
|
29548
29604
|
mediaVault: opts.mediaVault,
|
|
29549
29605
|
customAssetUrl: opts.customAssetUrl,
|
|
29550
29606
|
preserveAssetFilenames: opts.preserveAssetFilenames ?? false,
|
|
29551
29607
|
itemReferenceSource: opts.itemReferenceSource,
|
|
29608
|
+
splitCsvTags: opts.splitCsvTags,
|
|
29552
29609
|
fileAccess: opts.fileAccess
|
|
29553
29610
|
});
|
|
29554
29611
|
return Promise.resolve({
|
|
@@ -31881,6 +31938,15 @@ var AssetFilenameRegistry = class {
|
|
|
31881
31938
|
* - Does not write outputs if any error diagnostics exist
|
|
31882
31939
|
* - Deterministic ordering and stable JSON serialization
|
|
31883
31940
|
*/
|
|
31941
|
+
/**
|
|
31942
|
+
* Normalize an item reference / filename source for comparison and defaulting.
|
|
31943
|
+
* `'qti'` is a deprecated alias of `'itemIdentifier'`, and an omitted value
|
|
31944
|
+
* defaults to `'itemIdentifier'`.
|
|
31945
|
+
*/
|
|
31946
|
+
function normalizeRefSource(source) {
|
|
31947
|
+
if (source === "qti" || source === void 0) return "itemIdentifier";
|
|
31948
|
+
return source;
|
|
31949
|
+
}
|
|
31884
31950
|
const utf8Decoder = new TextDecoder();
|
|
31885
31951
|
/** Decode entry bytes as UTF-8 (works for both Uint8Array and Node Buffer). */
|
|
31886
31952
|
function decodeUtf8(data) {
|
|
@@ -31932,6 +31998,17 @@ function readAssessmentItemIdentifier(inputXml, fallback) {
|
|
|
31932
31998
|
} catch {}
|
|
31933
31999
|
return identifier;
|
|
31934
32000
|
}
|
|
32001
|
+
function readAssessmentTestIdentifier(inputXml, fallback) {
|
|
32002
|
+
let identifier = fallback;
|
|
32003
|
+
const parser = new import_saxes.SaxesParser({ xmlns: true });
|
|
32004
|
+
parser.on("opentag", (tag) => {
|
|
32005
|
+
if ((tag.local ?? tag.name) === "assessmentTest") identifier = getAttr$5(tag, "identifier") ?? fallback;
|
|
32006
|
+
});
|
|
32007
|
+
try {
|
|
32008
|
+
parser.write(inputXml).close();
|
|
32009
|
+
} catch {}
|
|
32010
|
+
return identifier;
|
|
32011
|
+
}
|
|
31935
32012
|
function uniqueItemReference(baseReference, sourceHref, items) {
|
|
31936
32013
|
if (!items.has(baseReference)) return baseReference;
|
|
31937
32014
|
const readableCandidate = `${baseReference}_${normalizeHref(sourceHref).split("/").at(-1)?.replace(/\.xml$/i, "") ?? "item"}`;
|
|
@@ -32156,6 +32233,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32156
32233
|
customAssetUrl: opts?.customAssetUrl,
|
|
32157
32234
|
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
32158
32235
|
itemReferenceSource: opts?.itemReferenceSource,
|
|
32236
|
+
splitCsvTags: opts?.splitCsvTags,
|
|
32159
32237
|
fileAccess: opts?.fileAccess,
|
|
32160
32238
|
packageRoot: opts?.sourceDir,
|
|
32161
32239
|
finalItemReference,
|
|
@@ -32192,6 +32270,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32192
32270
|
if (itemResource.metadataXml) try {
|
|
32193
32271
|
const tagResult = parseMetadataTags(itemResource.metadataXml, {
|
|
32194
32272
|
truncateTags: opts?.truncateTags,
|
|
32273
|
+
splitCsvTags: opts?.splitCsvTags,
|
|
32195
32274
|
filePath: itemResource.href
|
|
32196
32275
|
});
|
|
32197
32276
|
diagnostics.push(...tagResult.diagnostics);
|
|
@@ -32213,7 +32292,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32213
32292
|
inputXml: itemXml
|
|
32214
32293
|
});
|
|
32215
32294
|
const filenameSource = opts?.itemFilenameSource;
|
|
32216
|
-
if (filenameSource && filenameSource !== (opts.itemReferenceSource
|
|
32295
|
+
if (filenameSource && normalizeRefSource(filenameSource) !== normalizeRefSource(opts.itemReferenceSource)) {
|
|
32217
32296
|
const filename = generateItemReference(readAssessmentItemIdentifier(itemXml, md5Ref), filenameSource, itemFilePath);
|
|
32218
32297
|
itemFilenames.set(md5Ref, filename);
|
|
32219
32298
|
}
|
|
@@ -32244,8 +32323,10 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32244
32323
|
const activitiesManifest = {};
|
|
32245
32324
|
if (testResources.length > 0) for (const testResource of testResources) {
|
|
32246
32325
|
let activityReference;
|
|
32247
|
-
if (opts?.itemReferenceSource === "
|
|
32248
|
-
|
|
32326
|
+
if (normalizeRefSource(opts?.itemReferenceSource) === "itemIdentifier") {
|
|
32327
|
+
const testEntry = entries.get(normalizeHref(testResource.href));
|
|
32328
|
+
activityReference = testEntry ? readAssessmentTestIdentifier(decodeUtf8(testEntry.data), testResource.identifier) : testResource.identifier;
|
|
32329
|
+
} else {
|
|
32249
32330
|
const hrefParts = testResource.href.split("/");
|
|
32250
32331
|
activityReference = hrefParts[hrefParts.length - 1].replace(/\.xml$/i, "");
|
|
32251
32332
|
}
|
|
@@ -32287,6 +32368,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32287
32368
|
if (testResource.metadataXml) try {
|
|
32288
32369
|
const tagResult = parseMetadataTags(testResource.metadataXml, {
|
|
32289
32370
|
truncateTags: opts?.truncateTags,
|
|
32371
|
+
splitCsvTags: opts?.splitCsvTags,
|
|
32290
32372
|
filePath: testResource.href
|
|
32291
32373
|
});
|
|
32292
32374
|
diagnostics.push(...tagResult.diagnostics);
|
|
@@ -32381,7 +32463,7 @@ function convertQtiPackageToLearnosityBundle(input, opts) {
|
|
|
32381
32463
|
mediaVault: opts?.mediaVault ?? false,
|
|
32382
32464
|
customAssetUrl: opts?.customAssetUrl,
|
|
32383
32465
|
preserveAssetFilenames: opts?.preserveAssetFilenames ?? false,
|
|
32384
|
-
itemReferenceSource: opts?.itemReferenceSource ?? "
|
|
32466
|
+
itemReferenceSource: opts?.itemReferenceSource ?? "itemIdentifier"
|
|
32385
32467
|
}
|
|
32386
32468
|
},
|
|
32387
32469
|
items: Array.from(items.keys()).sort(),
|
|
@@ -33812,6 +33894,7 @@ async function convertQtiPackageToLearnosity(opts) {
|
|
|
33812
33894
|
itemReferenceSource: opts.itemReferenceSource,
|
|
33813
33895
|
itemFilenameSource: opts.itemFilenameSource,
|
|
33814
33896
|
truncateTags: opts.truncateTags,
|
|
33897
|
+
splitCsvTags: opts.splitCsvTags,
|
|
33815
33898
|
sourceDir,
|
|
33816
33899
|
fileAccess: sourceDir ? nodeFileAccess : void 0,
|
|
33817
33900
|
sourceLabel: opts.inputPath
|