HTML highlighting using prism.js

I cannot highlight html with prism.js because it removes the markup just by typing the text. The following code inside the pre tag shows only text. I have a class for the "code" tag set to "language-markup".

    <table class="data-table">
        <tr>
            <td>Title</td>
            <td>Amount</td>
        </tr>
        <tr>
            <td>Shorts</td>
            <td>£1.00</td>
        </tr>   
        <tr>
            <td>Shorts</td>
            <td>£1.00</td>
        </tr>           
    </table>

shows how

            Title
            Amount


            Shorts
            £1.00


            Shorts
            £1.00
+4
source share
2 answers

You need to avoid starting tags with &lt;. The easiest way is to insert the html code into the pre-tag, and then search and replace for all characters <.

This should work:

&lt;table class="data-table">
    &lt;tr>
        &lt;td>Title&lt;/td>
        &lt;td>Amount&lt;/td>
    &lt;/tr>
    &lt;tr>
        &lt;td>Shorts&lt;/td>
        &lt;td>£1.00&lt;/td>
    &lt;/tr>   
    &lt;tr>
        &lt;td>Shorts&lt;/td>
        &lt;td>£1.00&lt;/td>
    &lt;/tr>           
&lt;/table>
+1
source

Alternatively, you can wrap your code with <script type="prism-html-markup"> your code </script>

+1
source

Source: https://habr.com/ru/post/1537695/


All Articles