-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakecode.js
35 lines (31 loc) · 1.29 KB
/
makecode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function jntm(str) {
if(str.includes("&")) str = str.replace(/&/g,"&");
if(str.includes("<")) str = str.replace(/\</g,"<");
if(str.includes(">")) str = str.replace(/\>/g,">");
if(str.includes("'")) str = str.replace(/\'/g,"'");
if(str.includes('"')) str = str.replace(/\"/g,""");
return str;
}
function fun() {
// 语言
var cl = document.getElementById("choicelang");
var cl_s = cl.selectedIndex;
var lang = cl[cl_s].innerText;
if(lang != "— 选择语言 —") cl.classList.add("language-" + lang);
// 字体
var cf = document.getElementById("choicefont");
var cf_s = cf.selectedIndex;
var font = cf[cf_s].innerText;
if(font == "— 选择字体 —" || font == "Monospace") font = "monospace";
var cp = document.querySelector("#codeprint");
cp.style.fontFamily = font;
// 高亮
var cs = document.getElementById("choicestyle");
var cs_s = cs.selectedIndex;
var highlight = cs[cs_s].innerText;
if(highlight == "— 选择高亮预设 —") highlight = "default";
document.getElementById("hljscodestyle").href = "./highlight/styles/" + highlight + ".min.css";
// 转移
document.getElementById("codeprint").innerHTML = jntm(document.getElementById("codebox").value);
hljs.highlightBlock(document.getElementById("codeprint"));
}