Comments (10)
Thanks for the comments @joeypedicini92 :)
I think there are multiple things to discuss here:
- rtf.js version 1: this is only meant as a save point for pre existing users while I was making big changes in terms of typescript, modules bundling, build steps etc. We don't work on this version any more and instead focus on what is currently in master.
- requiring modules: version 1 is exclusively meant to be loaded in the browser using a script tag which is why it can't be required. The new version publishes a UMD bundle which works when loading it in the browser as a script and should support loading as a module with some caveats:
- requiring it from node will not work, since it depends on browser only libraries (jquery, jquery.svg.js), it can be used with JSDOM though (see the file test/utils.js for an example).
- the rtf.js bundle requires modules named 'WMFJS' and 'EMFJS'. Now if we published those to npm with the correct 'main' property in package.json it would work but as it stands now your module loader probably can't find the modules because they are all in the same directory and the bundle name doesn't match the module name. If you can share what you are working on or provide a minimal example of your specific setup I'd be happy to help you get it working (might be something fixable with a webpack config entry, renaming the bundles etc.). Right now I have only used the UMD bundle to get it working as a script the way it did before, I have not used it as a proper module yet.
- logging configuration: you can simply do
RTFJS.loggingEnabled = false
for 1.0 orRTFJS.loggingEnabled(false)
for the new version. It works the same way withEMFJS
andWMFJS
and should also work if you require it (var rtf = require('RTFJS.bundle.js'); rtf.loggingEnabled = false;
) - parser.version: the rtf spec requires every rtf file to declare that it is version 1 so this should not be an issue. Can you share an example file?
from rtf.js.
Thanks for the reply @zoehneto
I completely understand v1 isn't supported anymore, I was mainly voicing a suggestion that this library could be used as a node module (it was easier to do that against v1 which is why I went that route) and the changes I made to use it in that way.
We are running this on a browser, but as part of an Ember SPA, so it makes more sense to follow the pattern of importing modules in our js files than loading scripts on our index page. I think that's a more common pattern and something that should be supported by the library.
As far as providing a sample RTF I can't do that since they contain personal data. But the RTF source is version 1...but that code is expecting the parser.version to be null, so when it comes in as 1 it throws an error...can you explain how that works?
from rtf.js.
I'll have to think about getting the import to work without ugly hacks.
As far as the version check is concerned I was thinking of the wrong piece of code. The part you removed checks that no rtf version was previously specified. The reason is, that the RtfDestination has to be the first destination in the file (\rtf) and it may only be specified once. The rtf destination has the version parameter which sets the parser version. So if the RtfDestination is called and a parser version is all ready specified, you probably have multiple rtf destinations which according to the spec is invalid.
from rtf.js.
I just pushed the branch 'module-import' which should allow you to load rtf.js with require (at the moment this means you will also get wmf.js and emf.js, optionality is currently not implemented). Could you please test whether that solves your issue?
from rtf.js.
I have now also added the jQuery require so rendering documents without images should work if you require rtf.js . I still have to add support for jquery-svg.
from rtf.js.
Great thanks for the quick turnaround! I should have sometime today to test I'll let you know how it goes
from rtf.js.
Great, I have now also fixed the jquery-svg issue. I now provide that with a UMD header in the dist folder. As long as you keep everything in the dist folder together wherever you are copying it, requiring should work. I have tested it in an angular project (which uses webpack through the angular cli) and it works for me with the following code (using ES 6 imports, but require should work aswell):
import * as WMFJS from '../../rtf.js/WMFJS.bundle';
import * as EMFJS from '../../rtf.js/EMFJS.bundle';
import * as RTFJS from '../../rtf.js/RTFJS.bundle';
....
stringToBinaryArray(string) {
var buffer = new ArrayBuffer(string.length);
var bufferView = new Uint8Array(buffer);
for (var i=0; i<string.length; i++) {
bufferView[i] = string.charCodeAt(i);
}
return buffer;
}
rtfRender(){
RTFJS.loggingEnabled(false);
WMFJS.loggingEnabled(false);
EMFJS.loggingEnabled(false);
try {
var doc = new RTFJS.Document(this.stringToBinaryArray(this.rtf));
var meta = doc.metadata();
doc.render().then(function(htmlElements) {
console.log(meta, htmlElements);
}).catch(error => console.error(error))
} catch (error){
console.error(error)
}
....
from rtf.js.
I had to create an index.js file, and remove the main: 'rtf.js'
line from package.json to be able to do something like:
import { RTFJS } from 'rtf.js'
index.js:
const WMFJS = require('./dist/WMFJS.bundle');
const EMFJS = require('./dist/EMFJS.bundle');
const RTFJS = require('./dist/RTFJS.bundle');
module.exports = {WMFJS, EMFJS, RTFJS};
there's probably a better way using typescript...
from rtf.js.
I have added an index.js and corrected the main
attribute in package.json so everything should work correctly now.
It would be great if you could test it in your setup, then I can merge module-import
into master
.
from rtf.js.
I have just merged the branch and published the current state to npm, which should make working with the library a lot easier.
from rtf.js.
Related Issues (20)
- WMF image not renderer correctly HOT 2
- How to fetch email id from rtf file and render in html HOT 12
- Ordered list bullet list showing boxes in front on copying pastin from ms-outlook and ms-word HOT 3
- Some problems with displaying WMF HOT 1
- Unexpected token * HOT 4
- Converting an RTF that was copied from an outlook body where an apostrophe (') and images results in loss of the apostrophes HOT 2
- Hyperlinks are not rendered nor the control going into onHyperlink. HOT 4
- Cannot read property 'dec' of undefined HOT 3
- backslash newline not treated as equivalent to \par HOT 2
- Module won't compile HOT 2
- Error when parsing rtf file with spaces in colortbl definition HOT 2
- Adding <br /> in empty divs so new line is preserved when paste the html back MS Word
- some issues
- Issue rendering images HOT 2
- How here works images? HOT 3
- fail to render rtf file
- Some fonts are not correctly shown HOT 2
- HTML lists are lost when converted to RTF
- support for commonjs
- Unable to render Images of the original .rtf file
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rtf.js.