mirror of
https://github.com/Pomax/BezierInfo-2.git
synced 2025-08-12 03:34:12 +02:00
start of revision control
This commit is contained in:
36
lib/pre-loader.js
Normal file
36
lib/pre-loader.js
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* <pre> should preserve newlines. Damnit, JSX
|
||||
*/
|
||||
|
||||
var op = "<pre>";
|
||||
var ed = "</pre>";
|
||||
|
||||
function hasTokens(input) {
|
||||
return input.indexOf(op) + input.indexOf(ed) >= 0;
|
||||
}
|
||||
|
||||
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, term + ed.length);
|
||||
pre = pre.replace(/\n/g,"{'\\n'}");
|
||||
newsource += pre;
|
||||
}
|
||||
return newsource + source.substring(from);
|
||||
}
|
||||
|
||||
|
||||
module.exports = function(source) {
|
||||
this.cacheable();
|
||||
if (!hasTokens(source)) return source;
|
||||
return fixPreBlocks(source);
|
||||
};
|
||||
|
Reference in New Issue
Block a user