将RTF转换为Javascript中的HTML [英] Convert RTF to HTML in Javascript

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

问题描述

有没有一种方法可以将RichTextFormat转换为Javascript中的HTML?

我想粘贴从剪贴板中复制的RTF内容,要获取文本/rtf内容,现在我需要在div中应用所有样式来显示它.我怎样才能做到这一点?有什么建议么?.

例如:如果我复制

ghkasjhdk

gjhgjh

^^这是RTF

我将得到与此类似的字符串

  {\ rtf1 \ ansi \ ansicpg1252 \ deff0 \ deflang1033 {\ fonttbl {\ f0 \ fnil \ fcharset0 Calibri;}}{\ * \ generator Msftedit 5.41.21.2510;} \ viewkind4 \ uc1 \ pard \ sa200 \ sl276 \ slmult1 \ lang9 \ b \ f0 \ fs40 \ par\ b0 \ fs22 ghkasjhdk \ par\ b \ fs40 gjhgjh} 

我需要分别使用< strong> 标签和&br; br>

将其转换为html

解决方案

您可能希望改编此NodeJS软件包: rtf2html .我知道这已经使用较旧的版本完成了,因为您可以在此Github存储库中看到 .

获得相应的HTML代码后,您可以使用通常的DOM方法将其添加到容器中,如果已经使用过,则可以将其添加到jQuery之类的库中.

Is there a way to convert RichTextFormat to HTML in Javascript?

Iam trying to paste the RTF content copied , from clipboard iam getting the text/rtf content, now i need to show it with all styles applied in a div. how can i achive this ?? any suggestions?.

Eg: if i copy

ghkasjhdk

gjhgjh

^^ this as RTF

i will get a string simmilar to this

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
 {\*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\sa200\sl276\slmult1\lang9\b\f0\fs40\par
 \b0\fs22 ghkasjhdk\par
 \b\fs40 gjhgjh}

i need this to be converted to html with <strong> tags and <br>'s respectively

解决方案

You may wish to adapt this NodeJS package: rtf2html. I understand this has already be done with an older version, as you can see in this Github repository.

After you get the corresponding HTML code, you can add it to your container using the usual DOM methods, or a library like jQuery if you are already using it.

这篇关于将RTF转换为Javascript中的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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