JSX elements are syntax sugar for React DOM elements, which are objects. A string on it's own won't carry information about things such as font size or weight, so it may be best to represent the whole thing by JSX. I think something along these lines would do it:
const text = 'Welcome :: my ;;';
const myWorld = (
<span>
{text.split(' ').map((word, index) => {
const space = index == 0 ? '' : ' ';
if (word == '::') {
return (<strong key={index}>{space + "to"}</strong>);
} else if (word == ';;') {
return (<strong key={index}>{space + "world"}</strong>);
}
return (<span key={index}>{space + word}</span>);
}}
</span>
);
If you need the replacements to be dynamic, you can create a function for this:
// Example `replacements` object:
// {
// '::': 'to',
// ';;': 'world',
// }
function replaceWithEmphasis(text, replacements) {
const words = text.split(' ');
return (
<span>
{
words.map((word, index) => {
const replaced = replacements[word];
// Preserve spaces between words
const space = index == 0 ? '' : ' ';
if (replaced != null) {
return <strong key={index}>{space + replaced}</strong>;
} else {
return <span key={index}>{space + word}</span>;
}
})
}
</span>
);
}