@learnosity/lib-qti-converter 0.15.0 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +57 -9
  2. package/docs/EXAMPLES.md +4 -2
  3. package/docs/FAQ.md +20 -0
  4. package/docs/GETTING_STARTED.md +1 -1
  5. package/docs/SUPPORTED_INTERACTIONS.md +1 -1
  6. package/package.json +8 -8
  7. package/packages/cli/dist/{batchProcessors-B6Xmhfaz.js → batchProcessors-C7czhqX0.js} +73 -10
  8. package/packages/cli/dist/batchProcessors-C7czhqX0.js.map +1 -0
  9. package/packages/cli/dist/batchWorker.js +1 -1
  10. package/packages/cli/dist/{create-prompt-DyNnKXYU.js → create-prompt-dWckcotJ.js} +45 -43
  11. package/packages/cli/dist/create-prompt-dWckcotJ.js.map +1 -0
  12. package/packages/cli/dist/{dist-D3v6G5F8.js → dist-DXDR2peT.js} +6 -6
  13. package/packages/cli/dist/{dist-D3v6G5F8.js.map → dist-DXDR2peT.js.map} +1 -1
  14. package/packages/cli/dist/{learnosityToQti-hFKA3KnZ.js → learnosityToQti-D4ddrXaz.js} +4 -4
  15. package/packages/cli/dist/{learnosityToQti-hFKA3KnZ.js.map → learnosityToQti-D4ddrXaz.js.map} +1 -1
  16. package/packages/cli/dist/{learnosityToQtiPackage-DI7bYisT.js → learnosityToQtiPackage-Bwzm-uLX.js} +8 -8
  17. package/packages/cli/dist/learnosityToQtiPackage-Bwzm-uLX.js.map +1 -0
  18. package/packages/cli/dist/main.js +5 -5
  19. package/packages/cli/dist/main.js.map +1 -1
  20. package/packages/cli/dist/{pathUtils-DkptaCiz.js → pathUtils-D_VsVde8.js} +7 -7
  21. package/packages/cli/dist/pathUtils-D_VsVde8.js.map +1 -0
  22. package/packages/cli/dist/{qtiPackageToLearnosity-JDifZn8o.js → qtiPackageToLearnosity-CX9htPId.js} +4 -4
  23. package/packages/cli/dist/{qtiPackageToLearnosity-JDifZn8o.js.map → qtiPackageToLearnosity-CX9htPId.js.map} +1 -1
  24. package/packages/cli/dist/{qtiToLearnosity-Be0s-5Dr.js → qtiToLearnosity-JQYOkNbM.js} +4 -4
  25. package/packages/cli/dist/{qtiToLearnosity-Be0s-5Dr.js.map → qtiToLearnosity-JQYOkNbM.js.map} +1 -1
  26. package/packages/cli/dist/{resolveOptions-BotCofhl.js → resolveOptions-BuNN2KMA.js} +13 -16
  27. package/packages/cli/dist/resolveOptions-BuNN2KMA.js.map +1 -0
  28. package/packages/cli/dist/{rolldown-runtime-B4iAMlE-.js → rolldown-runtime-DktXgydw.js} +1 -1
  29. package/packages/cli/dist/{table-DlY4LGmL.js → table-DsKq-B4-.js} +6009 -2978
  30. package/packages/cli/dist/table-DsKq-B4-.js.map +1 -0
  31. package/packages/core/dist/index.d.ts +28 -1
  32. package/packages/core/dist/index.js +6014 -2974
  33. package/packages/core/dist/node.d.ts +28 -1
  34. package/packages/core/dist/node.js +3883 -789
  35. package/packages/cli/dist/batchProcessors-B6Xmhfaz.js.map +0 -1
  36. package/packages/cli/dist/create-prompt-DyNnKXYU.js.map +0 -1
  37. package/packages/cli/dist/learnosityToQtiPackage-DI7bYisT.js.map +0 -1
  38. package/packages/cli/dist/pathUtils-DkptaCiz.js.map +0 -1
  39. package/packages/cli/dist/resolveOptions-BotCofhl.js.map +0 -1
  40. package/packages/cli/dist/table-DlY4LGmL.js.map +0 -1
package/README.md CHANGED
@@ -44,6 +44,33 @@ node bin/lcon.js -i
44
44
 
