我有一段文本,其中包含\n
符号,我有一个短语数组想要用<mark>
标签将其在文本中的片段高亮显示。问题是,如果文本中存在\n
符号,我就无法找到这些短语。
我尝试从文本中替换\n
符号,但我需要在高亮显示后还原它们。
let text = 'Looking For An Enterprise Test Authoring Platform?\n
Learn More About Gauge\n
Watch our video to learn if Gauge can help you.'
let phrases = ["Authoring Platform? Learn More", "Gauge Watch our video", "can help you"]
const highlight = (phrase) => text.replace(phrase, `<mark style="background: #4CAF50">${phrase}</mark>`)
phrases.map(phrase=> text = highlight(phrase))
只有最后一句话与文本匹配。我正在寻找一种方法来忽略 \n
并匹配所有这些短语。或者也许有其他解决方法。感谢任何帮助!