@learnosity/lib-qti-converter 0.10.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/LICENSE +22 -0
- package/README.md +263 -0
- package/docs/DIAGNOSTICS.md +263 -0
- package/docs/EXAMPLES.md +869 -0
- package/docs/FAQ.md +415 -0
- package/docs/GETTING_STARTED.md +471 -0
- package/docs/LEARNOSITY_BUNDLE_FORMAT.md +338 -0
- package/docs/LEARNOSITY_SECTIONS.md +384 -0
- package/docs/QTI_METADATA_TO_TAGS.md +266 -0
- package/docs/QTI_STRUCTURE.md +353 -0
- package/docs/ROADMAP.md +232 -0
- package/docs/SUPPORTED_INTERACTIONS.md +601 -0
- package/docs/_sidebar.md +13 -0
- package/package.json +90 -0
- package/packages/cli/dist/main.js +45610 -0
- package/packages/core/dist/index.d.ts +2658 -0
- package/packages/core/dist/index.js +31706 -0
package/docs/EXAMPLES.md
ADDED
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Common conversion scenarios and code examples. The converter can be used as a [CLI tool](#cli-examples) or as a [library](#library-usage) imported into your own project.
|
|
4
|
+
|
|
5
|
+
## CLI Examples
|
|
6
|
+
|
|
7
|
+
### 1. Convert Single QTI Item to Learnosity
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
lcon qti-to-learnosity \
|
|
11
|
+
--in mcq-colors.xml \
|
|
12
|
+
--out mcq-colors.json \
|
|
13
|
+
--pretty
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
**Output:**
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"reference": "mcq-colors",
|
|
21
|
+
"type": "mcq",
|
|
22
|
+
"data": {
|
|
23
|
+
"options": [
|
|
24
|
+
{ "label": "Red", "value": "A" },
|
|
25
|
+
{ "label": "Blue", "value": "B" }
|
|
26
|
+
],
|
|
27
|
+
"validation": {
|
|
28
|
+
"scoring_type": "exactMatch",
|
|
29
|
+
"valid_response": { "value": ["B"] }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Convert Learnosity Item to QTI 2.2
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
lcon learnosity-to-qti \
|
|
39
|
+
--in item.json \
|
|
40
|
+
--out item.xml \
|
|
41
|
+
--qti-version 2.2
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 3. Convert QTI with Asset URL Transformation
|
|
45
|
+
|
|
46
|
+
Transform asset URLs to Learnosity CDN format:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
lcon qti-to-learnosity \
|
|
50
|
+
--in item.xml \
|
|
51
|
+
--out item.json \
|
|
52
|
+
--organisation_id 12345 \
|
|
53
|
+
--pretty
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
This transforms QTI asset references like `<img src="images/diagram.png" />` to Learnosity CDN URLs while preserving the original filename:
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<img src="https://assets.learnosity.com/organisations/12345/diagram.png" />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Because the converter preserves filenames and avoids random IDs in asset URLs, the output is deterministic for a given input item. Inline audio and video `<object>` elements are similarly converted to Learnosity feature spans with stable IDs derived from the transformed asset URL, which also keeps those outputs deterministic across runs.
|
|
63
|
+
|
|
64
|
+
**Using Media Vault subdomain:**
|
|
65
|
+
|
|
66
|
+
To use the `media-vault` subdomain instead of `assets`, add the `--mediavault` flag:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
lcon qti-to-learnosity \
|
|
70
|
+
--in item.xml \
|
|
71
|
+
--out item.json \
|
|
72
|
+
--organisation_id 12345 \
|
|
73
|
+
--mediavault \
|
|
74
|
+
--pretty
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
This produces URLs with the `media-vault` subdomain:
|
|
78
|
+
|
|
79
|
+
```html
|
|
80
|
+
<img src="https://media-vault.learnosity.com/organisations/12345/diagram.png" />
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The `--mediavault` flag also works with package conversions:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
lcon qti-package-to-learnosity \
|
|
87
|
+
--in package.zip \
|
|
88
|
+
--out bundle \
|
|
89
|
+
--organisation_id 12345 \
|
|
90
|
+
--mediavault
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Using a custom asset URL prefix:**
|
|
94
|
+
|
|
95
|
+
To use your own CDN or asset server instead of Learnosity's default, use the `--custom-asset-url` flag:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
lcon qti-to-learnosity \
|
|
99
|
+
--in item.xml \
|
|
100
|
+
--out item.json \
|
|
101
|
+
--organisation_id 12345 \
|
|
102
|
+
--custom-asset-url "https://my-cdn.example.com/assets" \
|
|
103
|
+
--pretty
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This produces URLs with your custom prefix:
|
|
107
|
+
|
|
108
|
+
```html
|
|
109
|
+
<img src="https://my-cdn.example.com/assets/diagram.png" />
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**Note:** When `--custom-asset-url` is provided, it overrides both the default Learnosity CDN and the `--mediavault` flag. The `--organisation_id` is still required but won't be used in the URL pattern.
|
|
113
|
+
|
|
114
|
+
The `--custom-asset-url` flag also works with package conversions:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
lcon qti-package-to-learnosity \
|
|
118
|
+
--in package.zip \
|
|
119
|
+
--out bundle \
|
|
120
|
+
--organisation_id 12345 \
|
|
121
|
+
--custom-asset-url "https://my-cdn.example.com/assets"
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
All configuration options used during package conversion are automatically recorded in the `manifest.json` file under the `diagnostics` section. This provides traceability for how the bundle was created. See [Learnosity Bundle Format - Diagnostics Section](LEARNOSITY_BUNDLE_FORMAT.md#diagnostics-section) for details.
|
|
125
|
+
|
|
126
|
+
### 4. Instructor-Facing Content (rubricBlock)
|
|
127
|
+
|
|
128
|
+
When converting QTI to Learnosity, `<rubricBlock view="scorer">` elements are automatically mapped to the `instructor_stimulus` field in the question data. This content is visible only to instructors/scorers, not to students.
|
|
129
|
+
|
|
130
|
+
**QTI Input:**
|
|
131
|
+
|
|
132
|
+
```xml
|
|
133
|
+
<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" identifier="essay-001">
|
|
134
|
+
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="string"/>
|
|
135
|
+
<itemBody>
|
|
136
|
+
<rubricBlock view="scorer">
|
|
137
|
+
<p><strong>Scoring Rubric:</strong></p>
|
|
138
|
+
<ul>
|
|
139
|
+
<li>2 points: Complete answer with supporting evidence</li>
|
|
140
|
+
<li>1 point: Partial answer</li>
|
|
141
|
+
<li>0 points: Incorrect or no answer</li>
|
|
142
|
+
</ul>
|
|
143
|
+
</rubricBlock>
|
|
144
|
+
<p>Explain the water cycle in your own words.</p>
|
|
145
|
+
<extendedTextInteraction responseIdentifier="RESPONSE">
|
|
146
|
+
<prompt></prompt>
|
|
147
|
+
</extendedTextInteraction>
|
|
148
|
+
</itemBody>
|
|
149
|
+
</assessmentItem>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Learnosity Output:**
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"questions": [
|
|
157
|
+
{
|
|
158
|
+
"type": "longtextV2",
|
|
159
|
+
"data": {
|
|
160
|
+
"type": "longtextV2",
|
|
161
|
+
"stimulus": "<p>Explain the water cycle in your own words.</p>",
|
|
162
|
+
"instructor_stimulus": "<p><strong>Scoring Rubric:</strong></p>\n<ul>\n <li>2 points: Complete answer with supporting evidence</li>\n <li>1 point: Partial answer</li>\n <li>0 points: Incorrect or no answer</li>\n</ul>"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Key Points:**
|
|
170
|
+
|
|
171
|
+
- `rubricBlock` content is placed in the `instructor_stimulus` field at the question data level
|
|
172
|
+
- Multiple `rubricBlock` elements are concatenated with newlines
|
|
173
|
+
- **Supported question types:** MCQ (choiceInteraction), shorttext/clozetext (textEntryInteraction), and longtextV2 (extendedTextInteraction)
|
|
174
|
+
- Asset URLs within `rubricBlock` are transformed the same way as in student-facing content
|
|
175
|
+
- `rubricBlock` content is never included in the student-facing `stimulus` field
|
|
176
|
+
|
|
177
|
+
### 5. Control Item Reference Generation
|
|
178
|
+
|
|
179
|
+
**Default behavior (hashed references):**
|
|
180
|
+
|
|
181
|
+
By default, the converter generates MD5 hashes of the QTI identifier to prevent collisions:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
lcon qti-to-learnosity \
|
|
185
|
+
--in Items/my-custom-item.xml \
|
|
186
|
+
--out item.json
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
This generates a deterministic MD5 hash for each item reference (e.g., `"5d41402abc4b2a76b9719d911017c592"`), ensuring no conflicts when multiple conversions are imported into the same database while maintaining consistency across repeated conversions of the same item.
|
|
190
|
+
|
|
191
|
+
**Use QTI identifier for human-readable references:**
|
|
192
|
+
|
|
193
|
+
When you want item references to match the QTI identifier attribute from the XML:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
lcon qti-to-learnosity \
|
|
197
|
+
--in item.xml \
|
|
198
|
+
--out item.json \
|
|
199
|
+
--item-reference-source qti
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
This uses the QTI identifier attribute from the XML (e.g., if the XML has `identifier="item-001"`, the reference will be `"item-001"`).
|
|
203
|
+
|
|
204
|
+
**Decouple item reference from output filename:**
|
|
205
|
+
|
|
206
|
+
Use `--item-filename-source` to control output JSON filenames independently from the item reference. Values: `sourceFilename` or `qti`. When omitted, filenames match whatever `--item-reference-source` produces.
|
|
207
|
+
|
|
208
|
+
For example, use QTI identifiers as references but name the output files after the source XML filenames:
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
lcon qti-package-to-learnosity \
|
|
212
|
+
--in ./qti-package \
|
|
213
|
+
--out ./output \
|
|
214
|
+
--item-reference-source qti \
|
|
215
|
+
--item-filename-source sourceFilename
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
This is useful when you need the `item.reference` in the JSON to match QTI identifiers, but want the output filenames to remain human-readable or match the original package structure.
|
|
219
|
+
|
|
220
|
+
### 6. Interactive Mode
|
|
221
|
+
|
|
222
|
+
Use interactive prompts for all options:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
lcon --interactive
|
|
226
|
+
# or use the short alias
|
|
227
|
+
lcon -i
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
You'll be prompted to:
|
|
231
|
+
|
|
232
|
+
1. Select a command (qti-to-learnosity, etc.)
|
|
233
|
+
2. Enter input path
|
|
234
|
+
3. Enter output path
|
|
235
|
+
4. Select QTI version
|
|
236
|
+
5. Enter organisation ID (optional)
|
|
237
|
+
6. Configure other options
|
|
238
|
+
|
|
239
|
+
### 7. Diagnostic Output Options
|
|
240
|
+
|
|
241
|
+
The converter provides flexible diagnostic output control:
|
|
242
|
+
|
|
243
|
+
**Show INFO-level diagnostics (verbose mode):**
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
lcon learnosity-to-qti-package \
|
|
247
|
+
--in ./bundle \
|
|
248
|
+
--out output.zip \
|
|
249
|
+
--verbose
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
By default, only ERROR and WARNING level diagnostics are shown. Use `--verbose` (or `-v`) to see all diagnostic messages including INFO level (e.g., "Unescaped ampersands found and escaped", "Replaced obsolete `<center>` tag").
|
|
253
|
+
|
|
254
|
+
**Suppress non-essential output (quiet mode):**
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
lcon learnosity-to-qti-package \
|
|
258
|
+
--in ./bundle \
|
|
259
|
+
--out output.zip \
|
|
260
|
+
--quiet
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Use `--quiet` (or `-q`) to suppress the banner and configuration summary. Diagnostics table will still be shown unless combined with `--diagnostics none`.
|
|
264
|
+
|
|
265
|
+
**Control where diagnostics are written:**
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Write diagnostics to stderr (default)
|
|
269
|
+
lcon learnosity-to-qti-package --in ./bundle --out output.zip --diagnostics stderr
|
|
270
|
+
|
|
271
|
+
# Write diagnostics to a JSON file
|
|
272
|
+
lcon learnosity-to-qti-package --in ./bundle --out output.zip --diagnostics file
|
|
273
|
+
|
|
274
|
+
# Write to both stderr and file
|
|
275
|
+
lcon learnosity-to-qti-package --in ./bundle --out output.zip --diagnostics both
|
|
276
|
+
|
|
277
|
+
# Suppress all diagnostics output
|
|
278
|
+
lcon learnosity-to-qti-package --in ./bundle --out output.zip --diagnostics none
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
**Fail on warnings (for CI/CD):**
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
lcon learnosity-to-qti-package \
|
|
285
|
+
--in ./bundle \
|
|
286
|
+
--out output.zip \
|
|
287
|
+
--fail-on-warn
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
Exit with error code 1 if any warnings are present. Useful for CI/CD pipelines where you want to enforce zero warnings.
|
|
291
|
+
|
|
292
|
+
**Combining options:**
|
|
293
|
+
|
|
294
|
+
```bash
|
|
295
|
+
# Quiet mode with verbose diagnostics written to file
|
|
296
|
+
lcon learnosity-to-qti-package \
|
|
297
|
+
--in ./bundle \
|
|
298
|
+
--out output.zip \
|
|
299
|
+
--quiet \
|
|
300
|
+
--verbose \
|
|
301
|
+
--diagnostics file
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### 8. Convert Learnosity Bundle to QTI Package
|
|
305
|
+
|
|
306
|
+
```bash
|
|
307
|
+
lcon learnosity-to-qti-package \
|
|
308
|
+
--in ./bundle-directory \
|
|
309
|
+
--out output-package.zip \
|
|
310
|
+
--activity activity_001 \
|
|
311
|
+
--output-format zip
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### 9. Include Learnosity Source in QTI Output
|
|
315
|
+
|
|
316
|
+
When converting from Learnosity to QTI, you can include the original source files for round-trip conversions or debugging:
|
|
317
|
+
|
|
318
|
+
**For single item conversion:**
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
lcon learnosity-to-qti \
|
|
322
|
+
--in item.json \
|
|
323
|
+
--out output/item.xml \
|
|
324
|
+
--include-learnosity-source
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
This creates:
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
output/
|
|
331
|
+
├── item.xml # Converted QTI XML
|
|
332
|
+
└── source/
|
|
333
|
+
└── item.json # Original Learnosity JSON
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
**For package conversion:**
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
lcon learnosity-to-qti-package \
|
|
340
|
+
--in ./bundle-directory \
|
|
341
|
+
--out output-package.zip \
|
|
342
|
+
--include-learnosity-source
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
This includes a `source/` folder in the output package containing the entire input bundle directory structure.
|
|
346
|
+
|
|
347
|
+
### 10. Batch Processing with Recursive Flag
|
|
348
|
+
|
|
349
|
+
Convert multiple packages in subdirectories with a single command using the `--recursive` flag.
|
|
350
|
+
|
|
351
|
+
**Convert multiple QTI packages to Learnosity bundles:**
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
lcon qti-package-to-learnosity \
|
|
355
|
+
--in ./qti-packages \
|
|
356
|
+
--out ./learnosity-bundles \
|
|
357
|
+
--organisation_id 12345 \
|
|
358
|
+
--recursive
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
**Input structure:**
|
|
362
|
+
|
|
363
|
+
```
|
|
364
|
+
qti-packages/
|
|
365
|
+
├── package-1/
|
|
366
|
+
│ ├── imsmanifest.xml
|
|
367
|
+
│ └── items/
|
|
368
|
+
├── package-2/
|
|
369
|
+
│ ├── imsmanifest.xml
|
|
370
|
+
│ └── items/
|
|
371
|
+
└── package-3/
|
|
372
|
+
├── imsmanifest.xml
|
|
373
|
+
└── items/
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
**Output structure:**
|
|
377
|
+
|
|
378
|
+
```
|
|
379
|
+
learnosity-bundles/
|
|
380
|
+
├── package-1/
|
|
381
|
+
│ ├── manifest.json
|
|
382
|
+
│ └── items/
|
|
383
|
+
├── package-2/
|
|
384
|
+
│ ├── manifest.json
|
|
385
|
+
│ └── items/
|
|
386
|
+
└── package-3/
|
|
387
|
+
├── manifest.json
|
|
388
|
+
└── items/
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
**Convert multiple Learnosity bundles to QTI packages:**
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
lcon learnosity-to-qti-package \
|
|
395
|
+
--in ./learnosity-bundles \
|
|
396
|
+
--out ./qti-packages \
|
|
397
|
+
--qti-version 2.2 \
|
|
398
|
+
--recursive
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
**Features:**
|
|
402
|
+
|
|
403
|
+
- ✅ Automatically detects package types in subdirectories
|
|
404
|
+
- ✅ Preserves folder structure (output mirrors input folder names)
|
|
405
|
+
- ✅ Shows progress for each package
|
|
406
|
+
- ✅ Continues processing even if individual packages fail
|
|
407
|
+
- ✅ Displays summary report at the end
|
|
408
|
+
- ✅ Optionally writes diagnostics for each package
|
|
409
|
+
|
|
410
|
+
**Example output:**
|
|
411
|
+
|
|
412
|
+
```
|
|
413
|
+
🔄 Batch Processing Mode
|
|
414
|
+
Scanning: ./qti-packages
|
|
415
|
+
|
|
416
|
+
Found 3 QTI package(s):
|
|
417
|
+
|
|
418
|
+
1. package-1
|
|
419
|
+
2. package-2
|
|
420
|
+
3. package-3
|
|
421
|
+
|
|
422
|
+
[1/3] Converting: package-1
|
|
423
|
+
Input: ./qti-packages/package-1
|
|
424
|
+
Output: ./learnosity-bundles/package-1
|
|
425
|
+
|
|
426
|
+
✓ SUCCESS (12 item(s) converted)
|
|
427
|
+
|
|
428
|
+
[2/3] Converting: package-2
|
|
429
|
+
Input: ./qti-packages/package-2
|
|
430
|
+
Output: ./learnosity-bundles/package-2
|
|
431
|
+
|
|
432
|
+
✓ SUCCESS (8 item(s) converted)
|
|
433
|
+
|
|
434
|
+
[3/3] Converting: package-3
|
|
435
|
+
Input: ./qti-packages/package-3
|
|
436
|
+
Output: ./learnosity-bundles/package-3
|
|
437
|
+
|
|
438
|
+
✓ SUCCESS (15 item(s) converted)
|
|
439
|
+
|
|
440
|
+
============================================================
|
|
441
|
+
Batch Conversion Summary
|
|
442
|
+
============================================================
|
|
443
|
+
Total packages: 3
|
|
444
|
+
✓ Succeeded: 3
|
|
445
|
+
✗ Failed: 0
|
|
446
|
+
Time elapsed: 12.3s
|
|
447
|
+
============================================================
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
**Notes:**
|
|
451
|
+
|
|
452
|
+
- The `--recursive` flag only processes immediate subdirectories (not nested subdirectories)
|
|
453
|
+
- Each subdirectory must be a valid package (QTI with `imsmanifest.xml` or Learnosity with `manifest.json`)
|
|
454
|
+
- Files in the root directory are ignored
|
|
455
|
+
- Cannot be used with ZIP input (only directory input)
|
|
456
|
+
|
|
457
|
+
### 11. Using stdin/stdout
|
|
458
|
+
|
|
459
|
+
```bash
|
|
460
|
+
# Read from stdin, write to stdout
|
|
461
|
+
cat input.xml | lcon qti-to-learnosity --in - --out -
|
|
462
|
+
|
|
463
|
+
# Chain with other tools
|
|
464
|
+
cat input.json | lcon learnosity-to-qti --in - --out - | xmllint --format -
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### 12. Using Configuration File
|
|
468
|
+
|
|
469
|
+
Create `lrn-converter.config.json` to set project defaults:
|
|
470
|
+
|
|
471
|
+
```json
|
|
472
|
+
{
|
|
473
|
+
"qtiVersion": "2.2",
|
|
474
|
+
"outputFormat": "dir",
|
|
475
|
+
"diagnostics": "both",
|
|
476
|
+
"pretty": true,
|
|
477
|
+
"verbose": true,
|
|
478
|
+
"output": "./output",
|
|
479
|
+
"organisationId": 12345,
|
|
480
|
+
"mediaVault": false,
|
|
481
|
+
"customAssetUrl": "https://my-cdn.example.com/assets"
|
|
482
|
+
}
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
Then run commands without specifying all flags:
|
|
486
|
+
|
|
487
|
+
```bash
|
|
488
|
+
# Config file options are automatically loaded
|
|
489
|
+
lcon qti-to-learnosity --in input.xml --out output.json
|
|
490
|
+
|
|
491
|
+
# CLI flags override config file values
|
|
492
|
+
lcon qti-to-learnosity --in input.xml --out output.json --verbose false
|
|
493
|
+
|
|
494
|
+
# Use custom config file location
|
|
495
|
+
lcon qti-to-learnosity --in input.xml --out output.json --config /path/to/config.json
|
|
496
|
+
|
|
497
|
+
# Disable config file loading
|
|
498
|
+
lcon qti-to-learnosity --in input.xml --out output.json --no-config
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
## Library Usage
|
|
502
|
+
|
|
503
|
+
You can import the converter into your own Node.js or TypeScript project instead of using the CLI. Install the package and import the functions you need:
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
import { convertQtiToLearnosity, convertLearnosityToQti } from '@learnosity/lib-qti-converter';
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### Convert QTI XML to Learnosity JSON
|
|
510
|
+
|
|
511
|
+
```typescript
|
|
512
|
+
import { convertQtiToLearnosity } from '@learnosity/lib-qti-converter';
|
|
513
|
+
|
|
514
|
+
const qtiXml = `<assessmentItem xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" identifier="item-001">
|
|
515
|
+
<responseDeclaration identifier="RESPONSE" cardinality="single" baseType="identifier">
|
|
516
|
+
<correctResponse><value>A</value></correctResponse>
|
|
517
|
+
</responseDeclaration>
|
|
518
|
+
<itemBody>
|
|
519
|
+
<choiceInteraction responseIdentifier="RESPONSE" maxChoices="1">
|
|
520
|
+
<simpleChoice identifier="A">Red</simpleChoice>
|
|
521
|
+
<simpleChoice identifier="B">Blue</simpleChoice>
|
|
522
|
+
</choiceInteraction>
|
|
523
|
+
</itemBody>
|
|
524
|
+
</assessmentItem>`;
|
|
525
|
+
|
|
526
|
+
const result = await convertQtiToLearnosity(qtiXml, {
|
|
527
|
+
qtiVersion: '2.2',
|
|
528
|
+
pretty: true,
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
console.log(result.output); // Converted Learnosity JSON (or undefined on failure)
|
|
532
|
+
console.log(result.diagnostics); // Array of Diagnostic objects
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### Convert Learnosity JSON to QTI XML
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
import { convertLearnosityToQti } from '@learnosity/lib-qti-converter';
|
|
539
|
+
|
|
540
|
+
const learnosityItem = {
|
|
541
|
+
reference: 'item-001',
|
|
542
|
+
content: '<span class="learnosity-response question-q-001"></span>',
|
|
543
|
+
definition: {
|
|
544
|
+
widgets: [{ reference: 'q-001', widget_type: 'response' }],
|
|
545
|
+
},
|
|
546
|
+
questions: [
|
|
547
|
+
{
|
|
548
|
+
reference: 'q-001',
|
|
549
|
+
type: 'mcq',
|
|
550
|
+
data: {
|
|
551
|
+
type: 'mcq',
|
|
552
|
+
stimulus: '<p>What color is the sky?</p>',
|
|
553
|
+
options: [
|
|
554
|
+
{ label: 'Red', value: '0' },
|
|
555
|
+
{ label: 'Blue', value: '1' },
|
|
556
|
+
],
|
|
557
|
+
validation: {
|
|
558
|
+
scoring_type: 'exactMatch',
|
|
559
|
+
valid_response: { score: 1, value: ['1'] },
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
],
|
|
564
|
+
features: [],
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
const result = await convertLearnosityToQti(learnosityItem, {
|
|
568
|
+
qtiVersion: '2.2',
|
|
569
|
+
outputFormat: 'dir',
|
|
570
|
+
diagnostics: 'none',
|
|
571
|
+
verbose: false,
|
|
572
|
+
pretty: true,
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
console.log(result.output); // QTI XML string
|
|
576
|
+
console.log(result.diagnostics); // Array of Diagnostic objects
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### Handling Diagnostics
|
|
580
|
+
|
|
581
|
+
Every conversion returns a `diagnostics` array. Each diagnostic has a `level` (`info`, `warning`, or `error`), a `code`, and a `message`:
|
|
582
|
+
|
|
583
|
+
```typescript
|
|
584
|
+
import {
|
|
585
|
+
convertQtiToLearnosity,
|
|
586
|
+
hasErrors,
|
|
587
|
+
filterByLevel,
|
|
588
|
+
type Diagnostic,
|
|
589
|
+
} from '@learnosity/lib-qti-converter';
|
|
590
|
+
|
|
591
|
+
const result = await convertQtiToLearnosity(qtiXml, {
|
|
592
|
+
qtiVersion: '2.2',
|
|
593
|
+
outputFormat: 'dir',
|
|
594
|
+
diagnostics: 'none',
|
|
595
|
+
verbose: false,
|
|
596
|
+
pretty: true,
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
// Check if conversion produced errors
|
|
600
|
+
if (hasErrors(result.diagnostics)) {
|
|
601
|
+
console.error('Conversion failed:');
|
|
602
|
+
const errors = filterByLevel(result.diagnostics, 'error');
|
|
603
|
+
errors.forEach((d: Diagnostic) => console.error(` [${d.code}] ${d.message}`));
|
|
604
|
+
} else {
|
|
605
|
+
// Safe to use result.output
|
|
606
|
+
console.log(result.output);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Filter warnings
|
|
610
|
+
const warnings = filterByLevel(result.diagnostics, 'warning');
|
|
611
|
+
if (warnings.length > 0) {
|
|
612
|
+
console.warn(`${warnings.length} warning(s) during conversion`);
|
|
613
|
+
}
|
|
614
|
+
```
|
|
615
|
+
|
|
616
|
+
### Convert QTI Content Package to Learnosity Bundle
|
|
617
|
+
|
|
618
|
+
Convert an entire QTI Content Package (directory or ZIP) to a Learnosity bundle. Optionally write the result to disk:
|
|
619
|
+
|
|
620
|
+
```typescript
|
|
621
|
+
import { convertQtiPackageToLearnosity } from '@learnosity/lib-qti-converter';
|
|
622
|
+
|
|
623
|
+
// Convert and write to disk
|
|
624
|
+
// Note: bundle is NOT returned when outputPath is provided — only diagnostics and summary are.
|
|
625
|
+
const result = await convertQtiPackageToLearnosity({
|
|
626
|
+
inputPath: '/path/to/qti-package',
|
|
627
|
+
outputPath: '/path/to/output-bundle',
|
|
628
|
+
organisationId: 12345,
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
console.log(result.convertedSourceFiles); // Items that were converted
|
|
632
|
+
console.log(result.failedSourceFiles); // Items that failed
|
|
633
|
+
|
|
634
|
+
// Or convert in-memory only (no disk write) — bundle is returned in this mode
|
|
635
|
+
const memResult = await convertQtiPackageToLearnosity({
|
|
636
|
+
inputPath: '/path/to/qti-package.zip',
|
|
637
|
+
organisationId: 12345,
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
console.log(memResult.bundle); // In-memory Learnosity bundle
|
|
641
|
+
|
|
642
|
+
// Or pass raw ZIP bytes
|
|
643
|
+
const zipBuffer = fs.readFileSync('/path/to/package.zip');
|
|
644
|
+
const zipResult = await convertQtiPackageToLearnosity({
|
|
645
|
+
zipBytes: new Uint8Array(zipBuffer),
|
|
646
|
+
});
|
|
647
|
+
|
|
648
|
+
console.log(zipResult.bundle); // In-memory Learnosity bundle
|
|
649
|
+
```
|
|
650
|
+
|
|
651
|
+
### Convert Learnosity Bundle to QTI Content Package
|
|
652
|
+
|
|
653
|
+
Convert a Learnosity bundle to a QTI Content Package. Specify which activities to convert, or omit to convert all:
|
|
654
|
+
|
|
655
|
+
```typescript
|
|
656
|
+
import { convertLearnosityToQtiPackage } from '@learnosity/lib-qti-converter';
|
|
657
|
+
|
|
658
|
+
// Convert all activities and write to a ZIP
|
|
659
|
+
const result = convertLearnosityToQtiPackage({
|
|
660
|
+
inputPath: '/path/to/learnosity-bundle',
|
|
661
|
+
outputPath: '/path/to/output.zip',
|
|
662
|
+
qtiVersion: '2.2',
|
|
663
|
+
pretty: true,
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
console.log(result.package); // In-memory QTI Content Package
|
|
667
|
+
console.log(result.diagnostics); // Diagnostics from the full pipeline
|
|
668
|
+
|
|
669
|
+
// Convert specific activities only
|
|
670
|
+
const result2 = convertLearnosityToQtiPackage({
|
|
671
|
+
inputPath: '/path/to/learnosity-bundle',
|
|
672
|
+
outputPath: '/path/to/output-dir',
|
|
673
|
+
activityRefs: ['activity_001', 'activity_002'],
|
|
674
|
+
qtiVersion: '2.1',
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
// Convert in-memory only (no disk write)
|
|
678
|
+
const memResult = convertLearnosityToQtiPackage({
|
|
679
|
+
inputPath: '/path/to/learnosity-bundle',
|
|
680
|
+
qtiVersion: '2.2',
|
|
681
|
+
});
|
|
682
|
+
// Use memResult.package to inspect or further process the QTI content
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
### Available Exports
|
|
686
|
+
|
|
687
|
+
The package exports the following for library consumers:
|
|
688
|
+
|
|
689
|
+
| Export | Description |
|
|
690
|
+
| ----------------------------------------------------- | -------------------------------------------------- |
|
|
691
|
+
| `convertQtiToLearnosity` | Convert a QTI XML string to Learnosity JSON |
|
|
692
|
+
| `convertLearnosityToQti` | Convert a Learnosity JSON object to QTI XML |
|
|
693
|
+
| `convertQtiPackageToLearnosity` | Convert a QTI Content Package to Learnosity bundle |
|
|
694
|
+
| `convertLearnosityToQtiPackage` | Convert a Learnosity bundle to QTI Content Package |
|
|
695
|
+
| `hasErrors`, `filterByLevel`, `countByLevel` | Diagnostic utility functions |
|
|
696
|
+
| `formatDiagnosticsReport` | Format diagnostics into a human-readable report |
|
|
697
|
+
| `DiagnosticCode` | Enum of all diagnostic codes |
|
|
698
|
+
| `Diagnostic`, `ConversionOptions`, `ConversionResult` | TypeScript types for single-item conversions |
|
|
699
|
+
| `ConvertQtiPackageToLearnosityOptions` | Options type for `convertQtiPackageToLearnosity` |
|
|
700
|
+
| `ConvertQtiPackageToLearnosityResult` | Result type for `convertQtiPackageToLearnosity` |
|
|
701
|
+
| `ConvertLearnosityToQtiPackageOptions` | Options type for `convertLearnosityToQtiPackage` |
|
|
702
|
+
| `ConvertLearnosityToQtiPackageResult` | Result type for `convertLearnosityToQtiPackage` |
|
|
703
|
+
|
|
704
|
+
### ConversionOptions Reference (single-item conversions)
|
|
705
|
+
|
|
706
|
+
`convertQtiToLearnosity` and `convertLearnosityToQti` accept a `ConversionOptions` object:
|
|
707
|
+
|
|
708
|
+
| Option | Type | Required | CLI Equivalent | Description |
|
|
709
|
+
| --------------------- | ---------------------------------------------- | -------- | ------------------------- | ------------------------------------------------------------------------------ |
|
|
710
|
+
| `qtiVersion` | `'2.1'` \| `'2.2'` | Yes | `--qti-version` | QTI version to use for conversion |
|
|
711
|
+
| `outputFormat` | `'dir'` \| `'zip'` \| `'stdout'` | Yes | `--output-format` | Output format |
|
|
712
|
+
| `diagnostics` | `'stderr'` \| `'file'` \| `'both'` \| `'none'` | Yes | `--diagnostics` | Where to write diagnostic messages. Use `'none'` when using as a library |
|
|
713
|
+
| `verbose` | `boolean` | Yes | `--verbose` | Include INFO-level diagnostics in the result |
|
|
714
|
+
| `pretty` | `boolean` | Yes | `--pretty` | Pretty-print JSON/XML output |
|
|
715
|
+
| `inputPath` | `string` | No | `--in` | Path to input file (used for LOM metadata lookup) |
|
|
716
|
+
| `organisationId` | `number` | No | `--organisation_id` | Organisation ID for Learnosity CDN asset URLs |
|
|
717
|
+
| `mediaVault` | `boolean` | No | `--mediavault` | Use `media-vault` subdomain instead of `assets` for CDN URLs |
|
|
718
|
+
| `customAssetUrl` | `string` | No | `--custom-asset-url` | Custom base URL for assets (overrides default Learnosity CDN and `mediaVault`) |
|
|
719
|
+
| `itemReferenceSource` | `'sourceFilename'` \| `'qti'` \| `'uuid'` | No | `--item-reference-source` | How to generate item references. Default: `'sourceFilename'` |
|
|
720
|
+
| `truncateTags` | `boolean` | No | N/A | Truncate tag types and names to 255 characters instead of failing |
|
|
721
|
+
|
|
722
|
+
### ConvertQtiPackageToLearnosityOptions Reference (package conversion)
|
|
723
|
+
|
|
724
|
+
`convertQtiPackageToLearnosity` accepts a `ConvertQtiPackageToLearnosityOptions` object:
|
|
725
|
+
|
|
726
|
+
| Option | Type | Required | CLI Equivalent | Description |
|
|
727
|
+
| --------------------- | ----------------------------------------- | -------- | ------------------------- | ------------------------------------------------------------------------------ |
|
|
728
|
+
| `inputPath` | `string` | \* | `--in` | Path to QTI package directory or .zip file |
|
|
729
|
+
| `zipBytes` | `Uint8Array` | \* | N/A | Raw ZIP bytes (alternative to `inputPath`) |
|
|
730
|
+
| `outputPath` | `string` | No | `--out` | Output path (directory or .zip). Omit to skip writing to disk |
|
|
731
|
+
| `organisationId` | `number` | No | `--organisation_id` | Organisation ID for Learnosity CDN asset URLs |
|
|
732
|
+
| `mediaVault` | `boolean` | No | `--mediavault` | Use `media-vault` subdomain instead of `assets` for CDN URLs |
|
|
733
|
+
| `customAssetUrl` | `string` | No | `--custom-asset-url` | Custom base URL for assets (overrides default Learnosity CDN and `mediaVault`) |
|
|
734
|
+
| `itemReferenceSource` | `'sourceFilename'` \| `'qti'` \| `'uuid'` | No | `--item-reference-source` | How to generate item references. Default: `'sourceFilename'` |
|
|
735
|
+
| `itemFilenameSource` | `'sourceFilename'` \| `'qti'` | No | `--item-filename-source` | How to name output files |
|
|
736
|
+
| `truncateTags` | `boolean` | No | N/A | Truncate tag types and names to 255 characters instead of failing |
|
|
737
|
+
|
|
738
|
+
\* Either `inputPath` or `zipBytes` must be provided.
|
|
739
|
+
|
|
740
|
+
### ConvertLearnosityToQtiPackageOptions Reference (package conversion)
|
|
741
|
+
|
|
742
|
+
`convertLearnosityToQtiPackage` accepts a `ConvertLearnosityToQtiPackageOptions` object:
|
|
743
|
+
|
|
744
|
+
| Option | Type | Required | CLI Equivalent | Description |
|
|
745
|
+
| -------------- | ------------------ | -------- | --------------- | ---------------------------------------------------------------- |
|
|
746
|
+
| `inputPath` | `string` | Yes | `--in` | Path to the Learnosity bundle directory |
|
|
747
|
+
| `activityRefs` | `string[]` | No | `--activity` | Activity reference(s) to convert. Omit to convert all activities |
|
|
748
|
+
| `outputPath` | `string` | No | `--out` | Output path (.zip or directory). Omit to skip writing to disk |
|
|
749
|
+
| `qtiVersion` | `'2.1'` \| `'2.2'` | No | `--qti-version` | QTI version (default: `'2.1'`) |
|
|
750
|
+
| `pretty` | `boolean` | No | `--pretty` | Pretty-print XML output |
|
|
751
|
+
|
|
752
|
+
## Validation Examples
|
|
753
|
+
|
|
754
|
+
### Validate Learnosity JSON Structure
|
|
755
|
+
|
|
756
|
+
The Learnosity validation script validates JSON files to ensure they conform to Learnosity's schema requirements:
|
|
757
|
+
|
|
758
|
+
**Validate a single file:**
|
|
759
|
+
|
|
760
|
+
```bash
|
|
761
|
+
pnpm run validate:learnosity ./output/learnosity/items/item.json
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
**Validate all JSON files in items/ and activities/ subdirectories:**
|
|
765
|
+
|
|
766
|
+
```bash
|
|
767
|
+
pnpm run validate:learnosity ./output/learnosity/
|
|
768
|
+
```
|
|
769
|
+
|
|
770
|
+
**Validate all JSON files recursively in a directory:**
|
|
771
|
+
|
|
772
|
+
```bash
|
|
773
|
+
pnpm run validate:learnosity ./output/learnosity/ --recursive
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
**Note:** When validating a directory without `--recursive`, the script only looks in `./items` and `./activities` subdirectories. Use `--recursive` to validate all JSON files in the directory tree.
|
|
777
|
+
|
|
778
|
+
**Example output:**
|
|
779
|
+
|
|
780
|
+
```
|
|
781
|
+
Validating Learnosity JSON files in: ./output/learnosity/items/
|
|
782
|
+
|
|
783
|
+
./output/learnosity/items/clozetext-invalid.json:
|
|
784
|
+
❌ [ERROR] LRN_CLOZE_NO_PLACEHOLDERS: clozetext template must contain at least one {{response}} placeholder
|
|
785
|
+
|
|
786
|
+
./output/learnosity/items/mcq-invalid.json:
|
|
787
|
+
❌ [ERROR] LRN_SCHEMA_INVALID: Missing required field: data.type
|
|
788
|
+
|
|
789
|
+
======================================================================
|
|
790
|
+
Validation Summary:
|
|
791
|
+
Total files validated: 25
|
|
792
|
+
Files with errors: 2
|
|
793
|
+
Files with warnings: 0
|
|
794
|
+
Total errors: 2
|
|
795
|
+
Total warnings: 0
|
|
796
|
+
|
|
797
|
+
❌ Validation failed with 2 error(s)
|
|
798
|
+
======================================================================
|
|
799
|
+
```
|
|
800
|
+
|
|
801
|
+
**What it validates:**
|
|
802
|
+
|
|
803
|
+
- Item structure (required fields, widget references)
|
|
804
|
+
- Question types (mcq, clozetext, shorttext, longtextV2, etc.)
|
|
805
|
+
- Validation objects (`valid_response`, `alt_responses`)
|
|
806
|
+
- Data type correctness:
|
|
807
|
+
- MCQ: `valid_response.value` must be array of strings
|
|
808
|
+
- Clozetext: `valid_response.value` must be array (one per gap)
|
|
809
|
+
- Shorttext: `valid_response.value` can be string or array (synonyms)
|
|
810
|
+
- HTML content in stimulus and template fields
|
|
811
|
+
|
|
812
|
+
**Use cases:**
|
|
813
|
+
|
|
814
|
+
- Quality assurance for existing Learnosity JSON files
|
|
815
|
+
- Post-conversion testing after code changes
|
|
816
|
+
- CI/CD integration (exits with code 1 on errors)
|
|
817
|
+
|
|
818
|
+
### Validate QTI XML Against Schema
|
|
819
|
+
|
|
820
|
+
The validation script validates XML files using **local XSD schemas** (not remote) and automatically detects the file type to use the appropriate schema:
|
|
821
|
+
|
|
822
|
+
- **QTI items/tests** - Validated against QTI 2.2 schema (`imsqti_v2p2p4.xsd`)
|
|
823
|
+
- **Manifest files** (`imsmanifest.xml`) - Validated against IMS Content Packaging schema (`imscp_v1p1.xsd`)
|
|
824
|
+
- **LOM metadata files** (`*.lom.xml`) - Validated against IMS Learning Resource Metadata schema (`imsmd_v1p2p4.xsd`)
|
|
825
|
+
|
|
826
|
+
Schema URLs are resolved to local files using the XML catalog (`schemas/qti/catalog.xml`).
|
|
827
|
+
|
|
828
|
+
```bash
|
|
829
|
+
pnpm run validate:qti ./output/qti-items
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
With debug mode to see schema resolution details:
|
|
833
|
+
|
|
834
|
+
```bash
|
|
835
|
+
pnpm run validate:qti:debug ./output/qti-items
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
With custom schema and parallel jobs:
|
|
839
|
+
|
|
840
|
+
```bash
|
|
841
|
+
pnpm run validate:qti ./output/qti-items ./schemas/qti/v2p1/imsqti_v2p1.xsd 16
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
## Testing Examples
|
|
845
|
+
|
|
846
|
+
### Run All Tests
|
|
847
|
+
|
|
848
|
+
```bash
|
|
849
|
+
pnpm test
|
|
850
|
+
```
|
|
851
|
+
|
|
852
|
+
### Run Specific Test File
|
|
853
|
+
|
|
854
|
+
```bash
|
|
855
|
+
cd packages/core
|
|
856
|
+
npx vitest --run test/hotspot.test.ts
|
|
857
|
+
```
|
|
858
|
+
|
|
859
|
+
### Watch Mode During Development
|
|
860
|
+
|
|
861
|
+
```bash
|
|
862
|
+
cd packages/core
|
|
863
|
+
npx vitest
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
## Next Steps
|
|
867
|
+
|
|
868
|
+
- Check [FAQ](https://learnosity.github.io/lib-qti-converter/#/FAQ) for common issues
|
|
869
|
+
- See the [package on npm](https://www.npmjs.com/package/@learnosity/lib-qti-converter) for full CLI documentation
|