diff --git a/src/LineBreak.ts b/src/LineBreak.ts index f92ff24..faa1765 100644 --- a/src/LineBreak.ts +++ b/src/LineBreak.ts @@ -269,6 +269,11 @@ const _lineBreakAtIndex = ( return BREAK_NOT_ALLOWED; } + // see LB9 in codePointsToCharacterClasses + if (indicies[index] === indicies[index -1]) { + return BREAK_NOT_ALLOWED; + } + let currentIndex = index - 1; if (Array.isArray(forbiddenBreaks) && forbiddenBreaks[currentIndex] === true) { return BREAK_NOT_ALLOWED; @@ -311,11 +316,6 @@ const _lineBreakAtIndex = ( return BREAK_NOT_ALLOWED; } - // zwj emojis - if ((current === EB || current === EM) && UnicodeTrie.get(codePoints[afterIndex]) === ZWJ) { - return BREAK_NOT_ALLOWED; - } - // LB11 Do not break before or after Word joiner and related characters. if (current === WJ || next === WJ) { return BREAK_NOT_ALLOWED; diff --git a/tests/LineBreaker.ts b/tests/LineBreaker.ts index 7f0ec21..47e2319 100644 --- a/tests/LineBreaker.ts +++ b/tests/LineBreaker.ts @@ -18,7 +18,7 @@ describe('LineBreaker', () => { }); it('should handle zwj emojis', () => { - const breaker = LineBreaker('Text with zwj emojis ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ and modifiers ๐Ÿคท๐Ÿพโ€โ™‚๏ธ.'); + const breaker = LineBreaker('Text with zwj emojis ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ and ๐Ÿณ๏ธโ€๐ŸŒˆ and modifiers ๐Ÿคท๐Ÿพโ€โ™‚๏ธ.'); const words = []; let bk; @@ -29,7 +29,7 @@ describe('LineBreaker', () => { } } - deepEqual(words, ['Text ', 'with ', 'zwj ', 'emojis ', '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ ', 'and ', 'modifiers ', '๐Ÿคท๐Ÿพโ€โ™‚๏ธ.']); + deepEqual(words, ['Text ', 'with ', 'zwj ', 'emojis ', '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ ', 'and ', '๐Ÿณ๏ธโ€๐ŸŒˆ ', 'and ', 'modifiers ', '๐Ÿคท๐Ÿพโ€โ™‚๏ธ.']); }); it('Works with options', () => {