0

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

2
  • the only thing wrong here is your misunderstanding of the code tag. Commented Sep 19, 2014 at 19:38
  • So its only 'style'? Commented Sep 19, 2014 at 20:14

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

Ok you have to change the '<' and '>' chars to his corresponding html code: jsfiddle.net/olliestrevel/dL7e41q6
Thank you very much!! But shouldn't the code tag "deactivate" the (also html)code inside?
The code tag just highlight the text into the html tags inside, the mark up render normally
1

Why not just use the HTML5 tag ?

<mark>Text here</mark>

2 Comments

well ... jsfiddle.net/9m3hsorp - but I understand now. Thx for your contribution!
Don't mark everything. Just the part you want marked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.