修复搜索高亮词导致代码块和链接异常的问题
This commit is contained in:
parent
87b2525be8
commit
3069272094
@ -484,16 +484,13 @@ function keyLight(id, key, bgColor){
|
||||
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元素的数组
|
||||
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>"
|
||||
return "<mark>" + text +"</mark>"
|
||||
}); //替换key
|
||||
sText = sText.replace(/{~}/g,function(){ //恢复html标签
|
||||
num++;
|
||||
@ -501,5 +498,4 @@ function keyLight(id, key, bgColor){
|
||||
});
|
||||
oDiv.innerHTML = sText;
|
||||
}
|
||||
};
|
||||
keyLight('doc-content',getQueryVariable("highlight"))
|
||||
};
|
||||
@ -242,9 +242,9 @@
|
||||
});
|
||||
|
||||
//修改a标签链接新窗口打开
|
||||
$('#content').on('click','a',function(e){
|
||||
e.target.target = '_blank';
|
||||
});
|
||||
// $('#content').on('click','a',function(e){
|
||||
// e.target.target = '_blank';
|
||||
// });
|
||||
// 显示文档下载弹出框
|
||||
$("#download_doc").click(function(r){
|
||||
var layer = layui.layer;
|
||||
|
||||
@ -335,26 +335,6 @@
|
||||
<script src="{% static 'luckysheet/dist/luckysheet.umd.js' %}?version={{mrdoc_version}}"></script>
|
||||
{% endif %}
|
||||
|
||||
<script>
|
||||
{% if project.is_watermark %}
|
||||
initWhterMark('{{project.watermark_value}}')
|
||||
{% endif %}
|
||||
|
||||
// 外部链接添加图标
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Array.prototype.filter.call(document.links, function(link) {
|
||||
return link.hostname && link.hostname !== location.hostname;
|
||||
})
|
||||
.forEach(function(link) {
|
||||
// console.log(link,$(link).children('img').length)
|
||||
if($(link).children().length == 0){
|
||||
link.classList.add('external');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<!-- 动态添加广告代码 -->
|
||||
{% if debug %}
|
||||
{% else %}
|
||||
@ -383,5 +363,27 @@
|
||||
<!-- 统计代码结束 -->
|
||||
{% block custom_script %}
|
||||
{% endblock %}
|
||||
<script>
|
||||
{% if project.is_watermark %}
|
||||
initWhterMark('{{project.watermark_value}}')
|
||||
{% endif %}
|
||||
|
||||
// 外部链接添加图标
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
Array.prototype.filter.call(document.links, function(link) {
|
||||
return link.hostname && link.hostname !== location.hostname;
|
||||
})
|
||||
.forEach(function(link) {
|
||||
link.target = '_blank';
|
||||
// console.log(link,$(link).children('img').length)
|
||||
console.log(link,$(link).children().length)
|
||||
if($(link).children().length == 0){
|
||||
link.classList.add('external');
|
||||
}
|
||||
});
|
||||
});
|
||||
// 高亮搜索词
|
||||
keyLight('doc-content',getQueryVariable("highlight"))
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user