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:
parent
4919b89ab8
commit
8015fd7600
5 changed files with 26 additions and 5 deletions
|
@ -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';
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue