Skip to content

Commit 7de63c7

Browse files
committed
add failing unit tests from wiki and try-ctop page
1 parent 9f17e8f commit 7de63c7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+6058
-3659
lines changed

tests/error-tests.js

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
1-
CToP.transform(document.querySelectorAll('math'));
1+
function formatXml(xml) {
2+
var formatted = '';
3+
var reg = /(>)(<)(\/*)/g;
4+
xml = xml.replace(reg, '$1\r\n$2$3');
5+
var pad = 0;
6+
xml.split('\r\n').map(function(node,index) {
7+
var indent = 0;
8+
if (node.match( /.+<\/\w[^>]*>$/ )) {
9+
indent = 0;
10+
} else if (node.match( /^<\/\w/ )) {
11+
if (pad != 0) {
12+
pad -= 1;
13+
}
14+
} else if (node.match( /^<\w[^>]*[^\/]>.*$/ )) {
15+
indent = 1;
16+
} else {
17+
indent = 0;
18+
}
19+
20+
var padding = '';
21+
for (var i = 0; i < pad; i++) {
22+
padding += ' ';
23+
}
24+
25+
formatted += padding + node + '\r\n';
26+
pad += indent;
27+
});
28+
29+
return formatted;
30+
}
31+
232
Array.prototype.map.call(document.querySelectorAll('.unit'),function(unit) {
3-
var math = unit.querySelector('math').outerHTML;
4-
var t = document.createElement('pre');
5-
t.textContent = math;
6-
unit.appendChild(t);
33+
try {
34+
var mathNodes = unit.querySelectorAll('math');
35+
CToP.transform(mathNodes);
36+
var math = unit.querySelector('math').outerHTML;
37+
var t = document.createElement('pre');
38+
t.textContent = formatXml(math);
39+
unit.appendChild(t);
40+
MathJax.Hub.Queue(["Typeset",MathJax.Hub,unit]);
41+
}
42+
catch(e) {
43+
console.log(e);
44+
}
745
})
8-
9-
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);

0 commit comments

Comments
 (0)