Skip to content

Commit 9305463

Browse files
committed
HFP-4150 Replace fill-in placeholder in genuine text
1 parent 14bcd3a commit 9305463

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/scripts/h5p-dictation-sentence.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ class Sentence {
317317
* @returns {string} Description text.
318318
*/
319319
getXAPIDescription() {
320-
return this.params.sentence.description || '' ?
321-
`<p>${this.params.sentence.description}</p>` :
320+
return this.params.sentence.description?.length ?
321+
`<p>${this.params.sentence.description
322+
.replaceAll(/_{10,}/gi, H5P.Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT)}</p>` :
322323
'';
323324
}
324325

src/scripts/h5p-dictation.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ class Dictation extends H5P.Question {
644644
// Fallback for h5p-php-reporting, expects en-US
645645
definition.name['en-US'] = definition.name[this.languageTag];
646646
definition.description = {};
647-
definition.description[this.languageTag] = `${this.getDescription()}${placeholders}`;
647+
definition.description[this.languageTag] = `${this.getXAPIDescription()}${placeholders}`;
648648
// Fallback for h5p-php-reporting, expects en-US
649649
definition.description['en-US'] = definition.description[this.languageTag];
650650
definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction';
@@ -758,6 +758,14 @@ class Dictation extends H5P.Question {
758758
return this.params.taskDescription || Dictation.DEFAULT_DESCRIPTION;
759759
}
760760

761+
/**
762+
* Get description for xAPI statement.
763+
* @returns {string} Description for xAPI statement.
764+
*/
765+
getXAPIDescription() {
766+
return this.getDescription().replaceAll(/_{10,}/gi, Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT);
767+
}
768+
761769
/**
762770
* Checks if any sentence's audio playback has started.
763771
* @returns {boolean} True if audio playback has started, false otherwise.
@@ -790,4 +798,7 @@ Dictation.XAPI_REPORTING_VERSION = '1.0.0';
790798
*/
791799
Dictation.FILL_IN_PLACEHOLDER = '__________';
792800

801+
/** @constant {string} FILL_IN_PLACEHOLDER_REPLACEMENT Replacement for FILL_IN_PLACEHOLDER in genuine text. */
802+
Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT = '_________';
803+
793804
export default Dictation;

0 commit comments

Comments
 (0)