'Put a bit of HTML inside a <pre> tag?

How do I put a bit of HTML inside a tag without escaping it? Or am I using an incorrect tag?

P.S. I cannot escape the HTML, it is produced by the server.



Solution 1:[1]

This:

    <pre>
      <&zwj;div>Hello<&zwj;/div>
    </pre>

Prints this:

<div>Hello</div>

Zero Width Joiner = &zwj;

Solution 2:[2]

You need to escape the HTML, like so:

You can use HTML entities that are escaped and printed without compiling.

&#60; // will print <
&#62; // will print >

Using these two, you can print any HTML elements.

&#60;div&#62; // will print <div>

To solve your specific problem, you will need to parse the HTML string and convert the chevrons to these entities.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pelón
Solution 2 AdamMcquiff