简体   繁体   English

如何从Highlight.js元素获取纯文本?

[英]How to get plain text from highlight.js element?

I use highlight.js this way: 我以这种方式使用Highlight.js:

<div class="ex1" contenteditable="true">
   <pre>
      <code id="script_code" class="pgsql"></code>
   </pre>
</div>

User can edit the code. 用户可以编辑代码。 When user wants to save changes I need to get plain text. 当用户想要保存更改时,我需要获取纯文本。

When I get it: 当我得到它:

var pscriptText = document.getElementById(divCodeView).innerHTML;

I see the tags. 我看到了标签。 How to get the plain text? 如何获得纯文本?

使用textContent而不是innerHTML:

var pscriptText = document.getElementById(divCodeView).textContent;

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

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