diff --git a/src/scripts/h5p-dictation-sentence.js b/src/scripts/h5p-dictation-sentence.js index 878133c..4b6da7c 100644 --- a/src/scripts/h5p-dictation-sentence.js +++ b/src/scripts/h5p-dictation-sentence.js @@ -317,8 +317,9 @@ class Sentence { * @returns {string} Description text. */ getXAPIDescription() { - return this.params.sentence.description || '' ? - `
${this.params.sentence.description}
` : + return this.params.sentence.description?.length ? + `${this.params.sentence.description + .replaceAll(/_{10,}/gi, H5P.Dictation.FILL_IN_PLACEHOLDER_REPLACEMENT)}
` : ''; } diff --git a/src/scripts/h5p-dictation.js b/src/scripts/h5p-dictation.js index 6c922ed..49a3c0f 100644 --- a/src/scripts/h5p-dictation.js +++ b/src/scripts/h5p-dictation.js @@ -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'; @@ -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. @@ -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;