@@ -1784,7 +1784,7 @@ export default class RichText extends WidthSizable( Node ) {
17841784 * Stringifies an HTML subtree defined by the given element, but removing certain tags that we don't need for
17851785 * accessibility (like <a>, <span>, etc.), and adding in tags we do want (see ACCESSIBLE_TAGS).
17861786 */
1787- public static himalayaElementToAccessibleString ( element : HimalayaNode ) : string {
1787+ public static himalayaElementToAccessibleString ( element : HimalayaNode , keepFormattingTags = true ) : string {
17881788 if ( isHimalayaTextNode ( element ) ) {
17891789 return richTextContentToString ( element . content ) ;
17901790 }
@@ -1797,11 +1797,18 @@ export default class RichText extends WidthSizable( Node ) {
17971797 content = StringUtils . wrapDirection ( content , dir ) ;
17981798 }
17991799
1800- if ( _ . includes ( ACCESSIBLE_TAGS , element . tagName ) ) {
1800+ if ( keepFormattingTags && _ . includes ( ACCESSIBLE_TAGS , element . tagName ) ) {
18011801 return `<${ element . tagName } >${ content } </${ element . tagName } >` ;
18021802 }
18031803 else {
1804- return content ;
1804+
1805+ // We are removing all formatting tags. For breaks, add a space as that was the most likely intent.
1806+ if ( element . tagName === 'br' ) {
1807+ return ` ${ content } ` ;
1808+ }
1809+ else {
1810+ return content ;
1811+ }
18051812 }
18061813 }
18071814 else {
@@ -1813,13 +1820,13 @@ export default class RichText extends WidthSizable( Node ) {
18131820 * Transforms a given string with HTML markup into a string suitable for screen readers.
18141821 * Preserves basic styling tags while removing non-accessible markup.
18151822 */
1816- public static getAccessibleStringProperty ( stringProperty : TReadOnlyProperty < string > ) : TReadOnlyProperty < string > {
1823+ public static getAccessibleStringProperty ( stringProperty : TReadOnlyProperty < string > , keepFormattingTags = true ) : TReadOnlyProperty < string > {
18171824 return new DerivedStringProperty ( [ stringProperty ] , string => {
18181825 const rootElements : HimalayaNode [ ] = himalayaVar . parse ( string ) ;
18191826
18201827 let accessibleString = '' ;
18211828 rootElements . forEach ( element => {
1822- accessibleString += RichText . himalayaElementToAccessibleString ( element ) ;
1829+ accessibleString += RichText . himalayaElementToAccessibleString ( element , keepFormattingTags ) ;
18231830 } ) ;
18241831
18251832 return accessibleString ;
0 commit comments