1. const textShow = (text, keyword) => {
    2. const len = keyword.length
    3. const correctText = keyword
    4. const specialStr = ["*", ".", "?", "+", "$", "^", "[", "]", "{", "}", "|", "\\", "(", ")", "/", "%"]
    5. let newText = ""
    6. if (len !== 0) {
    7. let index = 0
    8. // specialStr.map(item => {
    9. // if (correctText.includes(item)) {
    10. // correctText = correctText.replace(new RegExp(`\\${item}`, "g"), `a1s2d3${item}`)
    11. // }
    12. // })
    13. // correctText = correctText.replace(new RegExp("a1s2d3", "g"), `\\`)
    14. const matchData = new RegExp(correctText, "i").exec(text)
    15. if (matchData) {
    16. index = matchData.index
    17. newText += text.slice(0, index)
    18. // class用来定位高亮位置,样式还是以style为准
    19. newText += `<span class="heighlight" style='color: #FF3939; background-color: #FFE5E5;'>${text.slice(index, index + len)}</span>`
    20. if (text.slice(index + len).length > 0) {
    21. newText += textShow(text.slice(index + len), keyword)
    22. }
    23. } else {
    24. newText += text
    25. }
    26. } else {
    27. newText = text
    28. }
    29. newText = newText.replace(/%5f/g, "_")
    30. newText = newText.replace(/%27/g, "'")
    31. return newText
    32. }
    33. export default textShow