如何从JAVA中的ckeditor生成的html中提取纯文本

n92*_*n92 4 email jakarta-mail plaintext spam ckeditor

我正在使用ckeditor撰写电子邮件,我使用它生成的html发送html电子邮件广告我也需要文本版本,因此在电子邮件中同时使用html和纯文本版本将避免垃圾邮件.

在java中从ckeditor html代码获取文本的方法是什么?

ole*_*leq 12

这是一个非常简单的JavaScript调用:

CKEDITOR.instances.yourEditorInstance.getData() 
Run Code Online (Sandbox Code Playgroud)

返回:

<h1>Apollo 11</h1>    
<p><b>Apollo 11</b> was the spaceflight that landed the first humans, Americans <a href="http://en.wikipedia.org/wiki/Neil_Armstrong" title="Neil Armstrong">Neil Armstrong</a> and <a href="http://en.wikipedia.org/wiki/Buzz_Aldrin" title="Buzz Aldrin">Buzz Aldrin</a>, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.</p>
Run Code Online (Sandbox Code Playgroud)

然而:

CKEDITOR.instances.yourEditorInstance.editable().getText() 
Run Code Online (Sandbox Code Playgroud)

返回:

Apollo 11
Apollo 11 was the spaceflight that landed the first humans, Americans Neil Armstrong and Buzz Aldrin, on the Moon on July 20, 1969, at 20:18 UTC. Armstrong became the first to step onto the lunar surface 6 hours later on July 21 at 02:56 UTC.
Run Code Online (Sandbox Code Playgroud)

  • getText() 在一行中显示所有内容。下一行不显示第二个“Apollo 11” (2认同)