45
45
  Some development tasks need tools that are not npm dependencies: Python 3 with `lxml` for [QTI validation](#qti-validation-not-bundled), and the Trivy and Semgrep CLIs for [security scanning](#security-scanning-external-tools-required).
46
46
 
47
+ ## Content changes during Learnosity → QTI conversion (0.16.0)
48
+
49
+ As of 0.16.0, converting Learnosity to QTI changes the authored HTML wherever it is needed to produce QTI 2.2 that passes the 1EdTech validator (XSD, Schematron and package cross-references). Learnosity accepts HTML that QTI does not, so content that converted silently before may now look different in the output. The public API and CLI options have not changed.
50
+
51
+ **What changes.** Each change is reported in `diagnostics.json`, and most are lossless:
52
+
53
+ - **Structure is repaired without changing the content.** Examples: wrapping table rows in `<tbody>`, putting list items in a list, closing void elements, splitting a paragraph around a block, and moving an inline wrapper (`<strong>`, `<em>`) inside the block it surrounded.
54
+ - **Editor and paste residue is removed.** This covers CKEditor bookmarks and drag handles, MathJax rendering artefacts, empty buttons, Google Docs and Telerik ids, and pasted `<style>` blocks.
55
+ - **Attributes QTI does not allow are removed.** The allowed list for each element comes from the 1EdTech Schematron. This includes `style`, `width`/`border`/`cellpadding` on tables, `contenteditable`, ARIA roles and attributes outside QTI's list, and invalid or duplicate `id`s. Image sizes in `style` are kept as `width`/`height` attributes.
56
+ - **Elements QTI does not have are converted or unwrapped, and their text is kept.** `<u>`, `<s>`, `<del>`, `<ins>` and `<mark>` become `<span class="lrn-norm-*">`, styled by the bundled `lrn-normalize.css`. Elements with no meaning (`<font>`, `<form>`, `<label>`, `<canvas>`, `<article>`, unknown or misspelled tags) are unwrapped.
57
+ - **Authoring errors are repaired where the intent is clear.** Examples: an unclosed tag (`<b<math>`), a `<` typed as text (`K<Q`, `<http://…>`), escaped quotes in attribute values, and a cut-off MathML formula (padded with an empty `<mrow/>`).
58
+
59
+ **What can lose information.** These cases are warnings:
60
+
61
+ - **Formatting.** Inline styling (`style`, fonts, colours) and table/column widths are dropped (`CONTENT_ATTRIBUTE_STRIPPED`).
62
+ - **Choice labels.** Block markup inside gap-match and inline-choice labels is flattened to inline content, because QTI only allows inline content there (`CONTENT_BLOCK_FLATTENED`).
63
+ - **Image drop zones.** Zones that extend outside the image are clamped to its edges (`QTI_COORDS_CLAMPED`).
64
+ - **Shuffle on image drag-and-drop.** `shuffle` on image cloze association is dropped, because QTI does not support it there (`QTI_SHUFFLE_NOT_SUPPORTED`).
65
+
66
+ **Content that is now converted.** Some content that 0.15.x dropped is now in the output:
67
+
68
+ - per-choice feedback
69
+ - a second shared passage inside tabs in a two-column layout
70
+ - some interactions that were previously malformed XML
71
+
72
+ **If you use `--fail-on-warn`.** The warnings above are new, so a conversion that exited `0` with 0.15.x may exit `1` with 0.16.0 when the source has content QTI does not allow. Check `diagnostics.json` to see what changed in each item. Most of these warnings are `CONTENT_ATTRIBUTE_STRIPPED`.
73
+
47
74
  ## Quick Start
48
75
 
49
76
  ### CLI Usage
@@ -142,14 +169,21 @@ Run `lcon <command> --help` for detailed options, or see [Examples](https://lear
142
169
 
143
170
  ## QTI Validation (not bundled)
144
171
 
145
- After converting Learnosity to QTI, you can validate the generated QTI XML against the official IMS XSD schemas:
172
+ After converting Learnosity to QTI, you can validate the generated QTI package locally. The validator is designed to reproduce what the 1EdTech QTI validator reports, in three layers:
173
+
174
+ 0. **Zip container checks** (only when you pass a `.zip`): archive integrity, `imsmanifest.xml` at the zip root, unsafe/backslash/non-ASCII/duplicate entry names, OS junk files (`__MACOSX`, `.DS_Store`), empty XML, encrypted or unusual compression. The zip is then extracted to a temp folder (cleaned up on exit) and layers 1-3 run on its contents.
175
+ 1. **XSD validation** of every XML file, preceded by a strict byte-level check for invalid UTF-8 and C1 control characters (U+0080-U+009F).
176
+ 2. **Schematron business rules** from the official 1EdTech `.sch` files, for rules XSD cannot express (for example, attributes that are not allowed on an element).
177
+ 3. **Package cross-references**: every local `href`/`src`/`data` must exist in the package and be declared in `imsmanifest.xml`. Relative references are resolved against the folder of the file that contains them, as a browser or LMS would. For example, `stimuli/x.html` inside `items/a.xml` points at `items/stimuli/x.html` (which does not exist); the correct form is `../stimuli/x.html`. The same applies to `./assets/...`. Note that this is stricter than earlier versions of the validator, and it is not confirmed that the 1EdTech validator resolves paths the same way.
178
+
179
+ If the folder you pass has no `imsmanifest.xml` of its own but holds several packages (for example a `_output` folder with one package per subfolder), each package found below it is checked against its own manifest, and a problem is reported with the package's relative path. A folder with XML files but no manifest anywhere is still reported, because a QTI package needs one.
146
180
 
147
181
  ```bash
148
- # Validate all QTI XML files in a directory
182
+ # Validate a QTI package directory
149
183
  npm run validate:qti -- output/qti/
150
184
 
151
- # Validate a specific file
152
- npm run validate:qti -- output/qti/item.xml
185
+ # Or validate the .zip itself, as the 1EdTech validator receives it
186
+ npm run validate:qti -- output/qti-package.zip
153
187
 
154
188
  # Debug mode to see schema resolution details
155
189
  npm run validate:qti:debug -- output/qti/
@@ -190,10 +224,11 @@ npm run validate:qti -- output/qti/
190
224
  **Features:**
191
225
 
192
226
  - Uses **local XSD schemas** (not remote) via XML catalog
227
+ - Runs **Schematron** business rules and **package cross-reference** checks (see above)
193
228
  - Automatically detects file types and uses appropriate schemas:
194
- - QTI items/tests → **QTI 2.1 or 2.2** schema, auto-detected per file from its XML namespace (override with `--qti-version`)
195
- - Manifest files → **IMS Content Packaging v1.1.4** schema (`imscp_v1p1.xsd`)
196
- - LOM metadata → **IMS Learning Resource Metadata v1.2.4** schema (`imsmd_v1p2p4.xsd`)
229
+ - QTI items/tests → **QTI 2.1 or 2.2** schema, auto-detected per file from its XML namespace (override with `--qti-version`)
230
+ - Manifest files → **IMS Content Packaging v1.1.4** schema (`imscp_v1p1.xsd`)
231
+ - LOM metadata → **IMS Learning Resource Metadata v1.2.4** schema (`imsmd_v1p2p4.xsd`)
197
232
 
198
233
  **Schema Versions:**
199
234
 
@@ -207,6 +242,19 @@ When generating QTI Content Packages, we use the following IMS specifications:
207
242
 
208
243
  All schemas are stored locally in `./schemas/qti/` and resolved via the XML catalog (`./schemas/catalog.xml`).
209
244
 
245
+ **Schematron rules:**
246
+
247
+ The `.sch` files are 1EdTech's own rules, extracted from the `xs:appinfo` blocks embedded in the official XSDs. They run through `lxml.isoschematron`, so no extra tooling is needed.
248
+
249
+ | QTI version | Schematron file |
250
+ | ----------- | ------------------------------------ |
251
+ | 2.1 | `schemas/qti/v2p1/imsqti_v2p1.sch` |
252
+ | 2.2 | `schemas/qti/v2p2/imsqti_v2p2p4.sch` |
253
+
254
+ For 2.2 the ASI-only file is used because that is the file the 1EdTech validator reports running. `imsqti_v2p2p4_all.sch` (ASI + HTML5 + APIP), `imsqtiv2p2p4_html5_v1p0.sch` and `apipv1p0_qtiextv2p2_v1p0p1.sch` are present but not used. If a mapped file is missing, the run prints `Schematron: SKIPPED` rather than reporting a pass.
255
+
256
+ **Exit code:** `0` when every file, the zip container and the cross-references are clean; `1` when any of them reports a problem; `2` for usage errors (bad arguments, missing path or schema). A skipped schematron layer is reported but does not change the exit code.
257
+
210
258
  **Requirements:**
211
259
 
212
260
  - Python 3
@@ -309,7 +357,7 @@ pnpm run test # Run all tests (core + cli)
309
357
  pnpm run test:cli # Run CLI package tests only
310
358
  pnpm run test:core # Run core package tests only
311
359
  pnpm run validate:learnosity # Validate Learnosity JSON structure (see Learnosity JSON Validation section)
312
- pnpm run validate:qti # Validate QTI XML against XSD schema (see QTI Validation section)
360
+ pnpm run validate:qti # Validate a QTI package: XSD, Schematron, cross-references (see QTI Validation section)
313
361
  pnpm run validate:qti:debug # Validate QTI XML in debug mode
314
362
  ```
315
363
 
@@ -367,7 +415,7 @@ lib-qti-converter/
367
415
  ├── bin/ # Utility scripts (validation tools)
368
416
  │ ├── validateLearnosity.ts # Learnosity JSON validation
369
417
  │ └── validateQti.py # QTI XML validation
370
- ├── schemas/ # QTI/CC XSD schemas (2.1 and 2.2)
418
+ ├── schemas/ # QTI/CC XSD schemas and Schematron rules (2.1 and 2.2)
371
419
  ├── docs/ # User documentation
372
420
  │ ├── GETTING_STARTED.md
373
421
  │ ├── EXAMPLES.md
package/docs/EXAMPLES.md CHANGED
@@ -138,7 +138,7 @@ All configuration options used during package conversion are automatically recor
138
138
 
139
139
  **Custom asset URL for Learnosity → QTI:**
140
140
 
141
- The same `--custom-asset-url` flag works in the reverse direction (`learnosity-to-qti` and `learnosity-to-qti-package`). Here it rewrites the asset reference prefix in the generated QTI, preserving the filename. When omitted, the default prefix is `./assets`, so references resolve to `./assets/<filename>` (matching the packaged `assets/` folder):
141
+ The same `--custom-asset-url` flag works in the reverse direction (`learnosity-to-qti` and `learnosity-to-qti-package`). Here it rewrites the asset reference prefix in the generated QTI, preserving the filename. When omitted, the default prefix is `./assets` for `learnosity-to-qti` (references resolve to `./assets/<filename>`), and `../assets` for `learnosity-to-qti-package`, where items and stimuli sit in `items/` and `stimuli/` below the package's `assets/` folder:
142
142
 
143
143
  ```bash
144
144
  lcon learnosity-to-qti-package \
@@ -153,7 +153,7 @@ Given an input reference of `/vendor/learnosity/itembank/assets/abc123_photo.png
153
153
  <img src="https://my-cdn.example.com/media/abc123_photo.png" />
154
154
  ```
155
155
 
156
- Without the flag, the same reference becomes `./assets/abc123_photo.png`. Note that in this direction `--custom-asset-url` rewrites only the reference strings — it does not move or rename the physical asset files copied into the package (they remain under `assets/`). Remote and `data:` URIs, plus converter-internal references such as the `lrn-normalize.css` stylesheet, are left untouched.
156
+ Without the flag, the same reference becomes `./assets/abc123_photo.png` (`../assets/abc123_photo.png` in a package). Note that in this direction `--custom-asset-url` rewrites only the reference strings — it does not move or rename the physical asset files copied into the package (they remain under `assets/`). Remote and `data:` URIs are left untouched. Converter-internal references such as the `lrn-normalize.css` stylesheet always point at the packaged `assets/` folder and ignore `--custom-asset-url`.
157
157
 
158
158
  ### 4. Instructor-Facing Content (rubricBlock)
159
159
 
@@ -909,6 +909,8 @@ The validation script validates XML files using **local XSD schemas** (not remot
909
909
 
910
910
  Schema URLs are resolved to local files using the XML catalog (`schemas/catalog.xml`).
911
911
 
912
+ The script also runs the 1EdTech **Schematron** business rules (`schemas/qti/v2p1/imsqti_v2p1.sch`, `schemas/qti/v2p2/imsqti_v2p2p4.sch`) against each QTI item/test, and checks **package cross-references** against `imsmanifest.xml` (run it on the package root so the manifest is found). Pass a `.zip` instead of a folder to also check the archive itself before its contents are validated, e.g. `pnpm run validate:qti ./qti-package.zip`.
913
+
912
914
  ```bash
913
915
  pnpm run validate:qti ./output/qti-items
914
916
  ```
package/docs/FAQ.md CHANGED
@@ -67,6 +67,15 @@ import type {
67
67
 
68
68
  These are expected and do not indicate problems.
69
69
 
70
+ ### Q: What does the `CONTENT_ATTRIBUTE_STRIPPED` warning mean?
71
+
72
+ **A:** QTI 2.2 only allows a fixed set of attributes on the HTML elements inside an item, and the 1EdTech validator rejects anything else. When Learnosity content contains such attributes, the converter removes them from the QTI item and reports what it removed, for example `style on <span> (5)` or `aria-hidden on <span> (1)`. This is a warning (not an error) because the formatting or accessibility hint is lost:
73
+
74
+ - **`style`** - no QTI element allows it, so inline formatting such as `font-size` cannot be kept. On `<img>`, a pixel or percentage `width`/`height` in the style is converted to the `width`/`height` attribute so image sizing is preserved.
75
+ - **`aria-*`** - QTI allows only `aria-controls`, `aria-describedby`, `aria-flowto`, `aria-label`, `aria-labelledby`, `aria-level`, `aria-live`, `aria-orientation` and `aria-owns`. Others, such as `aria-hidden` and `aria-selected`, are removed.
76
+
77
+ MathML and sharedpassage stimulus pages (`stimuli/*.html`) are not changed.
78
+
70
79
  ### Q: Why are my alternate responses limited to 10?
71
80
 
72
81
  **A:** There is a fundamental difference in scoring flexibility between QTI and Learnosity:
@@ -265,6 +274,17 @@ This validates all XML files in the directory using **local XSD schemas** (not r
265
274
 
266
275
  Schema URLs are resolved to local files using the XML catalog (`schemas/catalog.xml`).
267
276
 
277
+ Beyond XSD, the validator also mirrors two checks the 1EdTech QTI validator performs:
278
+
279
+ - **Schematron business rules** - 1EdTech's own `.sch` rules (`schemas/qti/v2p1/imsqti_v2p1.sch`, `schemas/qti/v2p2/imsqti_v2p2p4.sch`) run against each QTI item/test. These catch things XSD cannot, such as an attribute that is not allowed on an element.
280
+ - **Package cross-references** - every local `href`/`src`/`data` must exist in the package and be declared in `imsmanifest.xml`. Relative paths are resolved from the folder of the file that contains them (so `stimuli/x.html` inside `items/` is reported missing; use `../stimuli/x.html`). This needs the package root (the folder containing `imsmanifest.xml`).
281
+
282
+ It also flags invalid UTF-8 bytes and C1 control characters (U+0080-U+009F) in any XML file.
283
+
284
+ You can pass a `.zip` instead of a folder (`pnpm run validate:qti ./package.zip`). The archive itself is checked first (integrity, `imsmanifest.xml` at the zip root, entry names, duplicates, OS junk files), then extracted to a temporary folder and validated as above. This is closest to how the 1EdTech validator receives a package.
285
+
286
+ The script exits `1` when any file, the zip container or the cross-references report a problem, `0` when all are clean, and `2` for usage errors, so it can gate CI.
287
+
268
288
  ### Q: Why does validation fail but conversion succeeds?
269
289
 
270
290
  **A:** The converter may produce technically valid but schema-non-compliant XML in some edge cases. Check diagnostics for clues and report issues.
@@ -279,7 +279,7 @@ lcon qti-to-learnosity \
279
279
 
280
280
  The library equivalent is `{ preserveAssetFilenames: true }`. The `--preserve-asset-filenames` flag is available on both `qti-to-learnosity` and `qti-package-to-learnosity`; the API option applies to both corresponding library conversions. This restores the original final QTI basename, such as `logo.png`, in both JSON URLs and bundle paths. It is compatibility behavior: if different QTI assets request the same basename, conversion reports a collision instead of silently overwriting an asset.
281
281
 
282
- **Learnosity → QTI** (`learnosity-to-qti`, `learnosity-to-qti-package`) — rewrite the asset prefix in the generated QTI. When omitted, the default prefix is `./assets`, so a reference resolves to `./assets/<filename>` (matching the packaged `assets/` folder):
282
+ **Learnosity → QTI** (`learnosity-to-qti`, `learnosity-to-qti-package`) — rewrite the asset prefix in the generated QTI. When omitted, the default prefix is `./assets` for `learnosity-to-qti` (a reference resolves to `./assets/<filename>`, next to the item), and `../assets` for `learnosity-to-qti-package`, because items and stimuli sit in `items/` and `stimuli/` one folder below the package's `assets/` folder:
283
283
 
284
284
  ```bash
285
285
  lcon learnosity-to-qti-package --in ./bundle --out package.zip --custom-asset-url "https://my-cdn.example.com/media"
@@ -199,7 +199,7 @@ The IMS QTI `associateInteraction` presents a flat list of `simpleAssociableChoi
199
199
 
200
200
  - Single or multiple correct responses
201
201
  - Shuffle options support
202
- - Per-option feedback (distractor rationale)
202
+ - Per-option feedback (distractor rationale). Written as a standard QTI `<feedbackBlock>` nested inside each `<simpleChoice>` (identified by the choice identifier, `showHide="show"`), with response processing that copies the response into the `FEEDBACK` outcome so the feedback displays when that choice is selected. Reading QTI also still accepts the older `simpleChoice/@feedbackBlock` attribute form.
203
203
 
204
204
  ---
205
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@learnosity/lib-qti-converter",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "description": "QTI ↔ Learnosity JSON converter",
6
6
  "license": "MIT",
@@ -73,18 +73,18 @@
73
73
  },
74
74
  "devDependencies": {
75
75
  "@arethetypeswrong/cli": "^0.18.5",
76
- "@types/node": "^26.6.2",
77
- "@typescript-eslint/eslint-plugin": "^8.70.0",
78
- "@typescript-eslint/parser": "^8.70.0",
76
+ "@types/node": "^26.6.5",
77
+ "@typescript-eslint/eslint-plugin": "^8.71.2",
78
+ "@typescript-eslint/parser": "^8.71.2",
79
79
  "@typescript/native": "npm:typescript@^7.0.2",
80
80
  "@vitest/coverage-v8": "^4.1.11",
81
- "eslint": "^10.11.0",
81
+ "eslint": "^10.12.0",
82
82
  "glob": "^13.0.6",
83
- "publint": "^0.3.24",
84
- "tsdown": "^0.23.0",
83
+ "publint": "^0.3.25",
84
+ "tsdown": "^0.23.1",
85
85
  "tsx": "^4.23.15",
86
86
  "typescript": "npm:@typescript/typescript6@^6.0.2",
87
- "vite": "^8.3.0",
87
+ "vite": "^8.3.4",
88
88
  "vitest": "^4.1.11"
89
89
  },
90
90
  "engines": {
@@ -1,4 +1,4 @@
1
- import { C as mapLearnosityToAst, D as DiagnosticCode, E as parseLearnosityItem, S as downgradeAssessmentTestToQti21, T as sanitizeHtmlContent, _ as md5hex, b as serializeAssessmentItem, c as transformForwardAssetUrlsInXml, d as getAllPassageDataPaths, f as generateItemReference, g as serializeQtiAssetIdentity, h as selectQtiAssetFilename, l as convertQtiAssessmentItemToLearnosity, m as isSupportedQtiAssetPath, n as formatDiagnosticsSummaryTable, p as canonicalizeQtiAssetHref, s as writeDiagnostics, u as parseMetadataTags, v as getAttr$2, w as normalizeXhtmlVoidElements, x as escapeXml$3, y as require_saxes } from "./table-DlY4LGmL.js";
1
+ import { C as buildGapImageSvgFromText, D as parseLearnosityItem, E as normalizeXhtmlVoidElements, O as DiagnosticCode, S as mapLearnosityToAst, T as sanitizeHtmlContent, _ as md5hex, b as serializeAssessmentItem, c as transformForwardAssetUrlsInXml, d as getAllPassageDataPaths, f as generateItemReference, g as serializeQtiAssetIdentity, h as selectQtiAssetFilename, l as convertQtiAssessmentItemToLearnosity, m as isSupportedQtiAssetPath, n as formatDiagnosticsSummaryTable, p as canonicalizeQtiAssetHref, s as writeDiagnostics, u as parseMetadataTags, v as getAttr$2, w as escapeXml$3, x as downgradeAssessmentTestToQti21, y as require_saxes } from "./table-DsKq-B4-.js";
2
2
  import { t as nodeFileAccess } from "./nodeFileAccess-BhCoGDOi.js";
3
3
  import * as path$1 from "node:path";
4
4
  import { join, relative, sep } from "node:path";
@@ -211,7 +211,7 @@ function buildManifest(resources, version = "2.2") {
211
211
  lines.push(" xmlns:imsmd=\"http://www.imsglobal.org/xsd/imsmd_v1p2\"");
212
212
  lines.push(` xmlns:imsqti="${qtiMetadataNs}"`);
213
213
  lines.push(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
214
- lines.push(" xsi:schemaLocation=\"http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/imscp_v1p1.xsd");
214
+ lines.push(` xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1 http://www.imsglobal.org/xsd/qti/qti${qtiVersionTag}/qti${qtiVersionTag}_imscpv1p2_v1p0.xsd`);
215
215
  lines.push(" http://www.imsglobal.org/xsd/imsmd_v1p2 http://www.imsglobal.org/xsd/imsmd_v1p2p2.xsd");
216
216
  lines.push(` ${qtiMetadataNs} ${qtiMetadataXsd}">`);
217
217
  lines.push(" <metadata>");
@@ -424,12 +424,12 @@ function mapSectionsToQti(learnositySections, activityTitle, diagnostics) {
424
424
  * Convert Learnosity sharedpassage to QTI assessmentStimulus
425
425
  */
426
426
  function mapSharedpassageToStimulus(reference, data, diagnostics) {
427
- const contentResult = sanitizeHtmlContent(data.content, `features[${reference}].content`);
427
+ const contentResult = sanitizeHtmlContent(data.content, `features[${reference}].content`, { stripQtiInvalidAttributes: false });
428
428
  diagnostics.push(...contentResult.diagnostics);
429
429
  let stimulusBody = contentResult.content;
430
430
  stimulusBody = convertMediaSpansToObjects(stimulusBody, diagnostics);
431
431
  if (data.heading) {
432
- const headingResult = sanitizeHtmlContent(data.heading, `features[${reference}].heading`);
432
+ const headingResult = sanitizeHtmlContent(data.heading, `features[${reference}].heading`, { stripQtiInvalidAttributes: false });
433
433
  diagnostics.push(...headingResult.diagnostics);
434
434
  stimulusBody = `<h2 class="lrn-hdg">${headingResult.content}</h2>` + stimulusBody;
435
435
  }
@@ -607,8 +607,7 @@ function buildAssessmentTestXml(test, pretty, version) {
607
607
  parts.push(`${indent}<testPart identifier="${escapeXml$3(testPart.identifier)}" navigationMode="${testPart.navigationMode}" submissionMode="${testPart.submissionMode}">`);
608
608
  if (pretty) parts.push("\n");
609
609
  for (const section of testPart.sections) {
610
- let sectionAttrs = `identifier="${escapeXml$3(section.identifier)}" title="${escapeXml$3(section.title)}" visible="${section.visible}"`;
611
- if (section.shuffle !== void 0) sectionAttrs += ` shuffle="${section.shuffle}"`;
610
+ const sectionAttrs = `identifier="${escapeXml$3(section.identifier)}" title="${escapeXml$3(section.title)}" visible="${section.visible}"`;
612
611
  parts.push(`${indent2}<assessmentSection ${sectionAttrs}>`);
613
612
  if (pretty) parts.push("\n");
614
613
  if (section.timeLimits) {
@@ -621,6 +620,10 @@ function buildAssessmentTestXml(test, pretty, version) {
621
620
  parts.push(`${indent3}<selection ${selectionAttrs}/>`);
622
621
  if (pretty) parts.push("\n");
623
622
  }
623
+ if (section.shuffle) {
624
+ parts.push(`${indent3}<ordering shuffle="true"/>`);
625
+ if (pretty) parts.push("\n");
626
+ }
624
627
  for (const itemRef of section.itemRefs) {
625
628
  parts.push(`${indent3}<assessmentItemRef identifier="${escapeXml$3(itemRef.identifier)}" href="${escapeXml$3(itemRef.href)}"/>`);
626
629
  if (pretty) parts.push("\n");
@@ -646,6 +649,12 @@ function buildAssessmentTestXml(test, pretty, version) {
646
649
  * - Sharedpassages → assessmentStimulus resources
647
650
  */
648
651
  /**
652
+ * Items are written to `items/` and stimuli to `stimuli/` (see
653
+ * buildPackageFromActivity), one folder below the package root, so relative
654
+ * asset references must step up with `../` to reach `assets/`.
655
+ */
656
+ const PACKAGE_SUBFOLDER_ASSET_OPTIONS = { packageRootRelativePath: ".." };
657
+ /**
649
658
  * Convert a Learnosity Activity to QTI 2.2/2.1 assessmentTest + items
650
659
  *
651
660
  * @param bundle - Loaded Learnosity bundle
@@ -714,7 +723,7 @@ function convertActivity(bundle, activityRef, options = {}) {
714
723
  diagnostics.push(...serializeDiagnostics);
715
724
  if (serializeResult.xml) items.push({
716
725
  reference: itemRef,
717
- xml: transformForwardAssetUrlsInXml(serializeResult.xml, customAssetUrl),
726
+ xml: transformForwardAssetUrlsInXml(serializeResult.xml, customAssetUrl, PACKAGE_SUBFOLDER_ASSET_OPTIONS),
718
727
  ast: mapResult.ast,
719
728
  diagnostics: [
720
729
  ...parseResult.diagnostics,
@@ -787,7 +796,7 @@ function collectStimuliFromFeatures(features, stimuliByRef, stimuli, diagnostics
787
796
  if (stimulusAst) {
788
797
  const stimulusEntry = {
789
798
  reference: feature.reference,
790
- xml: transformForwardAssetUrlsInXml(serializeAssessmentStimulusAsHtml(stimulusAst), customAssetUrl)
799
+ xml: transformForwardAssetUrlsInXml(serializeAssessmentStimulusAsHtml(stimulusAst), customAssetUrl, PACKAGE_SUBFOLDER_ASSET_OPTIONS)
791
800
  };
792
801
  stimuliByRef.set(feature.reference, stimulusEntry);
793
802
  stimuli.push(stimulusEntry);
@@ -3511,14 +3520,32 @@ const LRN_NORMALIZE_CSS = `/* Utility styles for converter-introduced normalizat
3511
3520
  .lrn-norm-underline {
3512
3521
  text-decoration: underline;
3513
3522
  }
3523
+ /* Converted from <s>, <strike> and <del> */
3524
+ .lrn-norm-strikethrough {
3525
+ text-decoration: line-through;
3526
+ }
3527
+ /* Converted from <ins> */
3528
+ .lrn-norm-inserted {
3529
+ text-decoration: underline;
3530
+ }
3531
+ /* Converted from <mark> */
3532
+ .lrn-norm-highlight {
3533
+ background-color: yellow;
3534
+ color: inherit;
3535
+ }
3514
3536
 
3515
3537
  /* Stimulus content embedded via object element */
3516
- object[type="text/html"] {
3538
+ object[type='text/html'] {
3517
3539
  display: block;
3518
3540
  width: 100vw;
3519
3541
  height: 100vh;
3520
3542
  border: none;
3521
3543
  }
3544
+
3545
+ .lrn-norm-math-entry {
3546
+ width: 100%;
3547
+ box-sizing: border-box; /* so padding/border don't overflow the wrapper */
3548
+ }
3522
3549
  `;
3523
3550
  //#endregion
3524
3551
  //#region ../core/src/learnosity-mapper/buildPackageFromActivity.ts
@@ -3669,6 +3696,33 @@ function buildPackageFromActivity(conversion, options) {
3669
3696
  pkg.resources.push(assetResource);
3670
3697
  }
3671
3698
  }
3699
+ const takenIdentifiers = new Set(pkg.resources.map((r) => r.identifier));
3700
+ for (const item of conversion.items) for (const gapImg of collectGapImgs(item.ast)) {
3701
+ const gapImgPath = gapImg.objectData;
3702
+ if (!gapImgPath.startsWith("assets/gapimgs/") || pkg.entries.has(gapImgPath)) continue;
3703
+ const { svg } = buildGapImageSvgFromText(gapImg.altText, gapImg.identifier);
3704
+ const data = Buffer.from(svg, "utf-8");
3705
+ const baseIdentifier = `asset_${gapImgPath.replace(/^assets\//, "").replace(/[^a-zA-Z0-9]/g, "_")}`;
3706
+ let identifier = baseIdentifier;
3707
+ for (let n = 2; takenIdentifiers.has(identifier); n++) identifier = `${baseIdentifier}_${n}`;
3708
+ takenIdentifiers.add(identifier);
3709
+ pkg.entries.set(gapImgPath, {
3710
+ file: gapImgPath,
3711
+ size: data.length,
3712
+ data
3713
+ });
3714
+ pkg.assets.push({
3715
+ identifier,
3716
+ href: gapImgPath,
3717
+ type: "image/svg+xml"
3718
+ });
3719
+ pkg.resources.push({
3720
+ identifier,
3721
+ type: "webcontent",
3722
+ href: gapImgPath,
3723
+ files: [gapImgPath]
3724
+ });
3725
+ }
3672
3726
  const cssPath = "assets/css/lrn-normalize.css";
3673
3727
  pkg.entries.set(cssPath, {
3674
3728
  file: cssPath,
@@ -3697,6 +3751,15 @@ function buildPackageFromActivity(conversion, options) {
3697
3751
  diagnostics
3698
3752
  };
3699
3753
  }
3754
+ /** All gapImg choices of every graphicGapMatch interaction in an item (single, multiple or in a layout). */
3755
+ function collectGapImgs(ast) {
3756
+ if (!ast) return [];
3757
+ const interactions = [];
3758
+ if (ast.interaction) interactions.push(ast.interaction);
3759
+ if (ast.interactions) interactions.push(...ast.interactions);
3760
+ for (const column of ast.layout?.columns ?? []) for (const widget of column.widgets) if (widget.interaction) interactions.push(widget.interaction);
3761
+ return interactions.flatMap((interaction) => interaction.type === "graphicGapMatch" ? interaction.gapImgs : []);
3762
+ }
3700
3763
  //#endregion
3701
3764
  //#region ../core/src/qti-to-learnosity/loadPackageDirectory.ts
3702
3765
  /**
@@ -3970,4 +4033,4 @@ function itemRefsToFilenames(bundle, itemRefs) {
3970
4033
  //#endregion
3971
4034
  export { buildPackageFromActivity as a, saveQtiContentPackage as c, ensureUniqueFolderName as d, sanitizeFolderName as f, loadPackageDirectory as i, convertQtiPackageToLearnosityBundle as l, processQtiPackageToLearnosity as n, writeLearnosityBundle as o, convertActivity as p, runBatchTask as r, loadLearnosityBundle as s, processLearnosityToQtiPackage as t, mergeActivityPackage as u };
3972
4035
 
3973
- //# sourceMappingURL=batchProcessors-B6Xmhfaz.js.map
4036
+ //# sourceMappingURL=batchProcessors-C7czhqX0.js.map