【问题标题】:How to extract plain text from ckeditor generated html in JAVA如何在 JAVA 中从 ckeditor 生成的 html 中提取纯文本
【发布时间】:2013-02-10 11:43:01
【问题描述】:

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

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

【问题讨论】:

    标签: email ckeditor jakarta-mail spam plaintext


    【解决方案1】:

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

    CKEDITOR.instances.yourEditorInstance.getData() 
    

    返回:

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

    但是:

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

    返回:

    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.
    

    【讨论】:

    • getText() 在一行中显示所有内容。下一行不显示第二个“阿波罗 11 号”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 2016-12-20
    • 2010-11-26
    相关资源
    最近更新 更多