| 1 |
define(["../library/greek"], function(greeks){ |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
return { |
| 13 |
|
| 14 |
convertHTML: function(inText){ |
| 15 |
if(inText){ |
| 16 |
return inText.replace(/&([^;]+);/g,function(match,code){ |
| 17 |
if(code.charAt(0)=='#'){ |
| 18 |
|
| 19 |
var number=+code.substr(1); |
| 20 |
if(!isNaN(number)){ |
| 21 |
return String.fromCharCode(number); |
| 22 |
} |
| 23 |
}else if(greeks[code]){ |
| 24 |
return String.fromCharCode(greeks[code]); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
console.warn("no HTML conversion for ",match); |
| 29 |
return match; |
| 30 |
}); |
| 31 |
} |
| 32 |
return inText; |
| 33 |
}, |
| 34 |
|
| 35 |
convertLaTeX: function(inText){ |
| 36 |
|
| 37 |
if(inText){ |
| 38 |
return inText.replace(/\\([a-zA-Z]+)/g,function(match,word){ |
| 39 |
if(greeks[word]){ |
| 40 |
return String.fromCharCode(greeks[word]); |
| 41 |
}else if(word.substr(0,2)=="mu"){ |
| 42 |
|
| 43 |
|
| 44 |
return String.fromCharCode(greeks["mu"])+word.substr(2); |
| 45 |
}else if(word.substr(0,5)=="theta"){ |
| 46 |
|
| 47 |
|
| 48 |
return String.fromCharCode(greeks["theta"])+word.substr(5); |
| 49 |
}else if(word.substr(0,3)=="phi"){ |
| 50 |
|
| 51 |
|
| 52 |
return String.fromCharCode(greeks["phi"])+word.substr(3); |
| 53 |
} |
| 54 |
console.log("no match for ",match," in ",inText); |
| 55 |
console.log("Need user-friendly error handling here!"); |
| 56 |
}).replace(/\\\\/g,'\\'); |
| 57 |
} |
| 58 |
return inText; |
| 59 |
} |
| 60 |
|
| 61 |
}; |
| 62 |
|
| 63 |
}); |