What do I need to escape inside the html
 tag

前端 未结 4 1208
栀梦
栀梦 2021-02-07 03:19

I use the

 tag in my blog to post code. I know I have to change < to < and > to >         


        
4条回答
  •  误落风尘
    2021-02-07 03:48

    What happens if you use the

     tag to display HTML markup on your blog:

    Use a span tag with style attribute to hightlight words

    This will pass HTML validation, but does it produce the expected result? No. The correct way is:

    Use a <span style="background: yellow;">span tag with style attribute</span> to hightlight words

    Another example: if you use the pre tag to display some other language code, the HTML encoding is still required:

    if (i && j) return;

    This might produce the expected result but does it pass HTML validation? No. The correct way is:

    if (i && j) return;

    Long story short, HTML-encode the content of a pre tag just the way you do with other tags.

提交回复
热议问题