rudib
rudib

Reputation: 227

Highlight PHP code in HTML with code tag - bug?

I'm using highlight.js to highlight the following code:

<pre><code class="hljs php">
echo '<table border="1">';
echo '<tr>';
    foreach ($keys as &$k)
    {
    echo '<th>'.$k.'</th>';
    }
 echo '</tr>';
echo '</table>'
</code></pre>

AAAnd all the table tags are rendered by the browser and not displayed as clear text... see for yourself(jsfiddle without highlight.js)

Is it me oris there something wrong with the code tags? Any Ideas? Thank you

Upvotes: 0

Views: 504

Answers (2)

Ollie Strevel
Ollie Strevel

Reputation: 871

Your tags:

<pre><code bla bla> must end </pre></code>

Final

<pre><code bla bla> must end </code></pre>

EDIT: Answer in the comments:

<pre>
    <code class="hljs php">
        &lt;table&gt;
            &lt;tr&gt;
                &lt;th&gt;1&lt;/th&gt;
                &lt;th&gt;2&lt;/th&gt;
                &lt;th&gt;3&lt;/th&gt;
                &lt;th&gt;4&lt;/th&gt;
                &lt;th&gt;5&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/table&gt;
    </code>
</pre>

Its nessecsary to HTML Escape the '<' and the '>'. This can be achieved with this php Function

Upvotes: 2

Typeconor
Typeconor

Reputation: 13

Why not just use the HTML5 tag ?

<mark>Text here</mark>

Upvotes: 1

Related Questions