最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

htmlspecialchars decode - Why does HTML entities are still encoded in Code Block?

programmeradmin2浏览0评论

In the Code Block if I type in reversed character, they are encoded to HTML entities:

  • Input:

  • Output:

    <pre class="wp-block-code"><code>'&#91;] </code></pre>
    

Meanwhile, if I put them in the custom HTML block, the output characters aren't encode:

  • Input:

  • Output:

    <code>'[]</code>
    <code class="'[]"></code>
    <code><code class="'[]"></code></code>
    <pre class="wp-block-code"><code>'[]</code></pre>
    

I wonder why this should be the case? I enable troubleshooting mode and use the Twenty Twenty-One theme.

Related: Why does the custom HTML block not preserve the HTML characters?

In the Code Block if I type in reversed character, they are encoded to HTML entities:

  • Input:

  • Output:

    <pre class="wp-block-code"><code>'&#91;] </code></pre>
    

Meanwhile, if I put them in the custom HTML block, the output characters aren't encode:

  • Input:

  • Output:

    <code>'[]</code>
    <code class="'[]"></code>
    <code><code class="'[]"></code></code>
    <pre class="wp-block-code"><code>'[]</code></pre>
    

I wonder why this should be the case? I enable troubleshooting mode and use the Twenty Twenty-One theme.

Related: Why does the custom HTML block not preserve the HTML characters?

Share Improve this question asked Jan 7, 2022 at 10:05 OokerOoker 3323 silver badges23 bronze badges 2
  • 1 This is the whole point of the code block. It’s for displaying actual code. You can’t do that if the characters aren’t encoded or it could be interpreted as HTML. – Jacob Peattie Commented Jan 7, 2022 at 11:26
  • do you mean the code block, or the <code> tag? Because when I put it in the custom html block, the <code> tag doesn't encode the characters – Ooker Commented Jan 7, 2022 at 11:32
Add a comment  | 

1 Answer 1

Reset to default 1

The Code Block is to display things just as you typed them, so it may encode to ensure no code actually executes.

The HTML block is the reverse - it is to execute code exactly as you typed it, so it doesn't encode.

This is intentional, so you can either show or execute code, depending on your needs. :)

发布评论

评论列表(0)

  1. 暂无评论