forked from mrlan/EnglishPal
				
			修复Bug508,解决带有特殊字符|的单词在文章中的高亮问题
							parent
							
								
									e74f1ff477
								
							
						
					
					
						commit
						d58dacd71c
					
				|  | @ -29,6 +29,8 @@ function highLight() { | |||
|     const list = allWords.split(" "); | ||||
|     for (let i = 0; i < list.length; ++i) { | ||||
|         list[i] = list[i].replace(/(^\s*)|(\s*$)/g, ""); //消除单词两边的空字符
 | ||||
|         list[i] = list[i].replace('|', ""); | ||||
|         list[i] = list[i].replace('?', ""); | ||||
|         if (list[i] !== "" && "<mark>".indexOf(list[i]) === -1 && "</mark>".indexOf(list[i]) === -1) { | ||||
| 	    //将文章中所有出现该单词word的地方改为:" <mark>" + word + "<mark> "。 正则表达式RegExp()中,"\\s"代表单词前后必须要有空格,以防止只对单词中的部分字符高亮的情况出现。
 | ||||
|             articleContent = articleContent.replace(new RegExp("\\s"+list[i]+"\\s", "g"), " <mark>" + list[i] + "</mark> "); | ||||
|  |  | |||
|  | @ -39,7 +39,7 @@ def file2str(fname):#文件转字符 | |||
| 
 | ||||
| 
 | ||||
| def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。 | ||||
|     special_characters = '_©~=+[]*&$%^@.,?!:;#()"“”—‘’' # 把里面的字符都去掉 | ||||
|     special_characters = '\_©~<=>+-/[]*&$%^@.,?!:;#()"“”—‘’{}' # 把里面的字符都去掉 | ||||
|     for c in special_characters: | ||||
|         s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况 | ||||
|     s = s.replace('--', ' ') | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue