forked from mirror/MrDoc
优化文档高亮参数
This commit is contained in:
parent
99af3e0c45
commit
791297cf23
@ -357,24 +357,26 @@ textBecomeImg = function(text,fontsize,fontcolor){
|
||||
// 搜索词高亮
|
||||
function keyLight(id, key, bgColor){
|
||||
// console.log(id,key,decodeURI(key))
|
||||
key = decodeURI(key);
|
||||
var oDiv = document.getElementById(id),
|
||||
sText = oDiv.innerHTML,
|
||||
bgColor = bgColor || "#c00",
|
||||
sKey = "<span name='addSpan' style='color: "+bgColor+";background:ff0;'>"+key+"</span>",
|
||||
num = -1,
|
||||
rStr = new RegExp(key, "ig"),
|
||||
rHtml = new RegExp("\<.*?\>","ig"), //匹配html元素
|
||||
aHtml = sText.match(rHtml); //存放html元素的数组
|
||||
sText = sText.replace(rHtml, '{~}'); //替换html标签
|
||||
// sText = sText.replace(rStr,sKey); //替换key
|
||||
sText = sText.replace(rStr,function(text){
|
||||
return "<span name='addSpan' style='color:#333;background:#ff0;'>"+text+"</span>"
|
||||
}); //替换key
|
||||
sText = sText.replace(/{~}/g,function(){ //恢复html标签
|
||||
num++;
|
||||
return aHtml[num];
|
||||
});
|
||||
oDiv.innerHTML = sText;
|
||||
if(key != false){
|
||||
key = decodeURI(key);
|
||||
var oDiv = document.getElementById(id),
|
||||
sText = oDiv.innerHTML,
|
||||
bgColor = bgColor || "#c00",
|
||||
sKey = "<span name='addSpan' style='color: "+bgColor+";background:ff0;'>"+key+"</span>",
|
||||
num = -1,
|
||||
rStr = new RegExp(key, "ig"),
|
||||
rHtml = new RegExp("\<.*?\>","ig"), //匹配html元素
|
||||
aHtml = sText.match(rHtml); //存放html元素的数组
|
||||
sText = sText.replace(rHtml, '{~}'); //替换html标签
|
||||
// sText = sText.replace(rStr,sKey); //替换key
|
||||
sText = sText.replace(rStr,function(text){
|
||||
return "<span name='addSpan' style='color:#333;background:#ff0;'>"+text+"</span>"
|
||||
}); //替换key
|
||||
sText = sText.replace(/{~}/g,function(){ //恢复html标签
|
||||
num++;
|
||||
return aHtml[num];
|
||||
});
|
||||
oDiv.innerHTML = sText;
|
||||
}
|
||||
};
|
||||
keyLight('doc-content',getQueryVariable("highlight"))
|
Loading…
x
Reference in New Issue
Block a user