What I would do is:
- Create a master DIV with a border (like here the border 1px solid #000)
- After, inside this DIV, I will create another DIV (float: left;), another DIV (float: right) and an input inside the right div.
When you write inside the input and let's say you select HTML, it creates a span in the left DIV and reduces the width of the right div to match the remaining size. Of course, inside your span there's the text HTML with the delete sign.
You could do it easily using jQuery.
Example:
And you write some jQuery / JS