Coder Social home page Coder Social logo

proposed changes about rtf.js HOT 10 CLOSED

joeypedicini92 avatar joeypedicini92 commented on August 28, 2024
proposed changes

from rtf.js.

Comments (10)

zoehneto avatar zoehneto commented on August 28, 2024

Thanks for the comments @joeypedicini92 :)

I think there are multiple things to discuss here:

  1. 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.
  2. 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.
  3. logging configuration: you can simply do RTFJS.loggingEnabled = false for 1.0 or RTFJS.loggingEnabled(false) for the new version. It works the same way with EMFJS and WMFJS and should also work if you require it (var rtf = require('RTFJS.bundle.js'); rtf.loggingEnabled = false;)
  4. 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.

joeypedicini92 avatar joeypedicini92 commented on August 28, 2024

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.

zoehneto avatar zoehneto commented on August 28, 2024

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.

zoehneto avatar zoehneto commented on August 28, 2024

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.

zoehneto avatar zoehneto commented on August 28, 2024

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.

joeypedicini92 avatar joeypedicini92 commented on August 28, 2024

Great thanks for the quick turnaround! I should have sometime today to test I'll let you know how it goes

from rtf.js.

zoehneto avatar zoehneto commented on August 28, 2024

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.

joeypedicini92 avatar joeypedicini92 commented on August 28, 2024

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.

zoehneto avatar zoehneto commented on August 28, 2024

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.

zoehneto avatar zoehneto commented on August 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.