!199 升级markdown组件 修复markdown被转义问题

Merge pull request !199 from 高雄/N/A
This commit is contained in:
陈精华 2023-08-06 14:14:16 +00:00 committed by Gitee
commit 5ecfb39a9e
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 17 additions and 1 deletions

View File

@ -45,14 +45,30 @@
initWaterMark();
loadMarkdown();
}
function htmlEscape(str){
var s = "";
if(str.length == 0) return "";
s = str.replace(/&/g,"&");
s = str.replace(/&/g,"&");
s = s.replace(/&lt;/g,"<");
s = s.replace(/&gt;/g,">");
s = s.replace(/&nbsp;/g," ");
s = s.replace(/&#39;/g,"\'");
s = s.replace(/&quot;/g,"\"");
s = s.replace(/<script.*?>.*?<\/script>/ig, '');
s = s.replace(/<script/gi, "&lt;script ");
s = s.replace(/<iframe/gi, "&lt;iframe ");
return s;
}
/**
* 加载markdown
*/
function loadMarkdown() {
var textData = Base64.decode($("#textData").val())
textData = htmlEscape(textData);
window.textPreData = "<pre style='background-color: #FFFFFF;border:none'>" + textData + "</pre>";
window.textMarkdownData = marked(textData);
window.textMarkdownData = marked.parse(textData);
$("#markdown").html(window.textMarkdownData);
}