简体   繁体   English

HTML代码段的HTML代码块?

[英]Html code block for html snippet?

This has to be the most frustrating thing ever lol. 这一定是有史以来最令人沮丧的事情。

I am using prettify.js to give the code syntax color, but with prettify.js or prism.js when I encode the html I have to write it like below with a period before .&lt , otherwise my syntax is messed up with # tags. 我正在使用prettify.js来提供代码语法的颜色,但是在对html进行编码时,使用prettify.js或prism.js时,我必须像下面这样写,前加一个句点.&lt

<pre class="prettyprint">.&lt;div class=&quot;modal modal--medium modal--middle&quot;&gt;
    &lt;div class=&quot;center-module&quot;&gt;
        &lt;input type=&quot;text&quot; placeholder=&quot;email&quot;&gt;
        &lt;button class=&quot;button button--primary&quot;&gt;send&lt;/button&gt;
    &lt;/div&gt;
&lt;/div&gt;</pre>

With a period the above shows 以上期间显示

.<div class="modal modal--medium modal--middle">
    <div class="center-module">
        <input type="text" placeholder="email">
        <button class="button button--primary">send</button>
    </div>
</div>

Without a period before &lt 之前没有&lt

#<DIV class="modal modal--medium modal--middle"#>
    #<DIV class="center-module"#>
        #<INPUT type="text" placeholder="email"#>
        #<BUTTON class="button button--primary"#>send#</BUTTON>
    #</DIV#>
#</DIV#>

My question is how/why is the &lt;div being wrapped with .tag <span class="tag">&lt;div</span> by prettify.js? 我的问题是为什么prettify.js将&lt;div.tag <span class="tag">&lt;div</span>包装? Why do I need to add some character before the &lt;div for it to work? 为什么我需要在&lt;div之前添加一些字符才能使其正常工作? Any ideas why it is doing this? 有什么想法为什么要这样做吗?

FYI any character before the &lt;div will show the block just fine, but without a character when the &lr;div is wrapped by the <pre></pre> tags it shows a block with # tags. 仅供参考, &lt;div之前的任何字符都可以很好地显示该块,但是当&lr;div<pre></pre>标记包装时,没有任何字符,它将显示带有#标记的块。

You may want to take a look at the HTML5 code tag : 您可能需要看一下HTML5代码标签

<code>
  <DIV class="modal modal--medium modal--middle">
    <DIV class="center-module">
      <INPUT type="text" placeholder="email">
      <BUTTON class="button button--primary">send</BUTTON>
    </DIV>
  </DIV>
</code>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM