-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/development'
- Loading branch information
Showing
13 changed files
with
124 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
app/react/RelationTypes/actions/specs/relationTypesActions.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable max-depth */ | ||
|
||
// Adapted from http://blog.stevenlevithan.com/archives/javascript-match-nested | ||
export default (function () { | ||
const formatParts = /^([\S\s]+?)\.\.\.([\S\s]+)/; | ||
const metaChar = /[-[\]{}()*+?.\\^$|,]/g; | ||
const escape = function (str) { | ||
return str.replace(metaChar, '\\$&'); | ||
}; | ||
|
||
return function (str, format, escapeCode = '') { | ||
const p = formatParts.exec(format); | ||
if (!p) { | ||
throw new Error('format must include start and end tokens separated by "..."'); | ||
} | ||
|
||
if (p[1] === p[2]) { | ||
throw new Error('start and end format tokens cannot be identical'); | ||
} | ||
|
||
const opener = p[1]; | ||
const closer = p[2]; | ||
const iterator = new RegExp(format.length === 5 ? '[' + escape(opener + closer) + ']' : escape(opener) + '|' + escape(closer), 'g'); | ||
const results = []; | ||
let openTokens; | ||
let matchStartIndex; | ||
let match; | ||
|
||
do { | ||
openTokens = 0; | ||
while ((match = iterator.exec(str)) !== null) { | ||
if (match[0] === opener) { | ||
if (!openTokens) { | ||
matchStartIndex = iterator.lastIndex; | ||
} | ||
openTokens += 1; | ||
} else if (openTokens) { | ||
openTokens -= 1; | ||
if (!openTokens) { | ||
if (str.slice(matchStartIndex - escapeCode.length - opener.length, matchStartIndex - opener.length) === escapeCode) { | ||
results.push(str.slice(matchStartIndex, match.index)); | ||
} | ||
} | ||
} | ||
} | ||
} while (openTokens && (iterator.lastIndex = matchStartIndex)); | ||
|
||
return results; | ||
}; | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import markdownEscapedValues from '../markdownEscapedValues'; | ||
|
||
describe('markdownEscapedValues', () => { | ||
it('should return an emtpy array when no match found', () => { | ||
expect(markdownEscapedValues(null, '(...)')).toEqual([]); | ||
expect(markdownEscapedValues('', '(...)')).toEqual([]); | ||
expect(markdownEscapedValues('Unmatched text', '(...)')).toEqual([]); | ||
}); | ||
|
||
it('should extract found matches, even in nested configurations', () => { | ||
expect(markdownEscapedValues('This is a (match)', '(...)')).toEqual(['match']); | ||
|
||
expect(markdownEscapedValues('This should also (match(as(nested(parenthesis),with more data)))', '(...)')) | ||
.toEqual(['match(as(nested(parenthesis),with more data))']); | ||
}); | ||
|
||
it('should extract matches with custom escape code only, and avoid other type of escapes that may use similar patters', () => { | ||
expect(markdownEscapedValues('This {should}(not match), this is a {a}(match), this other [a](should not)', '(...)', '{a}')) | ||
.toEqual(['match']); | ||
|
||
expect(markdownEscapedValues('This {should}(not match), this is a {a}(should(match)), this other {a}(too)', '(...)', '{a}')) | ||
.toEqual(['should(match)', 'too']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters