1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-18 22:41:49 +02:00

up to and including section 21

This commit is contained in:
Pomax
2016-01-04 16:17:01 -08:00
parent 8b78e22ac4
commit 76fc269b07
37 changed files with 5576 additions and 3407 deletions

View File

@@ -1,40 +1,19 @@
/**
* <pre> should preserve newlines. Damnit, JSX
*/
var blockLoader = require("block-loader");
var options = {
start: "<pre>",
end: "</pre>",
var op = "<pre>";
var ed = "</pre>";
function hasTokens(input) {
return input.indexOf(op) !== -1 && input.indexOf(ed) !== -1;
}
function fixPreBlocks(source) {
// we can't do this with regexp, unfortunately.
var from = 0, curr, term;
var newsource = "", pre;
for(curr = source.indexOf(op, from); curr !== -1; from = term + ed.length, curr = source.indexOf(op, from)) {
newsource += source.substring(from, curr);
term = source.indexOf(ed, from);
if(term === -1) {
// that's a problem...
throw new Error("improperly closed LaTeX encountered!");
}
pre = source.substring(curr+op.length, term);
pre = pre.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')
.replace(/([{}])/g,"{'$1'}")
.replace(/\n/g,"{'\\n'}");
newsource += "<pre>" + pre + "</pre>";
/**
* There's a fair few things we'll want to safify for
* <pre> elements used in JSX...
*/
process: function fixPreBlocks(pre) {
return pre
.replace(/&/g,'&amp;')
.replace(/</g,'&lt;')
.replace(/>/g,'&gt;')
.replace(/([{}])/g,"{'$1'}")
.replace(/\n/g,"{'\\n'}");
}
return newsource + source.substring(from);
}
module.exports = function(source) {
this.cacheable();
if (!hasTokens(source)) return source;
return fixPreBlocks(source);
};
module.exports = blockLoader(options);