My code right now is
const replace = (note) => {
return DOMPurify.sanitize(
note.replace(
/\S/g,
"<span class='letter' style='display: inline-block'>$&</span>"
)
)
};
as you can see in the span, I'm setting style as display inline-block directly. However instead, I want to set the style as some kind of variable like so:
const test = (note, style) => {
const styles = {display: 'inline-block'};
return DOMPurify.sanitize(
note.replace(
/\S/g,
"<span class='letter' style={styles}>$&</span>"
)
)
};
but this isn't working because the {styles} inside the span doesn't know that I'm referring to my styles variable. Does anyone know the proper syntax to make this work?
"<span class='letter' style='" + styles + "'>$&</span>". But,stylesshould be declared like this:const styles = "display:inline-block;"`<span class='letter' style=${styles}>$&</span>`