Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
szse
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhaochengxiang
szse
Commits
c7125def
Commit
c7125def
authored
Jul 16, 2021
by
zhaochengxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
高亮逻辑
parent
e3eb3124
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
index.js
src/util/index.js
+4
-3
No files found.
src/util/index.js
View file @
c7125def
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment