From 5432e70c0e5e991a496cfe75cb9b4d19881524e1 Mon Sep 17 00:00:00 2001 From: Shikher Somal Date: Tue, 26 Aug 2014 04:01:35 +0530 Subject: [PATCH 1/7] Added new functionality to allow users to send content to be diffed as parameters to the 'prettyTextDiff' function. Currently, the user has to set th text of the HTML elements i.e. the originalContainer and the changedContainer. This required the HTML content of the two containers to be part of the page source which caused web pages to be prone to XSS attacks. This method allows the user to set the HTML content to a JS variable and pass it as a parameter to this function. Both functionalities are supported to not break the existing plugin. --- README.md | 14 +++++++++++++- jquery.pretty-text-diff.coffee | 11 ++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7272d78..e54c0a4 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This [blog post](http://arnab-deka.com/posts/2013/02/hello-jquery-prettytextdiff explains things in a bit more detail. ## Demo -[jsfiddle demo](http://jsfiddle.net/YwSVY/) +[jsfiddle demo](http://jsfiddle.net/q7hyfev8/5/) ## Download From the [jQuery plugins site](http://plugins.jquery.com/pretty-text-diff/). @@ -93,6 +93,18 @@ in the [jsfiddle demo](#demo). false see some debug output in your browser's console + + + originalContent + None + Pass the original content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. + + + + changedContent + None + Pass the changed content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. + ## Development diff --git a/jquery.pretty-text-diff.coffee b/jquery.pretty-text-diff.coffee index 800cd93..6108610 100644 --- a/jquery.pretty-text-diff.coffee +++ b/jquery.pretty-text-diff.coffee @@ -1,5 +1,5 @@ ### -@preserve jQuery.PrettyTextDiff 1.0.3 +@preserve jQuery.PrettyTextDiff 1.0.4 See https://github.com/arnab/jQuery.PrettyTextDiff/ ### @@ -19,9 +19,14 @@ $.fn.extend dmp = new diff_match_patch(); @each -> - original = $(settings.originalContainer, this).text() + if settings.originalContent and settings.changedContent + original = $('
').html(settings.originalContent).text() + changed = $('
').html(settings.changedContent).text() + else + original = $(settings.originalContainer, this).text() + changed = $(settings.changedContainer, this).text() + $.fn.prettyTextDiff.debug "Original text found: ", original, settings - changed = $(settings.changedContainer, this).text() $.fn.prettyTextDiff.debug "Changed text found: ", changed, settings diffs = dmp.diff_main(original, changed) From 76a5dc0ced0d71e2f08be91d9ce71b96bb3e1d5a Mon Sep 17 00:00:00 2001 From: Arnab Deka Date: Tue, 26 Aug 2014 07:47:10 +0530 Subject: [PATCH 2/7] Updated contributing instructions in README --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7272d78..de103cc 100644 --- a/README.md +++ b/README.md @@ -105,12 +105,13 @@ in the [jsfiddle demo](#demo). coffeescript (and compiled/minified) javascript source and the jquery-json file. + `git tag x.y.z` -+ Push! ++ Push: `git push && git push --tags` ## Contributing + Fork this repo + create a feature/bugfix branch: `git checkout -b branch_name` + [Develop](#development) + + Just change the coffeescript source. When your PR is merged, I will generate the JS flavors and update the versioning. + Push to your repo: `git push origin branch_name` + [Submit a PR](https://github.com/arnab/jQuery.PrettyTextDiff/pulls/) From 29e0e0fdd41aa0e90bc344da3ac8fa2fa0d407f2 Mon Sep 17 00:00:00 2001 From: Arnab Deka Date: Wed, 29 Apr 2015 08:59:52 -0700 Subject: [PATCH 3/7] bump version to 1.0.4. See PR #6 and Issue #9. --- jquery.pretty-text-diff.js | 17 +++++++++++------ jquery.pretty-text-diff.min.js | 6 +++--- pretty-text-diff.jquery.json | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/jquery.pretty-text-diff.js b/jquery.pretty-text-diff.js index 1e8fec7..8c4d624 100644 --- a/jquery.pretty-text-diff.js +++ b/jquery.pretty-text-diff.js @@ -1,9 +1,9 @@ -// Generated by CoffeeScript 1.6.3 +// Generated by CoffeeScript 1.9.2 + /* -@preserve jQuery.PrettyTextDiff 1.0.3 +@preserve jQuery.PrettyTextDiff 1.0.4 See https://github.com/arnab/jQuery.PrettyTextDiff/ -*/ - + */ (function() { var $; @@ -25,9 +25,14 @@ See https://github.com/arnab/jQuery.PrettyTextDiff/ dmp = new diff_match_patch(); return this.each(function() { var changed, diff_as_html, diffs, original; - original = $(settings.originalContainer, this).text(); + if (settings.originalContent && settings.changedContent) { + original = $('
').html(settings.originalContent).text(); + changed = $('
').html(settings.changedContent).text(); + } else { + original = $(settings.originalContainer, this).text(); + changed = $(settings.changedContainer, this).text(); + } $.fn.prettyTextDiff.debug("Original text found: ", original, settings); - changed = $(settings.changedContainer, this).text(); $.fn.prettyTextDiff.debug("Changed text found: ", changed, settings); diffs = dmp.diff_main(original, changed); if (settings.cleanup) { diff --git a/jquery.pretty-text-diff.min.js b/jquery.pretty-text-diff.min.js index 25e1691..9a09975 100644 --- a/jquery.pretty-text-diff.min.js +++ b/jquery.pretty-text-diff.min.js @@ -1,5 +1,5 @@ /* -@preserve jQuery.PrettyTextDiff 1.0.3 +@preserve jQuery.PrettyTextDiff 1.0.4 See https://github.com/arnab/jQuery.PrettyTextDiff/ -*/ -(function(){var $;$=jQuery;$.fn.extend({prettyTextDiff:function(options){var dmp,settings;settings={originalContainer:".original",changedContainer:".changed",diffContainer:".diff",cleanup:true,debug:false};settings=$.extend(settings,options);$.fn.prettyTextDiff.debug("Options: ",settings,settings);dmp=new diff_match_patch;return this.each(function(){var changed,diff_as_html,diffs,original;original=$(settings.originalContainer,this).text();$.fn.prettyTextDiff.debug("Original text found: ",original,settings);changed=$(settings.changedContainer,this).text();$.fn.prettyTextDiff.debug("Changed text found: ",changed,settings);diffs=dmp.diff_main(original,changed);if(settings.cleanup){dmp.diff_cleanupSemantic(diffs)}$.fn.prettyTextDiff.debug("Diffs: ",diffs,settings);diff_as_html=$.map(diffs,function(diff){return $.fn.prettyTextDiff.createHTML(diff)});$(settings.diffContainer,this).html(diff_as_html.join(""));return this})}});$.fn.prettyTextDiff.debug=function(message,object,settings){if(settings.debug){return console.log(message,object)}};$.fn.prettyTextDiff.createHTML=function(diff){var data,html,operation,pattern_amp,pattern_gt,pattern_lt,pattern_para,text;html=[];pattern_amp=/&/g;pattern_lt=//g;pattern_para=/\n/g;operation=diff[0],data=diff[1];text=data.replace(pattern_amp,"&").replace(pattern_lt,"<").replace(pattern_gt,">").replace(pattern_para,"
");switch(operation){case DIFF_INSERT:return""+text+"";case DIFF_DELETE:return""+text+"";case DIFF_EQUAL:return""+text+""}}}).call(this); \ No newline at end of file + */ +(function(){var $;$=jQuery;$.fn.extend({prettyTextDiff:function(options){var dmp,settings;settings={originalContainer:".original",changedContainer:".changed",diffContainer:".diff",cleanup:true,debug:false};settings=$.extend(settings,options);$.fn.prettyTextDiff.debug("Options: ",settings,settings);dmp=new diff_match_patch;return this.each(function(){var changed,diff_as_html,diffs,original;if(settings.originalContent&&settings.changedContent){original=$("
").html(settings.originalContent).text();changed=$("
").html(settings.changedContent).text()}else{original=$(settings.originalContainer,this).text();changed=$(settings.changedContainer,this).text()}$.fn.prettyTextDiff.debug("Original text found: ",original,settings);$.fn.prettyTextDiff.debug("Changed text found: ",changed,settings);diffs=dmp.diff_main(original,changed);if(settings.cleanup){dmp.diff_cleanupSemantic(diffs)}$.fn.prettyTextDiff.debug("Diffs: ",diffs,settings);diff_as_html=$.map(diffs,function(diff){return $.fn.prettyTextDiff.createHTML(diff)});$(settings.diffContainer,this).html(diff_as_html.join(""));return this})}});$.fn.prettyTextDiff.debug=function(message,object,settings){if(settings.debug){return console.log(message,object)}};$.fn.prettyTextDiff.createHTML=function(diff){var data,html,operation,pattern_amp,pattern_gt,pattern_lt,pattern_para,text;html=[];pattern_amp=/&/g;pattern_lt=//g;pattern_para=/\n/g;operation=diff[0],data=diff[1];text=data.replace(pattern_amp,"&").replace(pattern_lt,"<").replace(pattern_gt,">").replace(pattern_para,"
");switch(operation){case DIFF_INSERT:return""+text+"";case DIFF_DELETE:return""+text+"";case DIFF_EQUAL:return""+text+""}}}).call(this); \ No newline at end of file diff --git a/pretty-text-diff.jquery.json b/pretty-text-diff.jquery.json index b7a5913..1214ed1 100644 --- a/pretty-text-diff.jquery.json +++ b/pretty-text-diff.jquery.json @@ -1,6 +1,6 @@ { "name": "pretty-text-diff", - "version": "1.0.3", + "version": "1.0.4", "title": "jQuery.PrettyTextDiff", "description": "A jQuery plugin to show diff between text. Uses Google's diff_match_patch library underneath.", "keywords": [ From 56136c76bc67e061edd0926e5e7eb26a899e0a05 Mon Sep 17 00:00:00 2001 From: Arnab Deka Date: Wed, 29 Apr 2015 09:26:21 -0700 Subject: [PATCH 4/7] Added package.json to add to nps.js (as suggested by jQuery Plugins) --- package.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..160436a --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "jquery-prettytextdiff", + "version": "1.0.4", + "description": "A jQuery plugin to diff text painlessly. Uses Google's diff_match_patch library underneath.", + "main": "jquery.pretty-text-diff.js", + "repository": { + "type": "git", + "url": "git+https://github.com/arnab/jQuery.PrettyTextDiff.git" + }, + "keywords": [ + "jquery-plugins", + "ecosystem:jquery", + "text", + "diff", + "compare", + "visualize" + ], + "author": "Arnab Deka", + "license": "MIT", + "bugs": { + "url": "https://github.com/arnab/jQuery.PrettyTextDiff/issues" + }, + "homepage": "https://github.com/arnab/jQuery.PrettyTextDiff#readme", + "dependencies" : { + "jquery": ">=1.4" + } +} From 02505e980ccdff88daf149ae2e4e19100b9650d7 Mon Sep 17 00:00:00 2001 From: Arnab Deka Date: Wed, 29 Apr 2015 09:51:34 -0700 Subject: [PATCH 5/7] move from jquery plugins site to npm.js jQuery Plugins site is read-only now, so there's no way to update the description there. --- README.md | 10 +++++----- pretty-text-diff.jquery.json | 33 --------------------------------- 2 files changed, 5 insertions(+), 38 deletions(-) delete mode 100644 pretty-text-diff.jquery.json diff --git a/README.md b/README.md index b89e395..b5ffb47 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ explains things in a bit more detail. [jsfiddle demo](http://jsfiddle.net/q7hyfev8/5/) ## Download -From the [jQuery plugins site](http://plugins.jquery.com/pretty-text-diff/). +From [npm.js](https://www.npmjs.com/package/jquery-prettytextdiff/). ## Usage #### First, include the libraries @@ -95,13 +95,13 @@ in the [jsfiddle demo](#demo). - originalContent + originalContent(since v1.0.4) None Pass the original content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. - changedContent + changedContent(since v1.0.4) None Pass the changed content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. @@ -115,9 +115,9 @@ in the [jsfiddle demo](#demo). + `cake build` to produce the output JS (minified) + Increment the version in the coffeescript (and compiled/minified) javascript source and the -jquery-json file. +`package.json` file. + `git tag x.y.z` -+ Push: `git push && git push --tags` ++ Push: `git push && git push --tags && npm publish` ## Contributing + Fork this repo diff --git a/pretty-text-diff.jquery.json b/pretty-text-diff.jquery.json deleted file mode 100644 index 1214ed1..0000000 --- a/pretty-text-diff.jquery.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "pretty-text-diff", - "version": "1.0.4", - "title": "jQuery.PrettyTextDiff", - "description": "A jQuery plugin to show diff between text. Uses Google's diff_match_patch library underneath.", - "keywords": [ - "jquery", - "plugin", - "diff", - "text", - "html", - "compare", - "visualize" - ], - "homepage": "https://github.com/arnab/jQuery.PrettyTextDiff", - "author": { - "name": "Arnab Deka", - "url": "http://arnab-deka.com" - }, - "docs": "https://github.com/arnab/jQuery.PrettyTextDiff/blob/master/README.md#usage", - "demo": "http://jsfiddle.net/arnab/YwSVY/", - "bugs": "https://github.com/arnab/jQuery.PrettyTextDiff/issues", - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/arnab/jQuery.PrettyTextDiff/blob/master/LICENSE" - } - ], - "dependencies": { - "jquery": ">=1.4", - "diff_match_patch": "*" - } -} From 4b0f134e7209659d2fcc84af3118f554e926d801 Mon Sep 17 00:00:00 2001 From: Arnab Deka Date: Wed, 29 Apr 2015 09:53:30 -0700 Subject: [PATCH 6/7] readme tweaks for version bump. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5ffb47..d65a3a1 100644 --- a/README.md +++ b/README.md @@ -95,13 +95,13 @@ in the [jsfiddle demo](#demo). - originalContent(since v1.0.4) + originalContentv1.0.4+ None Pass the original content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. - changedContent(since v1.0.4) + changedContentv1.0.4+ None Pass the changed content as a parameter in your JS file, instead of creating an element in your HTML code to extract this content. From 797b1225c90934cdd66ad6642d07d166ea4dd8f1 Mon Sep 17 00:00:00 2001 From: David Prothero Date: Wed, 15 Jun 2016 08:50:11 -0700 Subject: [PATCH 7/7] Fixed demo - link to diff-match-batch was broken --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d65a3a1..77cf84a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This [blog post](http://arnab-deka.com/posts/2013/02/hello-jquery-prettytextdiff explains things in a bit more detail. ## Demo -[jsfiddle demo](http://jsfiddle.net/q7hyfev8/5/) +[jsfiddle demo](http://jsfiddle.net/q7hyfev8/504/) ## Download From [npm.js](https://www.npmjs.com/package/jquery-prettytextdiff/).