-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcodify.js
71 lines (67 loc) · 2.38 KB
/
codify.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function () {
const ce_nodes = document.querySelectorAll('code.cpp');
function process(source) {
const display = [];
const compile = []
display.push("<a href=moo>moo</a>");
for (const line of source.split("\n")) {
display.push(line); // TODO escape?
}
return {
display: display.join("\n"),
compile: compile.join("\n")
};
}
for (let i = 0, len = ce_nodes.length; i < len; i++) {
const element = ce_nodes[i];
// let compiler = "g82";
// let options = "-O2 -march=haswell";
const source = unescape(element.textContent);
const {display, compile} = process(source);
element.innerHTML = display;
// let lines = source.split('\n');
// source = "";
// let displaySource = "";
// const configMatcher = /^\s*\/\/\/\s*([^:]+):(.*)$/;
// const hideMatcher = /^\s*\/\/\/\s*((un)?hide)$/;
// let skipDisplay = false;
// let hide = false;
// for (let idx = 0; idx < lines.length; ++idx) {
// let line = lines[idx];
// let match = line.match(configMatcher);
// if (match) {
// compiler = match[1];
// options = match[2];
// } else {
// match = line.match(hideMatcher);
// if (match) {
// hide = match[1] === "hide";
// continue;
// }
// if (line === "// setup") {
// skipDisplay = true;
// } else if (line[0] !== ' ') {
// skipDisplay = false;
// }
//
// source += line + "\n";
// if (!skipDisplay && !hide)
// displaySource += line + "\n"
// if (line.length > 36) {
// console.error(`Line too long: "${line}"`);
// }
// }
// }
function trim(source) {
while (source.startsWith("\n")) {
source = source.slice(1, source.length);
}
while (source.endsWith("\n\n")) {
source = source.slice(0, source.length - 1);
}
return source;
}
// displaySource = trim(displaySource);
// element.textContent = displaySource;
}
})();