0
0
Fork 0

Improve RTL detection (#3682)

- Use plaintext
- Strip out URLs
- Strip out mentions
- Strip out hashtags
- Strip out whitespace from "overall" count
- Consistent between JS and Ruby
This commit is contained in:
Eugen Rochko 2017-06-10 15:06:50 +02:00 committed by GitHub
parent 4919b89ab8
commit 8015fd7600
5 changed files with 26 additions and 5 deletions

View file

@ -100,7 +100,7 @@ class StatusContent extends React.PureComponent {
const spoilerContent = { __html: emojify(escapeTextContentForBrowser(status.get('spoiler_text', ''))) };
const directionStyle = { direction: 'ltr' };
if (isRtl(status.get('content'))) {
if (isRtl(status.get('search_index'))) {
directionStyle.direction = 'rtl';
}

View file

@ -17,11 +17,15 @@ export function isRtl(text) {
return false;
}
text = text.replace(/(?:^|[^\/\w])@([a-z0-9_]+(@[a-z0-9\.\-]+)?)/ig, '');
text = text.replace(/(?:^|[^\/\w])#([\S]+)/ig, '');
text = text.replace(/\s+/g, '');
const matches = text.match(rtlChars);
if (!matches) {
return false;
}
return matches.length / text.trim().length > 0.3;
return matches.length / text.length > 0.3;
};