Repository navigation
Keep text after a formula when reopening a QTI question #6297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AlexVelezLl
merged 3 commits into
learningequality:unstable
from
rtibblesbot:issue-6269-7cf169
Oct 7, 2026
+277
−39
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
contentcuration/contentcuration/frontend/shared/views/QTIEditor/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## QTI Editor | ||
|
|
||
| Edits an exercise's assessment items stored as [QTI 3](https://www.imsglobal.org/spec/qti/v3p0/impl) XML in `raw_data`. Rendered by `channelEdit/components/AssessmentTab/AssessmentTab.vue`. | ||
|
|
||
| ### Flow | ||
| 1. `index.vue` lists the items; each is a `components/QTIItemEditor`. | ||
| 2. `composables/useQtiItem.js` parses `raw_data` with `serialization/parseItem.js` into interaction blocks (`bodyXml` + `responseDeclarations`), hints and item metadata. | ||
| 3. `components/InteractionSection` resolves each block's descriptor and question type with `composables/useInteractionDescriptor.js`. | ||
| 4. The interaction's `Editor.vue` (`interactions/index.js`) edits a plain state object through `composables/useInteraction.js`: `descriptor.parse` → state → `descriptor.buildXML` → `descriptor.validate`. | ||
| 5. `useQtiItem` rebuilds the full item with `serialization/assembleItem.js`; `QTIItemEditor` emits `update:rawData`. | ||
|
|
||
| `validateItem.js` `validateQtiItem` runs the same parse and validation headless, without the Vue editors. | ||
|
|
||
| ### Layout | ||
| - `interactions/<type>/` — one per QTI interaction: | ||
| - `Descriptor.js` — subclass of `InteractionDescriptor`: matches the element, picks the question type, delegates to `parse.js` and `validation.js`. | ||
| - `parse.js` — XML ↔ state. | ||
| - `validation.js` — state → error codes. | ||
| - `Editor.vue` — the UI; absent for headless interactions (`HEADLESS_INTERACTIONS`). | ||
| - `interactions/descriptors.js` — descriptor registry, free of `.vue` imports. `interactions/index.js` adds the editors. | ||
| - `serialization/` — item-level parse/assemble, hints (`qti-catalog-info`), XML helpers (`xml.js`), response declarations (`qti/`). | ||
| - `components/` — shared UI: hints, chip lists, toolbars, question type selector. | ||
|
|
||
| ### Adding an interaction | ||
| 1. Create `interactions/<type>/` with `Descriptor.js`, `parse.js`, `validation.js` and `Editor.vue`. | ||
| 2. Register the descriptor in `interactions/descriptors.js` and the editor in `interactions/index.js`. | ||
| 3. Add its question types to `constants.js` and strings to `qtiEditorStrings.js`. | ||
|
|
||
| ### Rich text fields | ||
| Prompts, choices, items and hints are edited in `TipTapEditor` with `format="html"`. | ||
|
|
||
| > [!IMPORTANT] | ||
| > In `parse`, read any field TipTap loads as HTML with `getContentHTML` (or `getPromptHTML`) from `serialization/xml.js`, never `innerHTML` or `XMLSerializer`. XML serialization self-closes empty elements (`<span data-latex="…"/>`); the HTML parser doesn't treat `/>` as closing, so everything after it is nested inside and lost. | ||
| > | ||
| > On build, pass the HTML to `buildXmlNode({ innerHTML })`, which parses it as HTML and re-creates it as XML. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...ntentcuration/frontend/shared/views/QTIEditor/serialization/__tests__/formulaItem.spec.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { assembleItemXml } from '../assembleItem'; | ||
| import { parseItem } from '../parseItem'; | ||
| import { choiceInteractionDescriptor } from '../../interactions/choice/Descriptor'; | ||
| import { orderingInteractionDescriptor } from '../../interactions/ordering/Descriptor'; | ||
| import { matchInteractionDescriptor } from '../../interactions/match/Descriptor'; | ||
| import { associateInteractionDescriptor } from '../../interactions/associate/Descriptor'; | ||
| import { useEditor } from '../../../TipTapEditor/TipTapEditor/composables/useEditor'; | ||
| import { QuestionType } from '../../constants'; | ||
|
|
||
| const CONTENT = '<p>Solve <span data-latex="x^2"></span> for x</p>'; | ||
|
|
||
| const INTERACTIONS = [ | ||
| { | ||
| name: 'choice', | ||
| descriptor: choiceInteractionDescriptor, | ||
| questionType: QuestionType.SINGLE_SELECT, | ||
| state: { | ||
| prompt: CONTENT, | ||
| choices: [ | ||
| { id: 'a', content: CONTENT, correct: true, fixed: false }, | ||
| { id: 'b', content: '<p>Other</p>', correct: false, fixed: false }, | ||
| ], | ||
| shuffle: false, | ||
| orientation: 'vertical', | ||
| showAnswerCount: true, | ||
| }, | ||
| option: state => state.choices[0].content, | ||
| }, | ||
| { | ||
| name: 'ordering', | ||
| descriptor: orderingInteractionDescriptor, | ||
| questionType: QuestionType.ORDERING, | ||
| state: { | ||
| prompt: CONTENT, | ||
| items: [ | ||
| { id: 'a', content: CONTENT }, | ||
| { id: 'b', content: '<p>Other</p>' }, | ||
| ], | ||
| orientation: 'vertical', | ||
| shuffle: true, | ||
| }, | ||
| option: state => state.items[0].content, | ||
| }, | ||
| { | ||
| name: 'match', | ||
| descriptor: matchInteractionDescriptor, | ||
| questionType: QuestionType.MATCH, | ||
| state: { | ||
| prompt: CONTENT, | ||
| rows: [{ id: 'row_a', content: CONTENT, matches: [{ id: 'b', content: '<p>Other</p>' }] }], | ||
| distractors: [], | ||
| }, | ||
| option: state => state.rows[0].content, | ||
| }, | ||
| { | ||
| name: 'associate', | ||
| descriptor: associateInteractionDescriptor, | ||
| questionType: QuestionType.ASSOCIATE, | ||
| state: { | ||
| prompt: CONTENT, | ||
| pairs: [ | ||
| [ | ||
| { id: 'a', content: CONTENT }, | ||
| { id: 'b', content: '<p>Other</p>' }, | ||
| ], | ||
| ], | ||
| distractors: [], | ||
| }, | ||
| option: state => state.pairs[0][0].content, | ||
| }, | ||
| ]; | ||
|
|
||
| const load = html => { | ||
| const { initializeEditor, editor } = useEditor(); | ||
| initializeEditor(html, 'edit'); | ||
| const loaded = editor.value.getHTML(); | ||
| editor.value.destroy(); | ||
| return loaded; | ||
| }; | ||
|
|
||
| const buildItem = interaction => { | ||
| const { bodyXml, responseDeclarations } = interaction.descriptor.buildXML( | ||
| interaction.state, | ||
| interaction.questionType, | ||
| ); | ||
| return parseItem( | ||
| assembleItemXml({ | ||
| identifier: 'item_1', | ||
| title: 'Question', | ||
| language: 'en', | ||
| bodyXml, | ||
| responseDeclarations, | ||
| hints: [{ id: 'hint_1', content: CONTENT }], | ||
| }), | ||
| ); | ||
| }; | ||
|
|
||
| describe.each(INTERACTIONS)('a $name item with text after a formula', interaction => { | ||
| let state; | ||
|
|
||
| beforeAll(() => { | ||
| const [parsed] = buildItem(interaction).interactions; | ||
| state = interaction.descriptor.parse(parsed.bodyXml, parsed.responseDeclarations); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['prompt', () => state.prompt], | ||
| ['option', () => interaction.option(state)], | ||
| ])('keeps the text in its %s once loaded into the editor', (_, read) => { | ||
| expect(load(read())).toBe(CONTENT); | ||
| }); | ||
| }); | ||
|
|
||
| it('keeps the text after a formula in a hint once loaded into the editor', () => { | ||
| const item = buildItem(INTERACTIONS[0]); | ||
| expect(load(item.hints[0].content)).toBe(CONTENT); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (pre-existing, follow-up): This makes a formula-only option match its retyped twin, which is right. The opposite case is still broken:
richTextComparisonKeyuses only the text whenever there is any, and formulas contribute no text. So<p>Solve <span data-latex="x^2"></span> for x</p>and<p>Solve <span data-latex="y^3"></span> for x</p>both key to"Solve for x". I confirmed thatbuildMatchInteractionXMLthen merges two rows' answersx² is it/y³ is itinto a single choice (m1,match-max="2"), and they³content is lost. Choice/ordering validation will also report them as duplicates. Now that formula text survives reopening, authors are more likely to hit this. Could we file an issue to includedata-latex(and maybeimgsrc) in the key? Not for this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside this PR's scope — tracked as #6301 under #6103.
Written by rtibblesbot, an LLM-based coding agent.