Primefaces textEditor:使用JavaScript无法将文本转换为HTML [英] Primefaces textEditor: converting text to HTML with JavaScript not working

查看:85
本文介绍了Primefaces textEditor:使用JavaScript无法将文本转换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请允许我说这是我在这里的第一个问题,在这个社区中我是新手.请客气,不要犹豫,纠正我,将我带到可能找到答案或学习的地方,等等.

At first let me state that this is my first question here and I am new in this community. Please be kind, do not hesitate to correct me, direct me to where I might find answers or study, etc.

我将这个问题发布为寻找解决方案的最后希望,因为我自己没有找到或提出任何解决方案(也没有得到同事的帮助).

I am posting this question as a last hope for finding a solution as I have not found or come up with any by myself (nor with a help of my colleagues).

当前在页面上使用 PrimeFaces p:editor 在我正在研究的程序中.用户使用它来输入和格式化文本,然后将其作为电子邮件发送.当前,电子邮件内容是通过JavaScript函数saveHTML转换为HTML的,因此消息代码如下所示:

Basically PrimeFaces p:editor is currently used at a page in the program I am working on. Users use it for entering and formatting text which is then send as an e-mail. Currently the e-mail content is converted by JavaScript function saveHTML to HTML, so the message code looks exactly like this:

  <div style="font-weight:normal; font-style:normal">

  <div style="font-size:11pt; font-family: Calibri,sans-serif">
    <br>In case of questions please send a message to: <a href="mailto:sample@sample.com" target="_blank">sample@sample.com</a>.
    <br><br>Yours Sincerely
  </div>

但是,从那一刻起,用户一直在报告编辑器不可预测地更改了文本字体,等等,这就是我发现它是

Since a certain moment, however, users have been reporting that the editor changes text font unpredictably, etc., and that is how I found out that it is deprecated and wanted to change it to p:textEditor.

textEditor看起来可以正常工作(进行编辑)并且看起来不错,但是在测试过程中检查了已发送的电子邮件.发现textEditor不支持JavaScript函数saveHTML,因此该函数失败,消息代码的发送方式完全如下:

The textEditor seemed to work fine (with editing) and looked nice, but during tests a sent e-mail was checked. It was found out that the textEditor somehow does not support the JavaScript function saveHTML, so the function fails and the message code is sent exactly like this:

<p><br></p><p>In case of questions please send a message to:: <a href="mailto:sample@sample.com" target="_blank">sample@sample.com</a>. </p><p><br></p><p>Yours Sincerely</p><p><br></p><p><strong>Anna Li</strong></p>

然后我发现textEditor是基于 (?) QuillJs ( textEditor文档中的信息),如果我理解此内容 GitHub问题正确,则它不支持将文本转换为HTML.

Then I found out that the textEditor is based on(?) QuillJs (info in textEditor documentation) and if I understood this GitHub issue correctly, then it does not support converting the text to HTML.

  • 是否有一种方法可以修复textEditor,以便saveHTML函数起作用?还是有另一个功能可以代替使用?还是有没有像saveHTML函数一样优雅的解决方法?怎么解决呢? (因为我的最后一个想法是制作自己的Java函数,该函数将文本转换为HTML,但是与saveHTML相比,此选项很长,很痛苦,很困难并且非常笨拙)

PrimeFaces版本7.0.7; PrimeFaces Extension版本7.0.2.

请注意,我不想使用其他组织/公司的文本编辑器.

Please note that I do not want to use a text editor from another organization/company.

推荐答案

您遇到的问题是p:textEditor会生成不可移植的HTML代码,这实际上严重限制了其总体用例. 与GitHub最相关的问题似乎是PrimeFaces TextEditor:值返回具有Quill编辑器特定CSS的HTML(即PF的Quill实现没用吗?)#4486

The problem you encounter is that p:textEditor produces non-portable HTML code which indeed badly limits its overall use cases. The most relevant GitHub issues seem to be PrimeFaces TextEditor: value returns HTML with Quill editor specific CSS (aka is PF's Quill implementation useless?) #4486

这看起来像没有可行的解决方法,除了切换到pe:ckEditor之外,这对您来说不是一个大问题,因为您已经在使用PE.

This reads like there is no viable workaround other than switching to pe:ckEditor which should not be that big of a problem in your case as you already use PE.

p:textEditor使用的Quill编辑器使用CSS类而不是嵌入式样式表生成HTML输出.您需要将这些CSS定义与生成的HTML一起提供,这在大多数情况下都不是可选的.

The Quill editor used by p:textEditor uses CSS classes instead of inline style sheets to generate the HTML output. You'd need to deliver these CSS definitions together with the generated HTML which is not an option for most use cases.

这篇关于Primefaces textEditor:使用JavaScript无法将文本转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