Ruby How to convert RTF file to HTML?

bruceyue · 2013年12月24日 · 最后由 bruceyue 回复于 2014年01月03日 · 3627 次阅读

rtf_str = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Tahoma;}} {*\generator Msftedit 5.41.21.2510;}\viewkind4\uc1\pard\f0\fs17 Received Billing Agreement 12 04 12 KC \par Number of properties - 40\par \par \ul\b VERIFY WITH JOHN IF THE PROPERTY HE IS CALLING IN IS A FANNIE MAE OR NOT\par \par \par 1) On Vacant Fannie Mae properties ABC Company to fannie mae key- \par 2) On occupied properties ABC Company to random key \par 3) NON-FANNIE MAE PROPERTIES - KEY TO 60-70 and L-S\ulnone\b0\par \ul\b 4)\ulnone\b0 . Leave 2 keys at property\par 5). Do not test smoke alarms/only test on a per request basic\par 6) Always remove double cylinder deadbolts and replace with single cylinder deadbolts\par 7). Locking Knobs- other- Check if locking knobs need to be ABC Companyed and who has access (?)\par 8). Do not install security bar\par 9). Only ABC Company overhead garage doors when specifically requested \par 10). JOBS NOT TO EXCEEED $150 or Call if it goes over\par 11) Per John DO NOT LEAVE ANY KEYS FOR FANNIE MAE PROPERTIES EVER< UNLESS INSTRUCTED \par \par \par \ul\b OFFICE:\par \par \ulnone\b0 1. Leave 2 keys at property\par 2. Email invoice IMMEDIATELY ON COMPLETION OF JOB!!!\par \par \par \ul\b AUTHORIZED TO USE ACCOUNT:\par \par \pard\ulnone\b0 1. John Nold 425-777-0639\fs17 }"

用 ruby 怎么转化为 html 呢?

求各位大神帮忙。

另祝各位平安夜快乐,圣诞快乐。

2 楼 已删除

我一看有回复了,还以为有答案了呢。哎。

果断用万能的 pandoc

多交代一些你具体的需要。这样大家才可以帮你想办法。你的 RTF 文件从哪来的?为什么要转化而不是直接生成 html 格式?还有就是你转化的频率有多高,是自己用还是公司用。如果是自己用的话可以考虑用一些在线的 web 服务来做

需求是这样的: 一个数据库表里的一个字段存放 rtf 内容。另外一个字段为 html. html 来源为这个 rtf. 比如
html_field = rtf_field.convert_to_html 只需要实现这个 Contact.update(rtf_field, html_field)

pandoc --help
pandoc [OPTIONS] [FILES]

Input formats: docbook, haddock, html, json, latex, markdown, markdown_github, markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, native, opml, rst, textile Output formats: asciidoc, beamer, context, docbook, docx, dzslides, epub, epub3, fb2, html, html5, json, latex, man, markdown, markdown_github, markdown_mmd, markdown_phpextra, markdown_strict, mediawiki, native, odt, opendocument, opml, org, pdf*, plain, revealjs, rst, rtf, s5, slideous, slidy, texinfo, textile [*for pdf output, use latex or beamer and -o FILENAME.pdf]

pandoc 不支持 rtf to html.

使用 ERB 模板来做吧

具体怎么做呢?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号