Skip to content

Commit

Permalink
HFP-4150 Replace fill-in placeholder in genuine text
Browse files Browse the repository at this point in the history
  • Loading branch information
otacke committed Oct 31, 2024
1 parent 14bcd3a commit 9305463
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/scripts/h5p-dictation-sentence.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,9 @@ class Sentence {
* @returns {string} Description text.
*/
getXAPIDescription() {
return this.params.sentence.description || '' ?
`<p>${this.params.sentence.description}</p>` :
return this.params.sentence.description?.length ?
`<p>${this.params.sentence.description
.replaceAll(/_{10,}/gi, H5P.Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT)}</p>` :
'';
}

Expand Down
13 changes: 12 additions & 1 deletion src/scripts/h5p-dictation.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class Dictation extends H5P.Question {
// Fallback for h5p-php-reporting, expects en-US
definition.name['en-US'] = definition.name[this.languageTag];
definition.description = {};
definition.description[this.languageTag] = `${this.getDescription()}${placeholders}`;
definition.description[this.languageTag] = `${this.getXAPIDescription()}${placeholders}`;
// Fallback for h5p-php-reporting, expects en-US
definition.description['en-US'] = definition.description[this.languageTag];
definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction';
Expand Down Expand Up @@ -758,6 +758,14 @@ class Dictation extends H5P.Question {
return this.params.taskDescription || Dictation.DEFAULT_DESCRIPTION;
}

/**
* Get description for xAPI statement.
* @returns {string} Description for xAPI statement.
*/
getXAPIDescription() {
return this.getDescription().replaceAll(/_{10,}/gi, Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT);
}

/**
* Checks if any sentence's audio playback has started.
* @returns {boolean} True if audio playback has started, false otherwise.
Expand Down Expand Up @@ -790,4 +798,7 @@ Dictation.XAPI_REPORTING_VERSION = '1.0.0';
*/
Dictation.FILL_IN_PLACEHOLDER = '__________';

/** @constant {string} FILL_IN_PLACEHOLDER_REPLACEMENT Replacement for FILL_IN_PLACEHOLDER in genuine text. */
Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT = '_________';

export default Dictation;

0 comments on commit 9305463

Please sign in to comment.