Skip to content

Commit

Permalink
strip br tags from voicing output using himalaya, phetsims/scenery#1314
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph authored and jessegreenberg committed Feb 7, 2022
1 parent 6111cf6 commit a559907
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion js/accessibility/voicing/voicingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class VoicingManager extends Announcer {
}

// embedding marks (for i18n) impact the output, strip before speaking
const stringToSpeak = stripEmbeddingMarks( utterance.getTextToAlert( this.respectResponseCollectorProperties ) );
const stringToSpeak = removeBrTags( stripEmbeddingMarks( utterance.getTextToAlert( this.respectResponseCollectorProperties ) ) );
const speechSynthUtterance = new SpeechSynthesisUtterance( stringToSpeak );
speechSynthUtterance.voice = this.voiceProperty.value;
speechSynthUtterance.pitch = this.voicePitchProperty.value;
Expand Down Expand Up @@ -617,6 +617,22 @@ class VoicingQueueElement {
}


/**
* @param {Object} element - returned from himalaya parser, see documentation for details.
* @returns {boolean}
*/
const isNotBrTag = element => !( element.type.toLowerCase() === 'element' && element.tagName.toLowerCase() === 'br' );

/**
* Remove <br> or <br/> tags from a string
* @param {string} string - plain text or html string
* @returns {string}
*/
function removeBrTags( string ) {
const parsedAndFiltered = himalaya.parse( string ).filter( isNotBrTag );
return himalaya.stringify( parsedAndFiltered );
}

const voicingManager = new VoicingManager();

// @public - Priority levels that can be used by Utterances providing the `announcerOptions.priority` option.
Expand Down

0 comments on commit a559907

Please sign in to comment.