In this episode, we first do a quick recap on how to use the x-text
directive to output text in your components. We go over how it works on pretty much any HTML element that can contain text—like using x-text
inside an h1 to display "hello world," or running expressions such as toUpperCase()
inside x-text
to transform the output.
After that, we explore a big limitation of x-text
: it only outputs raw text, so any HTML tags inside your data will just be rendered as plain strings. This means if you're dealing with content like server-rendered markdown or any HTML fragments, x-text
isn't going to cut it.
That's where x-html
comes in! We look at how swapping to x-html
allows you to output actual HTML (like paragraphs and strong tags) from your data, so it renders correctly in the browser. There's also a quick but very important security warning about not using x-html
on untrusted user input, since that could open you up to cross-site scripting attacks.
Finally, we tee up the next episode, where we'll put this knowledge to work by building a markdown parser with Alpine.js.