Commit c7125def by zhaochengxiang

高亮逻辑

parent e3eb3124
...@@ -183,11 +183,12 @@ function highlightSearchContent(content) { ...@@ -183,11 +183,12 @@ function highlightSearchContent(content) {
) )
} }
export function searchContentAddDecorate(content, terms) { export function searchContentAddDecorate(content, terms, matchCount=0) {
if (!content || content==='') return ''; if (!content || content==='') return '';
if ((terms||[]).length===0 || typeof(content)!=='string') return content; if ((terms||[]).length===0 || typeof(content)!=='string') return content;
if (matchCount >= 10) return content;
let start = -1; let start = -1;
let useTerm = ''; let useTerm = '';
terms.forEach(term => { terms.forEach(term => {
...@@ -209,7 +210,7 @@ export function searchContentAddDecorate(content, terms) { ...@@ -209,7 +210,7 @@ export function searchContentAddDecorate(content, terms) {
const middleStr = content.substr(start, useTerm.length); const middleStr = content.substr(start, useTerm.length);
const afterStr = content.substr(start + useTerm.length); const afterStr = content.substr(start + useTerm.length);
return `${beforeStr}<em>${middleStr}</em>${searchContentAddDecorate(afterStr, terms)}`; return `${beforeStr}<em>${middleStr}</em>${searchContentAddDecorate(afterStr, terms, ++matchCount)}`;
} }
return content; return content;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment