Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Thai search keywords not properly hi-lighted in the search results. #8347

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/utils/markdown/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
const result = convertSearchTermToRegex('你好');
expect(result.pattern).toEqual(/()(你好)/gi);
});

Check failure on line 187 in app/utils/markdown/index.test.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
it('should create regex for Thai characters', () => {
const result = convertSearchTermToRegex('สวัสดี');
expect(result.pattern).toEqual(/()(สวัสดี)/gi);
});

it('should create regex for wildcard at the end', () => {
const result = convertSearchTermToRegex('hello*');
Expand Down
6 changes: 3 additions & 3 deletions app/utils/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ type LanguageObject = {
};
}

// pattern to detect the existence of a Chinese, Japanese, or Korean character in a string
// pattern to detect the existence of a Chinese, Japanese, Korean, or Thai character in a string
// http://stackoverflow.com/questions/15033196/using-javascript-to-check-whether-a-string-contains-japanese-characters-includi
const cjkPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf\uac00-\ud7a3]/;
const cjkPattern = /[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf\uac00-\ud7a3\u0e00-\u0e7f]/;
callmeott marked this conversation as resolved.
Show resolved Hide resolved

const puncStart = /^[^\p{L}\d\s#]+/u;
const puncEnd = /[^\p{L}\d\s]+$/u;
Expand Down Expand Up @@ -347,7 +347,7 @@ export function convertSearchTermToRegex(term: string): SearchPattern {
let pattern;

if (cjkPattern.test(term)) {
// term contains Chinese, Japanese, or Korean characters so don't mark word boundaries
// term contains Chinese, Japanese, Korean or Thai characters so don't mark word boundaries
pattern = '()(' + escapeRegex(term.replace(/\*/g, '')) + ')';
} else if ((/[^\s][*]$/).test(term)) {
pattern = '\\b()(' + escapeRegex(term.substring(0, term.length - 1)) + ')';
Expand Down
Loading