Skip to content

Commit

Permalink
feat(wickedest#132): added option to ignore accented characters (wick…
Browse files Browse the repository at this point in the history
…edest#136)

* feat(wickedest#132): added  option to ignore accented characters

* fixed lf

Co-authored-by: Jamie Peabody <[email protected]>
  • Loading branch information
wickedest and Jamie Peabody authored Oct 15, 2020
1 parent 577a324 commit 5a0cd15
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changes

## 4.2.0:
* minor: added new option `ignoreaccents` to ignore accented characters.

## 4.1.2:
* patch: fixes issue #134 where the readme had broken links.

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ $(document).ready(function () {
|<a name="fadein"></a>fadein|string|`fast`|A jQuery [fadein](http://api.jquery.com/fadein) value to enable the editor to fade in. Set to empty string to disable.|
|<a name="fgcolor"></a>fgcolor|string\|number\|object|`{a:'#4ba3fa', c:'#a3a3a3', d:'#ff7f7f', ca:'#4b73ff', cc:'#434343', cd:'#ff4f4f'}`|The foreground color that mergely marks changes with on the canvas. The value **a** is additions, **c** changes, **d** deletions, and the prefix *c* indicates current/active change (e.g. **cd** current delection).|
|<a name="ignorews"></a>ignorews|boolean|`false`|Ignores white-space.|
|<a name="ignorecase"></a>ignorecase|boolean|`false`|Ignores case when differientiating.
|<a name="ignorecase"></a>ignorecase|boolean|`false`|Ignores case when differientiating.|
|<a name="ignoreaccents"></a>ignorews|boolean|`false`|Ignores accented characters.|
|<a name="lcs"></a>lcs|boolean|`true`|Enables/disables LCS computation for paragraphs (word-by-word changes). Disabling can give a performance gain for large documents.|
|<a name="license"></a>license|string|`lgpl`|The choice of license to use with Mergely. Valid values are: `lgpl`, `gpl`, `mpl` or `lgpl-separate-notice`, `gpl-separate-notice`, `mpl-separate-notice` (the license requirements are met in a separate notice file).|
|<a name="line_numbers"></a>line_numbers|boolean|`true`|Enables/disables line numbers. Enabling line numbers will toggle the visibility of the line number margins.|
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mergely",
"version": "4.1.2",
"version": "4.2.0",
"description": "A javascript UI for diff/merge",
"directories": {
"doc": "doc",
Expand Down
20 changes: 14 additions & 6 deletions src/mergely.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ Mgly.sizeOf = function(obj) {
return size;
};

Mgly.LCS = function(x, y) {
Mgly.LCS = function(x, y, options) {
this.x = (x && x.replace(/[ ]{1}/g, '\n')) || '';
this.y = (y && y.replace(/[ ]{1}/g, '\n')) || '';
this.options = options;
};

jQuery.extend(Mgly.LCS.prototype, {
clear: function() { this.ready = 0; },
diff: function(added, removed) {
var d = new Mgly.diff(this.x, this.y, {ignorews: false});
var d = new Mgly.diff(this.x, this.y, {
ignorews: false,
ignoreaccents: !!this.options.ignoreaccents
});
var changes = Mgly.DiffParser(d.normal_form());
var li = 0, lj = 0;
for (var i = 0; i < changes.length; ++i) {
Expand Down Expand Up @@ -86,7 +90,6 @@ Mgly.CodeifyText = function(settings) {
this._max_code = 0;
this._diff_codes = {};
this.ctxs = {};
this.options = {ignorews: false};
jQuery.extend(this, settings);
this.lhs = settings.lhs.split('\n');
this.rhs = settings.rhs.split('\n');
Expand Down Expand Up @@ -119,6 +122,9 @@ jQuery.extend(Mgly.CodeifyText.prototype, {
if (this.options.ignorecase) {
line = line.toLowerCase();
}
if (this.options.ignoreaccents) {
line = line.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
var aCode = this._diff_codes[line];
if (aCode != undefined) {
ctx.codes[i] = aCode;
Expand All @@ -133,7 +139,7 @@ jQuery.extend(Mgly.CodeifyText.prototype, {
});

Mgly.diff = function(lhs, rhs, options) {
var opts = jQuery.extend({ignorews: false}, options);
var opts = jQuery.extend({ignorews: false, ignoreaccents: false}, options);
this.codeify = new Mgly.CodeifyText({
lhs: lhs,
rhs: rhs,
Expand Down Expand Up @@ -385,6 +391,7 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
viewport: false,
ignorews: false,
ignorecase: false,
ignoreaccents: false,
fadein: 'fast',
resize_timeout: 500,
change_timeout: 150,
Expand Down Expand Up @@ -438,7 +445,6 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
_debug: '', //scroll,draw,calc,diff,markup,change,init
resized: function() { }
}, options);

// save this element for faster queries
this.element = jQuery(el);

Expand Down Expand Up @@ -1391,7 +1397,9 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
}
lhs_line = led.getLine( j );
rhs_line = red.getLine( k );
var lcs = new Mgly.LCS(lhs_line, rhs_line);
var lcs = new Mgly.LCS(lhs_line, rhs_line, {
ignoreaccents: !!this.settings.ignoreaccents
});
lcs.diff(
function added (from, to) {
if (self._is_change_in_view('rhs', rhsvp, change)) {
Expand Down

0 comments on commit 5a0cd15

Please sign in to comment.