Search code examples
javascriptdiffjslint

How to pass parameters to local Prettydiff.com


I've downloaded a copy of PrettyDiff to embed in my own local application, so I can compare two AJAX loaded files that are in two variables.

Unfortunately, I can't seem to make prettydiff work. Here's how I try :

var example1 = getFile('exemple1.txt');
var example2 = getFile('exemple2.txt');
var output = prettydiff("/*prettydiff.com api.lang: 8, api.mode: diff, api.diffview: inline, api.source:example1, api.diff: example2 */");
document.getElementById("output").innerHTML = output[0];

All I get is "Error: Source sample is missing.".

I've also tried to make an "api" variable that I fill with the parameters, but that doesn't work either.

The documentation doesn't give any example on how to pass the parameters (options, source and diff texts).

Anyone knows ?


Solution

  • Ok, I found out a way to get it working. I still don't know the fuss about the parameters as comments as specified in the docs, but you can create a js object and pass all your parameters :

    var api = new Object();
    api.mode = "diff";
    api.diffview = "inline";
    api.lang = 8;
    api.source = example1;
    api.diff = example2;
    var output = prettydiff(api);