From 3bf3d245181e9144f4bf12c3a9bfaeedaa2857a7 Mon Sep 17 00:00:00 2001 From: Jonathan Olson Date: Thu, 8 Dec 2022 12:15:08 -0700 Subject: [PATCH] Wrap chemical formulas in LTR marks, see https://github.com/phetsims/chipper/issues/1355 --- js/util/StringUtils.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/js/util/StringUtils.js b/js/util/StringUtils.js index 1f866887..ea34b4f5 100644 --- a/js/util/StringUtils.js +++ b/js/util/StringUtils.js @@ -286,6 +286,28 @@ const StringUtils = { return string.replace( /\u202a/g, '[LTR]' ).replace( /\u202b/g, '[RTL]' ).replace( /\u202c/g, '[POP]' ); }, + /** + * Wraps a string with embedding marks for LTR display. + * @public + * + * @param {string} string + * @returns {string} + */ + wrapLTR: function( string ) { + return LTR + string + POP; + }, + + /** + * Wraps a string with embedding marks for RTL display. + * @public + * + * @param {string} string + * @returns {string} + */ + wrapRTL: function( string ) { + return LTR + string + POP; + }, + /** * Assert that a template var is in a string. Useful for translated strings with a template var pattern like * "Hello {{meanName}}" --> "Hello goofball". See StringUtils.fillIn() for base usages of template var pattern.