I'm suing svelte and reactivity here is key, I want to color as I type #hashtags in my text, code:
<script>
let tweet = "";
function blueColor() {
tweet = tweet.replace(/<a\b[^>]*>|\B(#[^\W_][\w-]*)/gi, function (m, p) {
return p ? '<span class="hash_tag">' + m + '</span>' : m;
});
}
</script>
<input
id="message"
rows="4"
bind:value={ tweet }
on:input={ blueColor }
class="block p-2.5 w-full
rounded-lg border text-white focus:outline-none focus:ring
bg-gray-700 border-gray-600 placeholder-gray-400
hover:border-blue-600"
placeholder="What's happening..."
maxlength="200"
/>
as you can see I can replace it while I am typing but I get this as output:
as <span class="hash_tag">#hashtag</span>
Do you have any quick solution?