项目作者: amweiss

项目描述 :
An AngularJS wrapper for google-diff-match-patch
高级语言: JavaScript
项目地址: git://github.com/amweiss/angular-diff-match-patch.git
创建时间: 2014-08-29T18:49:34Z
项目社区:https://github.com/amweiss/angular-diff-match-patch

开源协议:MIT License

下载


angular-diff-match-patch

npm
CircleCI Codecov

This library is simply a wrapper around google-diff-match-patch.

Simple

(Shown here with some custom styles)

Angular 2 Port

Should you wish to use this in an Angular 2+ project, take a look at this port: elliotforbes/ng-diff-match-patch

Setup

Install from NPM

npm install amweiss/angular-diff-match-patch

Install from Bower

bower install angular-diff-match-patch

Usage with webpack

  1. config.plugins = [
  2. new webpack.ProvidePlugin({
  3. diff_match_patch: 'diff-match-patch'
  4. }),
  5. ];

Usage

See the included demo for reference or view a sample on Codepen.

  1. <pre line-diff left-obj="left" right-obj="right"></pre>

Where left and right are defined on your scope. The options attribute can be used as well, but it’s optional.

  1. $scope.options = {
  2. editCost: 4,
  3. attrs: {
  4. insert: {
  5. 'data-attr': 'insert',
  6. 'class': 'insertion'
  7. },
  8. delete: {
  9. 'data-attr': 'delete'
  10. },
  11. equal: {
  12. 'data-attr': 'equal'
  13. }
  14. }
  15. };

editCost is specific to processingDiff and controls the tolerence for hunk separation. attrs can contain any/all/none of the following: insert, delete, and equal where the properties in those objects represent attributes that get added to the tags.

Another option is to skip angular processing the diff, it’s useful when you want to show a diff of a code pre-compiled by angular. The attribute you need to add is called: skipAngularCompilingOnDiff. If set to true, would skip compiling, otherwise it would compile the diff.

Add some style

  1. .match{
  2. color: gray;
  3. }
  4. .ins{
  5. color: black;
  6. background: #bbffbb;
  7. }
  8. .del{
  9. color: black;
  10. background: #ffbbbb;
  11. }

Development

Development work requires npm from Node.js

Begin with:

npm install

Then you can use:

npm start To host the directory so you can see the demo

npm test To run the Jasmine tests once

npm test-watch To run the Jasmine tests with change detection