Adam
Adam

Reputation: 2031

Nesting <pre> and </pre> tags

Ok, so weird one. Is it possible to escape a </pre> tag in a <pre> block?

I have a project wiki in Redmine. It uses Coderay for syntax highlighting, like so:

<pre>
<code class="JavaScript">

//your JS code here

</code>
</pre>

I'm writing a wiki explaining to our users how to use Redmine. I need to document above... but this results in nested <pre> tags:

<pre>
<pre>
<code class="JavaScript">

//your JS code here

</code>
</pre>
</pre>

Output:

<pre>
<code class="[LANGUAGE NAME]">

//your JS code here

</code>

The last </pre> is missing as it closes the previous <pre> tag. Is there any way I can escape the </pre> so that it is displayed?

Desired Ouput:

<pre>
<code class="[LANGUAGE NAME]">

//your JS code here

</code>
</pre>

Upvotes: 1

Views: 1608

Answers (1)

zzzzBov
zzzzBov

Reputation: 179284

If you want <, >, ", and & characters to be rendered as text in HTML you need to use their HTML entity counterparts:

< becomes &lt;
> becomes &gt;
" becomes &quot;
& becomes &amp;

<pre>
    &lt;pre&gt;
        foo bar baz
    &lt;/pre&gt;
</pre>

In some special cases you may want ' escaped, in which case you should use &#39; (or &apos; if you don't need to worry about old versions of IE).

Upvotes: 4

Related Questions