How to extract plain text from ckeditor generated html in JAVA

蓝咒 提交于 2019-12-01 05:07:22

问题


I am using ckeditor to compose the emails, I am using the html generated by it to send the html emails ad i also need the text version also, So having both html and plain text version in emails will avoid the spam.

What is the way to get the text from ckeditor html code in java.


回答1:


This is quite simple JavaScript call:

CKEDITOR.instances.yourEditorInstance.getData() 

Returns:

<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>

However:

CKEDITOR.instances.yourEditorInstance.editable().getText() 

Returns:

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.


来源:https://stackoverflow.com/questions/15065132/how-to-extract-plain-text-from-ckeditor-generated-html-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!