Reputation: 1265
Is there a text editor on the web that supports input from RTF-formatted documents?
I know it is a bit of an odd request for webdev, but I need to read RTF documents from the database and edit them in a web-based text editor and store it back in RTF. Before I invest too heavily in a conversion tool, I thought I would ask if any of the many web text editors supported RTF. My research is showing that they don't.
Additionally, since this is an MVC 4.6 application, would it be a huge effort to write a two-way RTF-HTML conversion tool in C#?
Sample input that would be received by the editor:
"{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par }"
Upvotes: 9
Views: 7634
Reputation: 1668
Quill is a rich text web editor.
Using the code from the quickstart you could enable it like this
<div id="toolbar">
<button class="ql-bold">Bold</button>
<button class="ql-italic">Italic</button>
</div>
<div id="editor">
<div>Hello World!</div>
<div>Some initial <b>bold</b> text</div>
<div><br></div>
</div>
<script src="https://cdn.quilljs.com/0.20.1/quill.js"></script>
<script>
var quill = new Quill('#editor');
quill.addModule('toolbar', { container: '#toolbar' });
</script>
editor.setText("RTF document ");
by default 0 will get everything in the editor
var text = editor.getText(0);
also see this Mozilla post (archive) which defines how to implement your own rich text editor.
Upvotes: 3
Reputation: 315
I also cam to this point and solved it by converting the html to rtf with a npm package. Like i posted here How to convert HTML to RTF using JavaScript you can use the package created from npm html-to-rtf-browser and bundled to a single file like i describe here
javascript-html-to-rtf-browser
form.onsubmit = function () {
// convert html to rtf
var htmlContent = editorElement.html();
var htmlToRtfLocal = new window.htmlToRtf();
var rtfContent = htmlToRtfLocal.convertHtmlToRtf(htmlContent);
editorElement.html(rtfContent);
return true;
}
Where editorElement
is the quill content element/editor as jQuery element
and form
is the parent form ( with jQuery $(editorElement).closest('form')
).
Upvotes: 0
Reputation: 287
You could use Word to load the RTF file, then Save As HTML. Works but generates a pile of spurious MS- tags.
Or I've written a program (Visual Studio) that you can have if you want - it's a bit basic, doesn't deal with fonts, but converts most text formatting. Let me know if you're interested (I'd need to tidy it a bit - it's very old - a bit like me).
Though as I write this, I see that Wamadahama may have a better solution.
Upvotes: 1